Changeset 9dd2eb7 in opengl-game for texture.frag


Ignore:
Timestamp:
Apr 28, 2018, 2:29:20 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
9f4986b
Parents:
d9f99b2
Message:

Implement Phong shading in the color and texture shaders

File:
1 edited

Legend:

Unmodified
Added
Removed
  • texture.frag

    rd9f99b2 r9dd2eb7  
    44
    55in vec2 texture_coordinates;
     6in vec3 position_eye, normal_eye, light_position_eye;
    67
    78out vec4 frag_color;
    89
     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
    921void main() {
    1022  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);
    1242}
Note: See TracChangeset for help on using the changeset viewer.