2
0

Phong.vert 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. // Request GLSL 3.3
  9. #version 330
  10. // Uniforms for world transform and view-proj
  11. uniform mat4 uWorldTransform;
  12. uniform mat4 uViewProj;
  13. // Attribute 0 is position, 1 is normal, 2 is tex coords.
  14. layout(location = 0) in vec3 inPosition;
  15. layout(location = 1) in vec3 inNormal;
  16. layout(location = 2) in vec2 inTexCoord;
  17. // Any vertex outputs (other than position)
  18. out vec2 fragTexCoord;
  19. // Normal (in world space)
  20. out vec3 fragNormal;
  21. // Position (in world space)
  22. out vec3 fragWorldPos;
  23. void main()
  24. {
  25. // Convert position to homogeneous coordinates
  26. vec4 pos = vec4(inPosition, 1.0);
  27. // Transform position to world space
  28. pos = pos * uWorldTransform;
  29. // Save world position
  30. fragWorldPos = pos.xyz;
  31. // Transform to clip space
  32. gl_Position = pos * uViewProj;
  33. // Transform normal into world space (w = 0)
  34. fragNormal = (vec4(inNormal, 0.0f) * uWorldTransform).xyz;
  35. // Pass along the texture coordinate to frag shader
  36. fragTexCoord = inTexCoord;
  37. }