physical_vertex.glsl 1.1 KB

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