standard_vertex.glsl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include <morphtarget_vertex_declaration>
  13. // Outputs for the fragment shader.
  14. out vec3 ColorFrontAmbdiff;
  15. out vec3 ColorFrontSpec;
  16. out vec3 ColorBackAmbdiff;
  17. out vec3 ColorBackSpec;
  18. out vec2 FragTexcoord;
  19. void main() {
  20. // Transform this vertex normal to camera coordinates.
  21. vec3 Normal = normalize(NormalMatrix * VertexNormal);
  22. // Calculate this vertex position in camera coordinates
  23. vec4 Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  24. // Calculate the direction vector from the vertex to the camera
  25. // The camera is at 0,0,0
  26. vec3 camDir = normalize(-Position.xyz);
  27. // Calculates the vertex Ambient+Diffuse and Specular colors using the Phong model
  28. // for the front and back
  29. phongModel(Position, Normal, camDir, MatAmbientColor, MatDiffuseColor, ColorFrontAmbdiff, ColorFrontSpec);
  30. phongModel(Position, -Normal, camDir, MatAmbientColor, MatDiffuseColor, ColorBackAmbdiff, ColorBackSpec);
  31. vec2 texcoord = VertexTexcoord;
  32. #if MAT_TEXTURES > 0
  33. // Flips texture coordinate Y if requested.
  34. if (MatTexFlipY(0)) {
  35. texcoord.y = 1 - texcoord.y;
  36. }
  37. #endif
  38. FragTexcoord = texcoord;
  39. vec3 vPosition = VertexPosition;
  40. #include <morphtarget_vertex> [MORPHTARGETS]
  41. gl_Position = MVP * vec4(vPosition, 1.0);
  42. }