source: opengl-game/color.frag@ e3ca955

feature/imgui-sdl points-test
Last change on this file since e3ca955 was 9dd2eb7, checked in by Dmitry Portnoy <dmp1488@…>, 6 years ago

Implement Phong shading in the color and texture shaders

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[ec4456b]1#version 410
2
[9dd2eb7]3in vec3 position_eye, normal_eye, color, light_position_eye;
[485424b]4
[8b7cfcf]5out vec4 frag_color;
[ec4456b]6
[9dd2eb7]7// fixed point light properties
8vec3 Ls = vec3(1.0, 1.0, 1.0); // white specular colour
9vec3 Ld = vec3(0.7, 0.7, 0.7); // dull white diffuse light colour
10vec3 La = vec3(0.2, 0.2, 0.2); // grey ambient colour
11
12// surface reflectance
13vec3 Ks = vec3(1.0, 1.0, 1.0); // fully reflect specular light
14vec3 Kd = vec3(1.0, 0.5, 0.0); // orange diffuse surface reflectance
15vec3 Ka = vec3(0.2, 0.2, 0.2); // fully reflect ambient light
16float specular_exponent = 100.0; // specular 'power'
17
[ec4456b]18void 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}
Note: See TracBrowser for help on using the repository browser.