summaryrefslogtreecommitdiffstats
path: root/examples/deferred-renderer-cpp/final_gl3.frag
blob: 88abd5cb13b6742c44af9ccea4299de5a144f755 (plain)
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
#version 140

uniform sampler2D color;
uniform sampler2D position;
uniform sampler2D normal;
uniform vec2 winSize;

out vec4 fragColor;

struct PointLight
{
    vec3 position;
    vec3 direction;
    vec4 color;
    float intensity;
};

const int lightCount = 3;
uniform PointLightBlock {
     PointLight lights[lightCount];
};

void main()
{
    vec2 texCoord = gl_FragCoord.xy / winSize;
    vec4 col = texture(color, texCoord);
    vec3 pos = texture(position, texCoord).xyz;
    vec3 norm = texture(normal, texCoord).xyz;

    vec4 lightColor;
    for (int i = 0; i < 3; i++) {
        vec3 s = normalize(lights[i].position - pos);
        lightColor += lights[i].color * (lights[i].intensity * max(dot(s, norm), 0.0));
    }
    lightColor /= float(lightCount);
    fragColor = col * lightColor;
}