feat(rendering): distance fog and config-derived far plane
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
in vec2 vUv;
|
||||
in float vShade;
|
||||
in float vWorldY;
|
||||
in vec3 vWorldPos;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
@@ -10,11 +11,25 @@ uniform float u_caveDarkStartY;
|
||||
uniform float u_caveDarkEndY;
|
||||
uniform float u_caveMinBrightness;
|
||||
|
||||
uniform vec3 u_cameraPos;
|
||||
uniform float u_fogStart;
|
||||
uniform float u_fogEnd;
|
||||
uniform vec3 u_skyColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture(atlas, vUv);
|
||||
|
||||
// Y-based cave darkness.
|
||||
float t = clamp((u_caveDarkStartY - vWorldY) /
|
||||
(u_caveDarkStartY - u_caveDarkEndY), 0.0, 1.0);
|
||||
float brightness = mix(1.0, u_caveMinBrightness, t);
|
||||
FragColor = vec4(texel.rgb * vShade * brightness, 1.0);
|
||||
vec3 color = texel.rgb * vShade * brightness;
|
||||
|
||||
// Distance fog to the sky color, applied after cave darkness.
|
||||
float dist = length(vWorldPos - u_cameraPos);
|
||||
float fog = clamp((dist - u_fogStart) / (u_fogEnd - u_fogStart), 0.0, 1.0);
|
||||
color = mix(color, u_skyColor, fog);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ layout(location = 2) in float aShade;
|
||||
out vec2 vUv;
|
||||
out float vShade;
|
||||
out float vWorldY;
|
||||
out vec3 vWorldPos;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
@@ -17,6 +18,7 @@ void main()
|
||||
vShade = aShade;
|
||||
// World-space position uses row-vector convention (matches gl_Position below).
|
||||
vec4 worldPos = vec4(aPos, 1.0) * model;
|
||||
vWorldPos = worldPos.xyz;
|
||||
vWorldY = worldPos.y;
|
||||
gl_Position = worldPos * view * projection;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user