standard_vertex.glsl 1.6 KB

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