Fragment.glsl 852 Bytes
Newer Older
1
varying vec4 diffuse_color;
Jan Möbius's avatar
 
Jan Möbius committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
varying vec3 normal;
varying vec4 vertexPosition;

vec4 phong_direct(int lightSource) {
    vec3 light_pos = vec3(gl_LightSource[lightSource].position);
    vec3 eye_pos = vec3(vertexPosition / vertexPosition.w);
    vec3 lightVector = vec3(light_pos - eye_pos);
    float lightDistance = length(lightVector);
    lightVector /= lightDistance;

    vec4 color = vec4(0.0);
    vec3 n;
    float NdotL, NdotHV;
    
    n = normalize(normal);
    
    NdotL = dot(n, lightVector);
    float LdotD = dot(lightVector, gl_LightSource[lightSource].spotDirection);

    if (NdotL > 0.0 && LdotD < 0.0) {
        color = gl_LightSource[lightSource].diffuse * -LdotD * NdotL;
    }
24
25
26
27

    // Use Alpha Value from original color
    color[3] = diffuse_color[3];

Jan Möbius's avatar
 
Jan Möbius committed
28
29
30
31
32
    return color;
}

void  main() {
  gl_FragColor = phong_direct(0);
33
}