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

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

entity.frag35 lines · 1013 BRaw
1#version 450
2layout(location=0) in vec2 fragUv;
3layout(location=1) in vec3 fragColor;
4layout(location=2) in vec3 fragWorldPos;
5layout(location=3) in vec3 fragNormal;
6
7layout(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};
22layout(binding=3) uniform sampler2D entityTex;
23
24layout(location=0) out vec4 outColor;
25
26void 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}