physical_vertex.glsl 1.2 KB

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