No Description

parallax.vert 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #version 450
  2. layout (location = 0) in vec3 inPos;
  3. layout (location = 1) in vec2 inUV;
  4. layout (location = 2) in vec3 inNormal;
  5. layout (location = 3) in vec3 inTangent;
  6. layout (location = 4) in vec3 inBiTangent;
  7. layout (binding = 0) uniform UBO
  8. {
  9. mat4 projection;
  10. mat4 view;
  11. mat4 model;
  12. vec4 lightPos;
  13. vec4 cameraPos;
  14. } ubo;
  15. layout (location = 0) out vec2 outUV;
  16. layout (location = 1) out vec3 outTangentLightPos;
  17. layout (location = 2) out vec3 outTangentViewPos;
  18. layout (location = 3) out vec3 outTangentFragPos;
  19. void main(void)
  20. {
  21. gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0f);
  22. outTangentFragPos = vec3(ubo.model * vec4(inPos, 1.0));
  23. outUV = inUV;
  24. vec3 T = normalize(mat3(ubo.model) * inTangent);
  25. vec3 B = normalize(mat3(ubo.model) * inBiTangent);
  26. vec3 N = normalize(mat3(ubo.model) * inNormal);
  27. mat3 TBN = transpose(mat3(T, B, N));
  28. outTangentLightPos = TBN * ubo.lightPos.xyz;
  29. outTangentViewPos = TBN * ubo.cameraPos.xyz;
  30. outTangentFragPos = TBN * outTangentFragPos;
  31. }