source: opengl-game/shaders/ship.frag@ 7c929fc

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

In VulkanGame, make lighting work correctly in the ship shader before the MVP matrices are applied

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#version 450
2#extension GL_ARB_separate_shader_objects : enable
3
4layout(location = 0) in vec3 position_eye;
5layout(location = 1) in vec3 color;
6layout(location = 2) in vec3 normal_eye;
7layout(location = 3) in vec3 light_position_eye;
8
9layout(location = 0) out vec4 outColor;
10
11// fixed point light properties
12vec3 Ls = vec3(1.0, 1.0, 1.0);
13vec3 Ld = vec3(0.7, 0.7, 0.7);
14vec3 La = vec3(0.2, 0.2, 0.2);
15
16// reflectance of the object surface
17// TODO: Eventually, I might want to move these properties into an ssbo so they differ per object
18vec3 Ks = vec3(1.0, 1.0, 1.0);
19vec3 Kd = color;
20vec3 Ka = vec3(0.2, 0.2, 0.2);
21float specular_exponent = 100.0; // specular 'power'
22
23void main() {
24 // ambient intensity
25 vec3 Ia = La * Ka;
26
27 // ambient intensity
28 vec3 Ia2 = La * Ka;
29
30 vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
31 float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
32
33 // diffuse intensity
34 vec3 Id = Ld * Kd * dot_prod;
35
36 vec3 surface_to_viewer_eye = normalize(-position_eye);
37
38 vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
39 float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
40 float specular_factor = pow(dot_prod_specular, specular_exponent);
41
42 // specular intensity
43 vec3 Is = Ls * Ks * specular_factor;
44
45 outColor = vec4(Is + Id + Ia, 1.0);
46}
Note: See TracBrowser for help on using the repository browser.