diff --git a/src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java b/src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java index f5030759..06b22926 100644 --- a/src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java +++ b/src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java @@ -4,14 +4,12 @@ import arc.graphics.g2d.*; import arc.math.*; import mindustry.gen.*; -import mindustry.graphics.*; import progressed.graphics.*; import static progressed.graphics.Draw3D.*; public class ArcBasicBulletType extends ArcBulletType{ public String sprite; - public float shadowLayer = Layer.flyingUnit + 1; public boolean bloomSprite = true; public boolean drawShadow = false, spinShade = true; public TextureRegion region, blRegion, trRegion; @@ -50,14 +48,17 @@ public void draw(Bullet b){ float hX = Draw3D.x(b.x, data.z), hY = Draw3D.y(b.y, data.z); float rot = Angles.angle(lastHX, lastHY, hX, hY); - if(drawShadow){ - Draw.scl(1f + height(data.z)); - Draw.z(shadowLayer); - float sX = Angles.trnsx(225f, data.z) + b.x, + if(drawShadow && data.z < shadowMax){ + float scl = shadowScale(data.z), + sX = Angles.trnsx(225f, data.z) + b.x, sY = Angles.trnsy(225f, data.z) + b.y, sRot = Angles.angle(b.originX, b.originY, b.aimX, b.aimY), //TODO better shadow rotation calculation - sAlpha = Draw3D.zAlpha(data.z); - PMDrawf.shadow(region, sX, sY, sRot, sAlpha); + sAlpha = Draw3D.shadowAlpha(data.z); + Draw3D.shadow(() -> { + Draw.scl(scl); + PMDrawf.shadow(region, sX, sY, sRot, sAlpha); + Draw.scl(); + }); } Draw.z(layer); diff --git a/src/progressed/entities/bullet/pseudo3d/ArcBulletType.java b/src/progressed/entities/bullet/pseudo3d/ArcBulletType.java index 08f0c058..4945101c 100644 --- a/src/progressed/entities/bullet/pseudo3d/ArcBulletType.java +++ b/src/progressed/entities/bullet/pseudo3d/ArcBulletType.java @@ -351,6 +351,7 @@ public void drawTargetZone(Bullet b){ float a = -ang + 90 * i; Lines.lineAngleCenter(x + Angles.trnsx(a, tR), y + Angles.trnsy(a, tR), a, sL, false); } + Draw.color(); } @Override diff --git a/src/progressed/graphics/Draw3D.java b/src/progressed/graphics/Draw3D.java index 22e18d33..a4023566 100644 --- a/src/progressed/graphics/Draw3D.java +++ b/src/progressed/graphics/Draw3D.java @@ -3,6 +3,7 @@ import arc.*; import arc.graphics.*; import arc.graphics.g2d.*; +import arc.graphics.gl.*; import arc.math.*; import arc.math.geom.*; import arc.struct.*; @@ -18,13 +19,36 @@ public class Draw3D{ /** Arbitrary value that translates z coordinate in world units to camera offset height. */ public static final float zToOffset = 1f/48f/tilesize; - public static final float zFadeBegin = 300f, zFadeEnd = 5000f; + /** z level in which the shadow becomes invisible. */ + public static final float shadowMax = 1024f; public static final float scaleFadeBegin = 1.5f, scaleFadeEnd = 7f; + public static final float shadowLayer = Layer.flyingUnit + 1; private static final Color tmpCol = new Color(); private static final Seq bloomQueue = new Seq<>(); + private static final Seq shadowQueue = new Seq<>(); public static void init(){ Events.run(Trigger.drawOver, () -> { + if(shadowQueue.any()){ + Draw.draw(shadowLayer, () -> { + FrameBuffer buffer = renderer.effectBuffer; + buffer.begin(Color.clear); + Draw.sort(false); + Gl.blendEquationSeparate(Gl.funcAdd, Gl.max); + + for(Runnable s : shadowQueue){ + s.run(); + } + + Draw.sort(true); + buffer.end(); + Gl.blendEquationSeparate(Gl.funcAdd, Gl.funcAdd); + + buffer.blit(PMShaders.passThrough); + }); + shadowQueue.clear(); + } + if(bloomQueue.any()){ bloomQueue.sort(q -> q.layer); Bloom bloom = renderer.bloom; @@ -249,8 +273,12 @@ public static float height(float z){ return z * zToOffset; } - public static float zAlpha(float z){ - return 1f - Mathf.curve(z, zFadeBegin, zFadeEnd); + public static float shadowScale(float z){ + return 1 + z / shadowMax * 5f; + } + + public static float shadowAlpha(float z){ + return Mathf.clamp(1f - Interp.circleOut.apply(z / shadowMax)); } public static float scaleAlpha(float z){ @@ -294,6 +322,10 @@ public static void highBloom(boolean bloom, float layer, Runnable draw){ } } + public static void shadow(Runnable draw){ + shadowQueue.add(draw); + } + private static class QueuedBloom{ public final float layer; public final Runnable draw;