standard_vertex.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <attributes>
  2. // Model uniforms
  3. uniform mat4 ModelViewMatrix;
  4. uniform mat3 NormalMatrix;
  5. uniform mat4 MVP;
  6. #include <material>
  7. #include <morphtarget_vertex_declaration>
  8. #include <bones_vertex_declaration>
  9. // Output variables for Fragment shader
  10. out vec4 Position;
  11. out vec3 Normal;
  12. out vec3 CamDir;
  13. out vec2 FragTexcoord;
  14. void main() {
  15. // Transform vertex position to camera coordinates
  16. Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  17. // Transform vertex normal to camera coordinates
  18. Normal = normalize(NormalMatrix * VertexNormal);
  19. // Calculate the direction vector from the vertex to the camera (origin)
  20. CamDir = normalize(-Position.xyz);
  21. vec2 texcoord = VertexTexcoord;
  22. #if MAT_TEXTURES > 0
  23. // Flip texture coordinate Y if requested.
  24. if (MatTexFlipY(0)) {
  25. texcoord.y = 1.0 - texcoord.y;
  26. }
  27. #endif
  28. FragTexcoord = texcoord;
  29. vec3 vPosition = VertexPosition;
  30. mat4 finalWorld = mat4(1.0);
  31. #include <morphtarget_vertex>
  32. #include <bones_vertex>
  33. // Output projected and transformed vertex position
  34. gl_Position = MVP * finalWorld * vec4(vPosition, 1.0);
  35. }