Skip to content

Commit

Permalink
Better missile shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Jul 24, 2024
1 parent a19b53a commit 12f199f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/progressed/entities/bullet/pseudo3d/ArcBasicBulletType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/progressed/entities/bullet/pseudo3d/ArcBulletType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 35 additions & 3 deletions src/progressed/graphics/Draw3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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<QueuedBloom> bloomQueue = new Seq<>();
private static final Seq<Runnable> 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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 12f199f

Please sign in to comment.