phong_vertex.glsl 1.0 KB

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