Skip to content

Commit 1b75dea

Browse files
committed
Better alpha fading
1 parent 309f4cc commit 1b75dea

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/progressed/graphics/draw3d/Perspective.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,17 @@ public static float scale(float x, float y, float z){
8282

8383
/** Fade out based on distance to viewport. */
8484
public static float alpha(float x, float y, float z){
85-
float cx = camera.position.x, cy = camera.position.y;
86-
float cz = cameraZ;
87-
88-
x -= cx;
89-
y -= cy;
90-
float zz = cz - z;
91-
92-
float vx = x / zz * viewportOffset, //Position scaled to near plane.
93-
vy = y / zz * viewportOffset;
9485
float vz = viewportZ();
9586

96-
float dst = Math3D.dst(x, y, z, vx, vy, vz); //Distance between viewport and pos
97-
float fade = Math.min(fadeDst, cz - viewportOffset);
87+
float dst = dstToViewport(x, y, z);
88+
float fade = Math.min(fadeDst, vz);
9889

9990
if(dst > fade){
10091
return 1f;
10192
}else if(z > vz){ //Behind viewport, should be 0
10293
return 0f;
10394
}else{
104-
return Mathf.clamp(dst / fade);
95+
return Interp.pow2In.apply(Mathf.clamp(dst / fade));
10596
}
10697
}
10798

@@ -131,6 +122,21 @@ public static void viewportSize(){
131122
}
132123
}
133124

125+
public static float dstToViewport(float x, float y, float z){
126+
float cx = camera.position.x, cy = camera.position.y;
127+
float cz = cameraZ;
128+
129+
x -= cx;
130+
y -= cy;
131+
float zz = cz - z;
132+
133+
float vx = x / zz * viewportOffset, //Position scaled to near plane.
134+
vy = y / zz * viewportOffset;
135+
float vz = viewportZ();
136+
137+
return Math3D.dst(x, y, z, vx, vy, vz); //Distance between viewport and pos
138+
}
139+
134140
/**
135141
* Calculates the camera z coordinate based on FOV and the size of the vanilla camera.
136142
* @return camera z coordinate

src/progressed/world/blocks/defence/turret/testing/SkyLaserTestTurret.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public SkyLaserTestTurret(String name){
1515
lifetime = bRange / speed;
1616
radius = 1.5f * tilesize;
1717
drag = -0.01f;
18-
z = 2000;
18+
z = 2400;
1919
}};
2020
reload = 45f;
2121
shootY = 0f;

0 commit comments

Comments
 (0)