summaryrefslogtreecommitdiffstats
path: root/cwd/assets/altcraft/shaders/frag/light.fs
blob: 07eb3ec0bf3b6dbb5ba2a08c8df31bd9fd46a90e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#version 330 core

out vec4 fragColor;

in vec2 uv;

uniform sampler2D color;
uniform sampler2D normal;
uniform sampler2D addColor;
uniform sampler2D light;
uniform sampler2D depthStencil;

uniform int renderBuff;

layout (std140) uniform Globals {
    mat4 projView;
    uvec2 viewportSize;
    float globalTime;
    float dayTime;
};

void main() {
    vec4 c = texture(color, uv);
    vec4 n = texture(normal, uv);
    vec4 ac = texture(addColor, uv);
    vec4 l = texture(light, uv);
    float d = 1.0f - texture(depthStencil, uv).r;

    float faceLight = l.r;
    float skyLight = l.g;
    float lightLevel = clamp(faceLight + skyLight * dayTime, 0.2f, 1.0f);
    vec3 faceColor = mix(ac.rgb * lightLevel, vec3(1,1,1) * lightLevel, float(ac.rgb == vec3(0,0,0)));

    vec4 finalColor = vec4(c.rgb * faceColor, 1.0f);

    switch(renderBuff) {
        case 0:
            fragColor = finalColor;
            break;
        case 1:
            fragColor = c;
            break;
        case 2:
            fragColor = n;
            break;
        case 3:
            fragColor = ac;
            break;
        case 4:
            fragColor = l;
            break;
        case 5:
            fragColor = vec4(d, d, d, 1.0f);
            break;
    }
}