Skip to content

Commit

Permalink
Better alpha fading
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Nov 21, 2024
1 parent 309f4cc commit 1b75dea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/progressed/graphics/draw3d/Perspective.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,17 @@ public static float scale(float x, float y, float z){

/** Fade out based on distance to viewport. */
public static float alpha(float x, float y, float z){
float cx = camera.position.x, cy = camera.position.y;
float cz = cameraZ;

x -= cx;
y -= cy;
float zz = cz - z;

float vx = x / zz * viewportOffset, //Position scaled to near plane.
vy = y / zz * viewportOffset;
float vz = viewportZ();

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

if(dst > fade){
return 1f;
}else if(z > vz){ //Behind viewport, should be 0
return 0f;
}else{
return Mathf.clamp(dst / fade);
return Interp.pow2In.apply(Mathf.clamp(dst / fade));
}
}

Expand Down Expand Up @@ -131,6 +122,21 @@ public static void viewportSize(){
}
}

public static float dstToViewport(float x, float y, float z){
float cx = camera.position.x, cy = camera.position.y;
float cz = cameraZ;

x -= cx;
y -= cy;
float zz = cz - z;

float vx = x / zz * viewportOffset, //Position scaled to near plane.
vy = y / zz * viewportOffset;
float vz = viewportZ();

return Math3D.dst(x, y, z, vx, vy, vz); //Distance between viewport and pos
}

/**
* Calculates the camera z coordinate based on FOV and the size of the vanilla camera.
* @return camera z coordinate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SkyLaserTestTurret(String name){
lifetime = bRange / speed;
radius = 1.5f * tilesize;
drag = -0.01f;
z = 2000;
z = 2400;
}};
reload = 45f;
shootY = 0f;
Expand Down

0 comments on commit 1b75dea

Please sign in to comment.