Oebele

Broken Diffuse Lighting vertex shader

Jan 12th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #version 330
  2.  
  3. layout(location = 0) in vec4 position;
  4. layout(location = 2) in vec3 normal;
  5.  
  6. uniform vec3 dirToLightSource;
  7. uniform vec4 lightIntensity;
  8.  
  9. uniform mat4 cameraToClipMatrix;
  10. uniform mat4 modelToCameraMatrix;
  11. uniform mat3 normalModelToCameraMatrix;
  12.  
  13. uniform vec4 color;
  14.  
  15. out vec4 theColor;
  16.  
  17. void main()
  18. {
  19. gl_Position = (modelToCameraMatrix * position);
  20.  
  21. vec3 normCamSpace = normalize(modelToCameraMatrix * vec4(normal, 0)).xyz;
  22.  
  23. float cosAngIncidence = dot(normCamSpace, dirToLightSource);
  24. cosAngIncidence = clamp(cosAngIncidence, 0.0, 1.0);
  25.  
  26. theColor = lightIntensity * color * cosAngIncidence;
  27. theColor = vec4(normCamSpace, 1);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment