source: opengl-game/shaders/ship.frag

feature/imgui-sdl
Last change on this file was 8d92284, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

In VulkanGame, change the ship pipeline to use ModelVertex

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