|
3 | 3 | import arc.*;
|
4 | 4 | import arc.graphics.*;
|
5 | 5 | import arc.graphics.g2d.*;
|
| 6 | +import arc.graphics.gl.*; |
6 | 7 | import arc.math.*;
|
7 | 8 | import arc.math.geom.*;
|
8 | 9 | import arc.struct.*;
|
|
18 | 19 | public class Draw3D{
|
19 | 20 | /** Arbitrary value that translates z coordinate in world units to camera offset height. */
|
20 | 21 | public static final float zToOffset = 1f/48f/tilesize;
|
21 |
| - public static final float zFadeBegin = 300f, zFadeEnd = 5000f; |
| 22 | + /** z level in which the shadow becomes invisible. */ |
| 23 | + public static final float shadowMax = 1024f; |
22 | 24 | public static final float scaleFadeBegin = 1.5f, scaleFadeEnd = 7f;
|
| 25 | + public static final float shadowLayer = Layer.flyingUnit + 1; |
23 | 26 | private static final Color tmpCol = new Color();
|
24 | 27 | private static final Seq<QueuedBloom> bloomQueue = new Seq<>();
|
| 28 | + private static final Seq<Runnable> shadowQueue = new Seq<>(); |
25 | 29 |
|
26 | 30 | public static void init(){
|
27 | 31 | Events.run(Trigger.drawOver, () -> {
|
| 32 | + if(shadowQueue.any()){ |
| 33 | + Draw.draw(shadowLayer, () -> { |
| 34 | + FrameBuffer buffer = renderer.effectBuffer; |
| 35 | + buffer.begin(Color.clear); |
| 36 | + Draw.sort(false); |
| 37 | + Gl.blendEquationSeparate(Gl.funcAdd, Gl.max); |
| 38 | + |
| 39 | + for(Runnable s : shadowQueue){ |
| 40 | + s.run(); |
| 41 | + } |
| 42 | + |
| 43 | + Draw.sort(true); |
| 44 | + buffer.end(); |
| 45 | + Gl.blendEquationSeparate(Gl.funcAdd, Gl.funcAdd); |
| 46 | + |
| 47 | + buffer.blit(PMShaders.passThrough); |
| 48 | + }); |
| 49 | + shadowQueue.clear(); |
| 50 | + } |
| 51 | + |
28 | 52 | if(bloomQueue.any()){
|
29 | 53 | bloomQueue.sort(q -> q.layer);
|
30 | 54 | Bloom bloom = renderer.bloom;
|
@@ -249,8 +273,12 @@ public static float height(float z){
|
249 | 273 | return z * zToOffset;
|
250 | 274 | }
|
251 | 275 |
|
252 |
| - public static float zAlpha(float z){ |
253 |
| - return 1f - Mathf.curve(z, zFadeBegin, zFadeEnd); |
| 276 | + public static float shadowScale(float z){ |
| 277 | + return 1 + z / shadowMax * 5f; |
| 278 | + } |
| 279 | + |
| 280 | + public static float shadowAlpha(float z){ |
| 281 | + return Mathf.clamp(1f - Interp.circleOut.apply(z / shadowMax)); |
254 | 282 | }
|
255 | 283 |
|
256 | 284 | public static float scaleAlpha(float z){
|
@@ -294,6 +322,10 @@ public static void highBloom(boolean bloom, float layer, Runnable draw){
|
294 | 322 | }
|
295 | 323 | }
|
296 | 324 |
|
| 325 | + public static void shadow(Runnable draw){ |
| 326 | + shadowQueue.add(draw); |
| 327 | + } |
| 328 | + |
297 | 329 | private static class QueuedBloom{
|
298 | 330 | public final float layer;
|
299 | 331 | public final Runnable draw;
|
|
0 commit comments