36 lines
917 B
GLSL
36 lines
917 B
GLSL
#version 330 core
|
|
in vec2 vUv;
|
|
in float vShade;
|
|
in float vWorldY;
|
|
in vec3 vWorldPos;
|
|
|
|
out vec4 FragColor;
|
|
|
|
uniform sampler2D atlas;
|
|
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);
|
|
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);
|
|
}
|