source: opengl-game/color.frag@ 5c403fe

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

Add a system to keep track of which keys are pressed or held down and add another light source to help illuminate the scene from different directions.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#version 410
2
3in vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;
4
5out vec4 frag_color;
6
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
18void main() {
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 = Ld * color * dot_prod;
27
28 vec3 direction_to_light2_eye = normalize(light2_position_eye - position_eye);
29 float dot_prod2 = max(dot(direction_to_light2_eye, normal_eye), 0.0);
30
31 // diffuse intensity
32 vec3 Id2 = Ld * color * dot_prod2;
33
34 vec3 surface_to_viewer_eye = normalize(-position_eye);
35
36 vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
37 float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
38 float specular_factor = pow(dot_prod_specular, specular_exponent);
39
40 vec3 reflection_eye2 = reflect(-direction_to_light2_eye, normal_eye);
41 float dot_prod_specular2 = max(dot(reflection_eye2, surface_to_viewer_eye), 0.0);
42 float specular_factor2 = pow(dot_prod_specular2, specular_exponent);
43
44 // specular intensity
45 vec3 Is = Ls * Ks * specular_factor;
46 vec3 Is2 = Ls * Ks * specular_factor2;
47
48 frag_color = vec4(Is + Id + Ia + Is2 + Id2, 1.0);
49}
Note: See TracBrowser for help on using the repository browser.