Improve terrain fog quality and refactor cloud rendering #52

Merged
embeddedt merged 8 commits from rdh/celeritas:sky-fog into stonecutter 2026-11-19 21:51:49 -05:00
Showing only changes of commit 5c784d4002 - Show all commits
@@ -121,16 +121,30 @@ public final class CloudRenderer {
float relativeTopY = relativeBottomY + CLOUD_THICKNESS; float relativeTopY = relativeBottomY + CLOUD_THICKNESS;
CameraPosition cameraPosition; CameraPosition cameraPosition;
float verticalDistance;
if (relativeTopY < 0.0f) { if (relativeTopY < 0.0f) {
cameraPosition = CameraPosition.ABOVE_CLOUDS; cameraPosition = CameraPosition.ABOVE_CLOUDS;
verticalDistance = -relativeTopY;
} else if (relativeBottomY > 0.0f) { } else if (relativeBottomY > 0.0f) {
cameraPosition = CameraPosition.BELOW_CLOUDS; cameraPosition = CameraPosition.BELOW_CLOUDS;
verticalDistance = relativeBottomY;
} else { } else {
cameraPosition = CameraPosition.INSIDE_CLOUDS; cameraPosition = CameraPosition.INSIDE_CLOUDS;
verticalDistance = 0.0f;
} }
int radius = (int) Math.ceil(frame.range() / Math.min(this.cellSizeX, this.cellSizeZ)); // Every cloud has faded out, such as underwater far below them
if (verticalDistance >= frame.fogEnd()) {
return false;
}
float cellSize = Math.min(this.cellSizeX, this.cellSizeZ);
int maxRadius = (int) Math.ceil(frame.range() / cellSize);
// Cells past the fade end are invisible. Rounding up keeps a fade end that changes gradually, like water fog
// while the player's eyes adjust, from rebuilding the faces every frame.
int fadeRadius = ((int) Math.ceil(frame.fogEnd() / cellSize) + 1 + 15) & ~15;
int radius = Math.min(maxRadius, fadeRadius);
if (this.needsRebuild || cellX != this.prevCellX || cellZ != this.prevCellZ || radius != this.prevRadius if (this.needsRebuild || cellX != this.prevCellX || cellZ != this.prevCellZ || radius != this.prevRadius
|| cameraPosition != this.prevCameraPosition || frame.fancy() != this.prevFancy) { || cameraPosition != this.prevCameraPosition || frame.fancy() != this.prevFancy) {