Changeset 60578ce in opengl-game for shaders/ship.frag


Ignore:
Timestamp:
Dec 18, 2019, 2:48:28 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
a79be34
Parents:
7c929fc
Message:

In VulkanGame, make lighting work correctly in the ship shader with the model, view, and projection matrices all being applied

File:
1 edited

Legend:

Unmodified
Added
Removed
  • shaders/ship.frag

    r7c929fc r60578ce  
    66layout(location = 2) in vec3 normal_eye;
    77layout(location = 3) in vec3 light_position_eye;
     8layout(location = 4) in vec3 light2_position_eye;
    89
    9 layout(location = 0) out vec4 outColor;
     10layout(location = 0) out vec4 frag_color;
    1011
    1112// fixed point light properties
     
    3435   vec3 Id = Ld * Kd * dot_prod;
    3536
     37  vec3 direction_to_light2_eye = normalize(light2_position_eye - position_eye);
     38  float dot_prod2 = max(dot(direction_to_light2_eye, normal_eye), 0.0);
     39
     40  // diffuse intensity
     41  vec3 Id2 = Ld * Kd * dot_prod2;
     42
    3643   vec3 surface_to_viewer_eye = normalize(-position_eye);
    3744
     
    4350   vec3 Is = Ls * Ks * specular_factor;
    4451
    45    outColor = vec4(Is + Id + Ia, 1.0);
     52   vec3 reflection_eye2 = reflect(-direction_to_light2_eye, normal_eye);
     53   float dot_prod_specular2 = max(dot(reflection_eye2, surface_to_viewer_eye), 0.0);
     54   float specular_factor2 = pow(dot_prod_specular2, specular_exponent);
     55
     56   // specular intensity
     57   vec3 Is2 = Ls * Ks * specular_factor2;
     58
     59   frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0);
    4660}
Note: See TracChangeset for help on using the changeset viewer.