Guest User

Untitled

a guest
Jul 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #version 330 core
  2.  
  3. // Input vertex data, different for all executions of this shader.
  4. layout(location = 0) in vec3 position_modelspace;
  5. layout(location = 1) in vec3 normal_modelspace;
  6.  
  7. uniform mat4 model;
  8. uniform mat4 view;
  9. uniform mat4 projection;
  10.  
  11. out vec3 normal_worldspace;
  12.  
  13. void main(){
  14.  
  15. //transform normal into worldspace
  16. normal_worldspace = normalize(vec3(model * vec4(normal_modelspace,0.0)));
  17.  
  18. //transform vertex position into screenspace
  19. vec4 v = vec4(position_modelspace,1);
  20. vec4 position_worldspace = model * v;
  21. gl_Position = projection * view * position_worldspace;
  22. }
  23.  
  24. ----------------------------
  25. #version 330 core
  26.  
  27. in vec3 normal_worldspace;
  28.  
  29. // Ouput data
  30. out vec3 color;
  31.  
  32. void main()
  33. {
  34. float intensity;
  35. vec3 lightDir;
  36. vec3 normal;
  37.  
  38. lightDir = normalize(vec3(1.0,0.0,1.0));
  39. normal = normalize(normal_worldspace);
  40. intensity = max(dot(lightDir,normal),0.0);
  41. // Output color = red
  42. color = (vec3(0.5f,0.5f,0.5f) * intensity) + vec3(0.2f,0.2f,0.2f) ;
  43. }
Add Comment
Please, Sign In to add comment