Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / games / kart / src / main / rust / shaders / kart.frag

kart.frag25 lines · 809 BRaw
1#version 450
2// Flat shading plus distance fog: one fixed sun direction, no shadow maps.
3// Karts read as solid boxes against the track; the fog melts the far side of
4// the oval into the sky clear color so the pop-in line never shows.
5layout(location = 0) in vec3 vColor;
6layout(location = 1) in vec3 vWorld;
7
8layout(location = 0) out vec4 outColor;
9
10layout(set = 0, binding = 0) uniform Ubo {
11 mat4 viewProj;
12 vec3 sunDir;
13 vec3 camPos;
14} ubo;
15
16const vec3 SKY = vec3(0.45, 0.68, 0.94);
17
18void main() {
19 vec3 up = vec3(0.0, 1.0, 0.0);
20 float ndl = 0.72 + 0.28 * clamp(dot(up, normalize(ubo.sunDir)), 0.0, 1.0);
21 vec3 col = vColor * ndl;
22 float dist = length(vWorld - ubo.camPos);
23 float fog = 1.0 - exp(-dist * 0.0045);
24 outColor = vec4(mix(col, SKY, clamp(fog, 0.0, 1.0)), 1.0);
25}