[1908591] | 1 | #version 450
|
---|
| 2 | #extension GL_ARB_separate_shader_objects : enable
|
---|
| 3 |
|
---|
| 4 | layout(location = 0) in vec3 position_eye;
|
---|
| 5 | layout(location = 1) in vec3 color;
|
---|
[e1308e8] | 6 | layout(location = 2) in vec3 normal_eye;
|
---|
| 7 | layout(location = 3) in vec3 light_position_eye;
|
---|
[1908591] | 8 |
|
---|
| 9 | layout(location = 0) out vec4 outColor;
|
---|
| 10 |
|
---|
| 11 | // fixed point light properties
|
---|
| 12 | vec3 Ls = vec3(1.0, 1.0, 1.0);
|
---|
[e1308e8] | 13 | vec3 Ld = vec3(0.7, 0.7, 0.7);
|
---|
[1908591] | 14 | vec3 La = vec3(0.2, 0.2, 0.2);
|
---|
| 15 |
|
---|
[e1308e8] | 16 | // reflectance of the object surface
|
---|
[1908591] | 17 | vec3 Ks = vec3(1.0, 1.0, 1.0);
|
---|
[e1308e8] | 18 | vec3 Kd = vec3(1.0, 0.5, 0.0);
|
---|
[1908591] | 19 | vec3 Ka = vec3(0.2, 0.2, 0.2);
|
---|
| 20 | float specular_exponent = 100.0; // specular 'power'
|
---|
| 21 |
|
---|
| 22 | void main() {
|
---|
[8e02b6b] | 23 | // ambient intensity
|
---|
| 24 | vec3 Ia = La * Ka;
|
---|
[1908591] | 25 |
|
---|
[8e02b6b] | 26 | // ambient intensity
|
---|
| 27 | vec3 Ia2 = La * Ka;
|
---|
[1908591] | 28 |
|
---|
[aa00bf2] | 29 | vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
|
---|
[e1308e8] | 30 | float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
|
---|
[1908591] | 31 |
|
---|
[8e02b6b] | 32 | // diffuse intensity
|
---|
[e1308e8] | 33 | vec3 Id = Ld * color * dot_prod;
|
---|
| 34 | //vec3 Id = Ld * Kd * dot_prod;
|
---|
[1908591] | 35 |
|
---|
[e1308e8] | 36 | vec3 surface_to_viewer_eye = normalize(-position_eye);
|
---|
[1908591] | 37 |
|
---|
[e1308e8] | 38 | vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
|
---|
| 39 | float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
|
---|
| 40 | float specular_factor = pow(dot_prod_specular, specular_exponent);
|
---|
[1908591] | 41 |
|
---|
[8e02b6b] | 42 | // specular intensity
|
---|
[e1308e8] | 43 | vec3 Is = Ls * Ks * specular_factor;
|
---|
[1908591] | 44 |
|
---|
[e1308e8] | 45 | outColor = vec4(Is + Id + Ia, 1.0);
|
---|
[1908591] | 46 | }
|
---|