source: opengl-game/shaders/ship.frag@ 4994692

feature/imgui-sdl points-test
Last change on this file since 4994692 was 6385d0f, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Change all shaders to have 3-space indentation

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[1908591]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;
[e1308e8]6layout(location = 2) in vec3 normal_eye;
7layout(location = 3) in vec3 light_position_eye;
[60578ce]8layout(location = 4) in vec3 light2_position_eye;
[1908591]9
[60578ce]10layout(location = 0) out vec4 frag_color;
[1908591]11
12// fixed point light properties
13vec3 Ls = vec3(1.0, 1.0, 1.0);
[e1308e8]14vec3 Ld = vec3(0.7, 0.7, 0.7);
[1908591]15vec3 La = vec3(0.2, 0.2, 0.2);
16
[e1308e8]17// reflectance of the object surface
[7c929fc]18// TODO: Eventually, I might want to move these properties into an ssbo so they differ per object
[1908591]19vec3 Ks = vec3(1.0, 1.0, 1.0);
[7c929fc]20vec3 Kd = color;
[1908591]21vec3 Ka = vec3(0.2, 0.2, 0.2);
22float specular_exponent = 100.0; // specular 'power'
23
24void main() {
[8e02b6b]25 // ambient intensity
26 vec3 Ia = La * Ka;
[1908591]27
[8e02b6b]28 // ambient intensity
29 vec3 Ia2 = La * Ka;
[1908591]30
[aa00bf2]31 vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
[e1308e8]32 float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
[1908591]33
[8e02b6b]34 // diffuse intensity
[7c929fc]35 vec3 Id = Ld * Kd * dot_prod;
[1908591]36
[6385d0f]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);
[60578ce]39
[6385d0f]40 // diffuse intensity
41 vec3 Id2 = Ld * Kd * dot_prod2;
[60578ce]42
[e1308e8]43 vec3 surface_to_viewer_eye = normalize(-position_eye);
[1908591]44
[e1308e8]45 vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye);
46 float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0);
47 float specular_factor = pow(dot_prod_specular, specular_exponent);
[1908591]48
[8e02b6b]49 // specular intensity
[e1308e8]50 vec3 Is = Ls * Ks * specular_factor;
[1908591]51
[60578ce]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
[22217d4]59 frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2) / 2.0, 1.0);
[1908591]60}
Note: See TracBrowser for help on using the repository browser.