source: opengl-game/texture.frag@ be34c9a

feature/imgui-sdl points-test
Last change on this file since be34c9a 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.3 KB
RevLine 
[485424b]1#version 410
2
3uniform sampler2D basic_texture;
4
5in vec2 texture_coordinates;
[9dd2eb7]6in vec3 position_eye, normal_eye, light_position_eye;
[485424b]7
8out vec4 frag_color;
9
[9dd2eb7]10// fixed point light properties
11vec3 Ls = vec3(1.0, 1.0, 1.0); // white specular colour
12vec3 Ld = vec3(0.7, 0.7, 0.7); // dull white diffuse light colour
13vec3 La = vec3(0.2, 0.2, 0.2); // grey ambient colour
14
15// surface reflectance
16vec3 Ks = vec3(1.0, 1.0, 1.0); // fully reflect specular light
17vec3 Kd = vec3(1.0, 0.5, 0.0); // orange diffuse surface reflectance
18vec3 Ka = vec3(0.2, 0.2, 0.2); // fully reflect ambient light
19float specular_exponent = 100.0; // specular 'power'
20
[485424b]21void main() {
22 vec4 texel = texture(basic_texture, texture_coordinates);
[9dd2eb7]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
[f7d35da]31 vec3 Id = Ld * vec3(texel) * dot_prod;
[9dd2eb7]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);
[485424b]42}
Note: See TracBrowser for help on using the repository browser.