physical_vertex.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Physically Based Shading of a microfacet surface material - Vertex Shader
  3. // Modified from reference implementation at https://github.com/KhronosGroup/glTF-WebGL-PBR
  4. //
  5. #include <attributes>
  6. // Model uniforms
  7. uniform mat4 ModelViewMatrix;
  8. uniform mat3 NormalMatrix;
  9. uniform mat4 MVP;
  10. #include <morphtarget_vertex_declaration>
  11. #include <bones_vertex_declaration>
  12. // Output variables for Fragment shader
  13. out vec3 Position;
  14. out vec3 Normal;
  15. out vec3 CamDir;
  16. out vec2 FragTexcoord;
  17. void main() {
  18. // Transform this vertex position to camera coordinates.
  19. Position = vec3(ModelViewMatrix * vec4(VertexPosition, 1.0));
  20. // Transform this vertex normal to camera coordinates.
  21. Normal = normalize(NormalMatrix * VertexNormal);
  22. // Calculate the direction vector from the vertex to the camera
  23. // The camera is at 0,0,0
  24. CamDir = normalize(-Position.xyz);
  25. // Output texture coordinates to fragment shader
  26. FragTexcoord = VertexTexcoord;
  27. vec3 vPosition = VertexPosition;
  28. mat4 finalWorld = mat4(1.0);
  29. #include <morphtarget_vertex>
  30. #include <bones_vertex>
  31. gl_Position = MVP * finalWorld * vec4(vPosition, 1.0);
  32. }