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