phong_vertex.glsl 929 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // Output variables for Fragment shader
  11. out vec4 Position;
  12. out vec3 Normal;
  13. out vec3 CamDir;
  14. out vec2 FragTexcoord;
  15. void main() {
  16. // Transform this vertex position to camera coordinates.
  17. Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  18. // Transform this vertex normal to camera coordinates.
  19. Normal = normalize(NormalMatrix * VertexNormal);
  20. // Calculate the direction vector from the vertex to the camera
  21. // The camera is at 0,0,0
  22. CamDir = normalize(-Position.xyz);
  23. // Flips texture coordinate Y if requested.
  24. vec2 texcoord = VertexTexcoord;
  25. #if MAT_TEXTURES>0
  26. if (MatTexFlipY(0)) {
  27. texcoord.y = 1 - texcoord.y;
  28. }
  29. #endif
  30. FragTexcoord = texcoord;
  31. gl_Position = MVP * vec4(VertexPosition, 1.0);
  32. }