source: opengl-game/gl-shaders/ship.frag@ 4d84c72

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

Move the OpenGL shaders to a gl-shaders folder

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[ec4456b]1#version 410
2
[f7d35da]3in vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;
[485424b]4
[8b7cfcf]5out vec4 frag_color;
[ec4456b]6
[9dd2eb7]7// fixed point light properties
[cf2d1e5]8vec3 Ls = vec3(1.0, 1.0, 1.0);
9vec3 Ld = vec3(1.0, 1.0, 1.0);
10vec3 La = vec3(0.2, 0.2, 0.2);
[9dd2eb7]11
12// surface reflectance
[cf2d1e5]13vec3 Ks = vec3(1.0, 1.0, 1.0);
14vec3 Kd = vec3(1.0, 1.5, 1.0);
15vec3 Ka = vec3(0.2, 0.2, 0.2);
[9dd2eb7]16float specular_exponent = 100.0; // specular 'power'
17
[ec4456b]18void main() {
[9dd2eb7]19 // ambient intensity
20 vec3 Ia = La * Ka;
21
[cf2d1e5]22 // ambient intensity
23 vec3 Ia2 = La * Ka;
24
[9dd2eb7]25 vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
26 float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
27
28 // diffuse intensity
[f7d35da]29 vec3 Id = Ld * color * dot_prod;
30
31 vec3 direction_to_light2_eye = normalize(light2_position_eye - position_eye);
32 float dot_prod2 = max(dot(direction_to_light2_eye, normal_eye), 0.0);
33
34 // diffuse intensity
35 vec3 Id2 = Ld * color * dot_prod2;
[9dd2eb7]36
37 vec3 surface_to_viewer_eye = normalize(-position_eye);
[f7d35da]38
39 vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
[9dd2eb7]40 float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
41 float specular_factor = pow(dot_prod_specular, specular_exponent);
42
[f7d35da]43 vec3 reflection_eye2 = reflect(-direction_to_light2_eye, normal_eye);
44 float dot_prod_specular2 = max(dot(reflection_eye2, surface_to_viewer_eye), 0.0);
45 float specular_factor2 = pow(dot_prod_specular2, specular_exponent);
46
[9dd2eb7]47 // specular intensity
48 vec3 Is = Ls * Ks * specular_factor;
[f7d35da]49 vec3 Is2 = Ls * Ks * specular_factor2;
[9dd2eb7]50
[cf2d1e5]51 frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0);
[ec4456b]52}
Note: See TracBrowser for help on using the repository browser.