Advertisement
Guest User

opengl vertex shader

a guest
Aug 16th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #version 330 core
  2.  
  3. layout (location = 0) in vec3 position_modelspace;
  4. layout (location = 1) in vec2 uv;
  5. layout (location = 2) in vec3 normal_modelspace;
  6.  
  7. out vec2 UV;
  8. out vec3 Position_worldspace;
  9. out vec3 Normal_cameraspace;
  10. out vec3 EyeDirection_cameraspace;
  11. out vec3 LightDirection_cameraspace;
  12.  
  13. uniform mat4 mvp;
  14. uniform mat4 viewMatrix;
  15. uniform mat4 modelMatrix;
  16. uniform vec3 lightPosition_worldspace;
  17.  
  18. void main() {
  19. gl_Position = mvp * vec4(position_modelspace, 1.0f);
  20.  
  21. Position_worldspace = (modelMatrix * vec4(position_modelspace, 1.0f)).xyz;
  22.  
  23. vec3 position_modelspaceCamera = (viewMatrix * modelMatrix * vec4(position_modelspace, 1.0f)).xyz;
  24. EyeDirection_cameraspace = vec3(0, 0, 0) - position_modelspaceCamera;
  25.  
  26. vec3 lightPosition_worldspaceCamera = (viewMatrix * vec4(lightPosition_worldspace, 1.0f)).xyz;
  27. LightDirection_cameraspace = lightPosition_worldspaceCamera + EyeDirection_cameraspace;
  28.  
  29. Normal_cameraspace = (viewMatrix * modelMatrix * vec4(normal_modelspace, 0.0f)).xyz;
  30. UV = uv;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement