standard_vertex.glsl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // Vertex shader standard
  3. //
  4. #include <attributes>
  5. // Model uniforms
  6. uniform mat4 ModelViewMatrix;
  7. uniform mat3 NormalMatrix;
  8. uniform mat4 MVP;
  9. #include <lights>
  10. #include <material>
  11. #include <phong_model>
  12. // Outputs for the fragment shader.
  13. out vec3 ColorFrontAmbdiff;
  14. out vec3 ColorFrontSpec;
  15. out vec3 ColorBackAmbdiff;
  16. out vec3 ColorBackSpec;
  17. out vec2 FragTexcoord;
  18. void main() {
  19. // Transform this vertex normal to camera coordinates.
  20. vec3 normal = normalize(NormalMatrix * VertexNormal);
  21. // Calculate this vertex position in camera coordinates
  22. vec4 position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  23. // Calculate the direction vector from the vertex to the camera
  24. // The camera is at 0,0,0
  25. vec3 camDir = normalize(-position.xyz);
  26. // Calculates the vertex Ambient+Diffuse and Specular colors using the Phong model
  27. // for the front and back
  28. phongModel(position, normal, camDir, MatAmbientColor, MatDiffuseColor, ColorFrontAmbdiff, ColorFrontSpec);
  29. phongModel(position, -normal, camDir, MatAmbientColor, MatDiffuseColor, ColorBackAmbdiff, ColorBackSpec);
  30. vec2 texcoord = VertexTexcoord;
  31. #if MAT_TEXTURES > 0
  32. // Flips texture coordinate Y if requested.
  33. if (MatTexFlipY(0)) {
  34. texcoord.y = 1 - texcoord.y;
  35. }
  36. #endif
  37. FragTexcoord = texcoord;
  38. gl_Position = MVP * vec4(VertexPosition, 1.0);
  39. }