[ec4456b] | 1 | #version 410
|
---|
| 2 |
|
---|
[9dd2eb7] | 3 | in vec3 position_eye, normal_eye, color, light_position_eye;
|
---|
[485424b] | 4 |
|
---|
[8b7cfcf] | 5 | out vec4 frag_color;
|
---|
[ec4456b] | 6 |
|
---|
[9dd2eb7] | 7 | // fixed point light properties
|
---|
| 8 | vec3 Ls = vec3(1.0, 1.0, 1.0); // white specular colour
|
---|
| 9 | vec3 Ld = vec3(0.7, 0.7, 0.7); // dull white diffuse light colour
|
---|
| 10 | vec3 La = vec3(0.2, 0.2, 0.2); // grey ambient colour
|
---|
| 11 |
|
---|
| 12 | // surface reflectance
|
---|
| 13 | vec3 Ks = vec3(1.0, 1.0, 1.0); // fully reflect specular light
|
---|
| 14 | vec3 Kd = vec3(1.0, 0.5, 0.0); // orange diffuse surface reflectance
|
---|
| 15 | vec3 Ka = vec3(0.2, 0.2, 0.2); // fully reflect ambient light
|
---|
| 16 | float specular_exponent = 100.0; // specular 'power'
|
---|
| 17 |
|
---|
[ec4456b] | 18 | void main() {
|
---|
[9dd2eb7] | 19 | // ambient intensity
|
---|
| 20 | vec3 Ia = La * Ka;
|
---|
| 21 |
|
---|
| 22 | vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
|
---|
| 23 | float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
|
---|
| 24 |
|
---|
| 25 | // diffuse intensity
|
---|
| 26 | vec3 Id = Ls * color * dot_prod;
|
---|
| 27 |
|
---|
| 28 | vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
|
---|
| 29 | vec3 surface_to_viewer_eye = normalize(-position_eye);
|
---|
| 30 | float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
|
---|
| 31 | float specular_factor = pow(dot_prod_specular, specular_exponent);
|
---|
| 32 |
|
---|
| 33 | // specular intensity
|
---|
| 34 | vec3 Is = Ls * Ks * specular_factor;
|
---|
| 35 |
|
---|
| 36 | frag_color = vec4(Is + Id + Ia, 1.0);
|
---|
[ec4456b] | 37 | }
|
---|