source: opengl-game/shaders/asteroid.frag@ b01b50c

feature/imgui-sdl
Last change on this file since b01b50c was b8efa56, checked in by Dmitry Portnoy <dportnoy@…>, 3 years ago

In VulkanGame, change the asteroid pipeline to use ModelVertex

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[3e8cc8b]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;
[b8efa56]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;
[3e8cc8b]10
11layout(location = 0) out vec4 frag_color;
12
13// fixed point light properties
14vec3 Ls = vec3(1.0, 1.0, 1.0);
15vec3 Ld = vec3(1.0, 1.0, 1.0);
16vec3 La = vec3(0.2, 0.2, 0.2);
17
18// surface reflectance
19vec3 Ks = vec3(1.0, 1.0, 1.0);
20vec3 Kd = vec3(1.0, 1.5, 1.0);
21vec3 Ka = vec3(0.2, 0.2, 0.2);
22float specular_exponent = 100.0; // specular 'power'
23
24void main() {
[6385d0f]25 // ambient intensity
26 vec3 Ia = La * Ka;
[3e8cc8b]27
[6385d0f]28 // ambient intensity
29 vec3 Ia2 = La * Ka;
[3e8cc8b]30
[6385d0f]31 vec3 direction_to_light_eye = normalize(light_position_eye - position_eye);
32 float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);
[3e8cc8b]33
[6385d0f]34 // diffuse intensity
35 vec3 Id = Ld * color * dot_prod;
[3e8cc8b]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);
[3e8cc8b]39
[6385d0f]40 // diffuse intensity
41 vec3 Id2 = Ld * color * dot_prod2;
[3e8cc8b]42
[6385d0f]43 vec3 surface_to_viewer_eye = normalize(-position_eye);
[3e8cc8b]44
[6385d0f]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);
[3e8cc8b]48
[6385d0f]49 vec3 reflection_eye2 = reflect(-direction_to_light2_eye, normal_eye);
50 float dot_prod_specular2 = max(dot(reflection_eye2, surface_to_viewer_eye), 0.0);
51 float specular_factor2 = pow(dot_prod_specular2, specular_exponent);
[3e8cc8b]52
[6385d0f]53 // specular intensity
54 vec3 Is = Ls * Ks * specular_factor;
[b8efa56]55 vec3 Is2 = Ls * Ks * specular_factor2 + vec3(fragTexCoord, 0.0) - vec3(fragTexCoord, 0.0);
[3e8cc8b]56
[6385d0f]57 frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0);
[3e8cc8b]58}
Note: See TracBrowser for help on using the repository browser.