Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #version 330
  2.  
  3. layout(location = 0) in vec3 v_position;
  4. layout(location = 1) in vec3 v_normal;
  5. layout(location = 2) in vec2 v_texture_coord;
  6.  
  7. // Uniform properties
  8. uniform mat4 Model;
  9. uniform mat4 View;
  10. uniform mat4 Projection;
  11.  
  12. // Uniforms for light properties
  13. uniform vec3 light_position;
  14. uniform vec3 eye_position;
  15. uniform float material_kd;
  16. uniform float material_ks;
  17. uniform int material_shininess;
  18.  
  19. uniform vec3 object_color;
  20.  
  21. // Output value to fragment shader
  22. out vec3 color;
  23.  
  24. void main()
  25. {
  26. // TODO: compute world space vectors
  27. vec3 world_pos = (Model * vec4(v_position,1)).xyz;
  28. vec3 Npos = normalize( mat3(Model) * v_normal );
  29.  
  30. vec3 Lpos = normalize( light_position - world_pos );
  31. vec3 Vpos = normalize( eye_position - world_pos );
  32. vec3 Hpos = normalize( Lpos + Vpos );
  33.  
  34. // TODO: define ambient light component
  35. float ambient_light = 0.25;
  36.  
  37. // TODO: compute diffuse light component
  38. float dotNL = dot(Npos,Lpos);
  39. float diffuse_light;
  40. diffuse_light = max(dotNL, 0);
  41.  
  42. // TODO: compute specular light component
  43. float _specular_light = 0;
  44.  
  45. if (dotNL > 0)
  46. {
  47. _specular_light = pow(dotNL, material_shininess);
  48. }
  49.  
  50. float specular_light = (dotNL > 0 ? _specular_light : 0);
  51.  
  52. float light = ambient_light + diffuse_light + specular_light;
  53.  
  54. float look = distance(world_pos, eye_position);
  55. const float x = .01, y = .02, z = 1;
  56. float atten = 1 / (x * look * look + y * look + z);
  57. color = light * object_color * atten;
  58.  
  59. gl_Position = Projection * View * Model * vec4(v_position, 1.0);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement