Advertisement
Lucassim

vs

Aug 8th, 2013
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 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 vertexPosition_modelspace;
  5. layout(location = 1) in vec2 vertexUV;
  6. layout(location = 2) in vec3 vertexNormal_modelspace;
  7.  
  8. // Output data ; will be interpolated for each fragment.
  9. out vec2 UV;
  10. out vec3 Position_worldspace;
  11. out vec3 Normal_cameraspace;
  12. out vec3 EyeDirection_cameraspace;
  13. out vec3 LightDirection_cameraspace;
  14. out vec4 ShadowCoord;
  15.  
  16. // Values that stay constant for the whole mesh.
  17. uniform mat4 MVP;
  18. uniform mat4 V;
  19. uniform mat4 M;
  20. uniform vec3 LightInvDirection_worldspace;
  21. uniform mat4 DepthBiasMVP;
  22.  
  23.  
  24. void main(){
  25.  
  26.     // Output position of the vertex, in clip space : MVP * position
  27.     gl_Position =  MVP * vec4(vertexPosition_modelspace,1);
  28.    
  29.     ShadowCoord = DepthBiasMVP * vec4(vertexPosition_modelspace,1);
  30.    
  31.     // Position of the vertex, in worldspace : M * position
  32.     Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
  33.    
  34.     // Vector that goes from the vertex to the camera, in camera space.
  35.     // In camera space, the camera is at the origin (0,0,0).
  36.     EyeDirection_cameraspace = vec3(0,0,0) - ( V * M * vec4(vertexPosition_modelspace,1)).xyz;
  37.  
  38.     // Vector that goes from the vertex to the light, in camera space
  39.     LightDirection_cameraspace = (V*vec4(LightInvDirection_worldspace,0)).xyz;
  40.    
  41.     // Normal of the the vertex, in camera space
  42.     Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace,0)).xyz; // Only correct if ModelMatrix does not scale the model ! Use its inverse transpose if not.
  43.    
  44.     // UV of the vertex. No special space for this one.
  45.     UV = vertexUV;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement