Advertisement
Guest User

GLSL

a guest
Jan 22nd, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #shader vertex
  2. #version 330 core
  3.  
  4. layout(location = 0) in vec4 in_position;
  5. layout(location = 2) in vec3 in_normal;
  6.  
  7. out vec3 i_normal;
  8. out vec4 i_pos;
  9.  
  10. uniform mat4 uni_model;
  11. uniform mat4 uni_view;
  12. uniform mat4 uni_projection;
  13.  
  14. void main()
  15. {
  16. gl_Position = uni_projection * uni_view * uni_model * in_position;
  17. i_normal = in_normal;
  18. i_pos = uni_model * in_position;
  19. }
  20.  
  21. #shader end
  22.  
  23. #shader fragment
  24. #version 330 core
  25.  
  26. in vec3 i_normal;
  27. in vec4 i_pos;
  28.  
  29. out vec4 out_color;
  30.  
  31. uniform vec4 uni_color = vec4(1, 0, 0, 1);
  32. uniform vec3 uni_lightPos = vec3(0, 0.5, 0.2);
  33.  
  34. const vec3 lightColor = vec3(1, 1, 1);
  35.  
  36. void main()
  37. {
  38. float ambientStrength = 0.1;
  39. vec3 ambient = ambientStrength * lightColor;
  40.  
  41. vec3 norm = normalize(i_normal);
  42. vec3 lightDir = normalize(uni_lightPos);
  43.  
  44. float diff = max(dot(norm, lightDir), 0.0);
  45. vec3 diffuse = diff * lightColor;
  46.  
  47. vec3 result = (ambient + diffuse) * uni_color.xyz;
  48. out_color = vec4(result, 1.0);
  49. }
  50.  
  51. #shader end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement