Changeset 9dd2eb7 in opengl-game for texture.frag
- Timestamp:
- Apr 28, 2018, 2:29:20 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 9f4986b
- Parents:
- d9f99b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
texture.frag
rd9f99b2 r9dd2eb7 4 4 5 5 in vec2 texture_coordinates; 6 in vec3 position_eye, normal_eye, light_position_eye; 6 7 7 8 out vec4 frag_color; 8 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 9 21 void main() { 10 22 vec4 texel = texture(basic_texture, texture_coordinates); 11 frag_color = texel; 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); 12 42 }
Note:
See TracChangeset
for help on using the changeset viewer.