summaryrefslogtreecommitdiffstats
path: root/src/render/shaders/diffuse.frag
blob: e9985422a44d2b13b55809850e329d4c72806d1f (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
#version 150

uniform vec4 lightPosition;
uniform vec3 lightIntensity;
uniform vec3 kd; // Diffuse reflectivity
uniform vec3 ka; // Ambient reflectivity

in vec3 position;
in vec3 normal;

//layout (location = 0)
out vec4 fragColor;

void main()
{
    // Calculate the vector from the light to the fragment
    vec3 s = normalize( vec3( lightPosition ) - position );

    // Calculate the diffuse lighting factor
    vec3 n = normalize( normal );
    float diffuse = max( dot( s, n ), 0.0 );

    // Multiply by incoming light intensity
    fragColor = vec4( lightIntensity * (kd * diffuse + ka), 1.0 );
}