Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / games / voxels / src / main / rust / shaders / entity.frag
entity.frag35 lines · 1013 BRaw
| 1 | #version 450 |
| 2 | layout(location=0) in vec2 fragUv; |
| 3 | layout(location=1) in vec3 fragColor; |
| 4 | layout(location=2) in vec3 fragWorldPos; |
| 5 | layout(location=3) in vec3 fragNormal; |
| 6 | |
| 7 | layout(binding=0) uniform Ubo { |
| 8 | mat4 viewProj; |
| 9 | vec3 sunDir; |
| 10 | float time; |
| 11 | vec3 fogColor; |
| 12 | float fogDensity; |
| 13 | vec4 playerPos; |
| 14 | float dayFactor; |
| 15 | mat4 invViewProj; |
| 16 | vec3 sunColor; |
| 17 | float cloudShadow; |
| 18 | vec3 ambientColor; |
| 19 | float _pad2; |
| 20 | mat4 lightViewProj; |
| 21 | }; |
| 22 | layout(binding=3) uniform sampler2D entityTex; |
| 23 | |
| 24 | layout(location=0) out vec4 outColor; |
| 25 | |
| 26 | void main() { |
| 27 | vec4 t = texture(entityTex, fragUv); |
| 28 | if (t.a < 0.5) discard; // cut out transparent skin regions |
| 29 | vec3 n = normalize(fragNormal); |
| 30 | vec3 s = normalize(sunDir); |
| 31 | float ndl = max(dot(n, s), 0.0); |
| 32 | vec3 amb = ambientColor * (0.55 + 0.45 * (0.5 + 0.5 * n.y)); |
| 33 | vec3 lit = t.rgb * fragColor * (sunColor * ndl + amb); |
| 34 | outColor = vec4(lit, 1.0); // linear HDR; tonemapped in composite |
| 35 | } |