Skip to content

Commit 12f199f

Browse files
committed
Better missile shadows
1 parent a19b53a commit 12f199f

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
import arc.graphics.g2d.*;
55
import arc.math.*;
66
import mindustry.gen.*;
7-
import mindustry.graphics.*;
87
import progressed.graphics.*;
98

109
import static progressed.graphics.Draw3D.*;
1110

1211
public class ArcBasicBulletType extends ArcBulletType{
1312
public String sprite;
14-
public float shadowLayer = Layer.flyingUnit + 1;
1513
public boolean bloomSprite = true;
1614
public boolean drawShadow = false, spinShade = true;
1715
public TextureRegion region, blRegion, trRegion;
@@ -50,14 +48,17 @@ public void draw(Bullet b){
5048
float hX = Draw3D.x(b.x, data.z),
5149
hY = Draw3D.y(b.y, data.z);
5250
float rot = Angles.angle(lastHX, lastHY, hX, hY);
53-
if(drawShadow){
54-
Draw.scl(1f + height(data.z));
55-
Draw.z(shadowLayer);
56-
float sX = Angles.trnsx(225f, data.z) + b.x,
51+
if(drawShadow && data.z < shadowMax){
52+
float scl = shadowScale(data.z),
53+
sX = Angles.trnsx(225f, data.z) + b.x,
5754
sY = Angles.trnsy(225f, data.z) + b.y,
5855
sRot = Angles.angle(b.originX, b.originY, b.aimX, b.aimY), //TODO better shadow rotation calculation
59-
sAlpha = Draw3D.zAlpha(data.z);
60-
PMDrawf.shadow(region, sX, sY, sRot, sAlpha);
56+
sAlpha = Draw3D.shadowAlpha(data.z);
57+
Draw3D.shadow(() -> {
58+
Draw.scl(scl);
59+
PMDrawf.shadow(region, sX, sY, sRot, sAlpha);
60+
Draw.scl();
61+
});
6162
}
6263

6364
Draw.z(layer);

src/progressed/entities/bullet/pseudo3d/ArcBulletType.java

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public void drawTargetZone(Bullet b){
351351
float a = -ang + 90 * i;
352352
Lines.lineAngleCenter(x + Angles.trnsx(a, tR), y + Angles.trnsy(a, tR), a, sL, false);
353353
}
354+
Draw.color();
354355
}
355356

356357
@Override

src/progressed/graphics/Draw3D.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import arc.*;
44
import arc.graphics.*;
55
import arc.graphics.g2d.*;
6+
import arc.graphics.gl.*;
67
import arc.math.*;
78
import arc.math.geom.*;
89
import arc.struct.*;
@@ -18,13 +19,36 @@
1819
public class Draw3D{
1920
/** Arbitrary value that translates z coordinate in world units to camera offset height. */
2021
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;
2224
public static final float scaleFadeBegin = 1.5f, scaleFadeEnd = 7f;
25+
public static final float shadowLayer = Layer.flyingUnit + 1;
2326
private static final Color tmpCol = new Color();
2427
private static final Seq<QueuedBloom> bloomQueue = new Seq<>();
28+
private static final Seq<Runnable> shadowQueue = new Seq<>();
2529

2630
public static void init(){
2731
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+
2852
if(bloomQueue.any()){
2953
bloomQueue.sort(q -> q.layer);
3054
Bloom bloom = renderer.bloom;
@@ -249,8 +273,12 @@ public static float height(float z){
249273
return z * zToOffset;
250274
}
251275

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));
254282
}
255283

256284
public static float scaleAlpha(float z){
@@ -294,6 +322,10 @@ public static void highBloom(boolean bloom, float layer, Runnable draw){
294322
}
295323
}
296324

325+
public static void shadow(Runnable draw){
326+
shadowQueue.add(draw);
327+
}
328+
297329
private static class QueuedBloom{
298330
public final float layer;
299331
public final Runnable draw;

0 commit comments

Comments
 (0)