No Description

normalmap.vert 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (location = 0) in vec3 inPos;
  5. layout (location = 1) in vec2 inUV;
  6. layout (location = 2) in vec3 inNormal;
  7. layout (location = 3) in vec3 inTangent;
  8. layout (location = 4) in vec3 inBiTangent;
  9. layout (binding = 0) uniform UBO
  10. {
  11. mat4 projection;
  12. mat4 model;
  13. mat4 normal;
  14. vec4 lightPos;
  15. } ubo;
  16. out gl_PerVertex
  17. {
  18. vec4 gl_Position;
  19. };
  20. layout (location = 0) out vec2 outUV;
  21. layout (location = 1) out vec3 outLightVec;
  22. layout (location = 2) out vec3 outLightVecB;
  23. layout (location = 3) out vec3 outLightDir;
  24. layout (location = 4) out vec3 outViewVec;
  25. void main(void)
  26. {
  27. vec3 vertexPosition = vec3(ubo.model * vec4(inPos, 1.0));
  28. outLightDir = normalize(ubo.lightPos.xyz - vertexPosition);
  29. // Setup (t)angent-(b)inormal-(n)ormal matrix for converting
  30. // object coordinates into tangent space
  31. mat3 tbnMatrix;
  32. tbnMatrix[0] = mat3(ubo.normal) * inTangent;
  33. tbnMatrix[1] = mat3(ubo.normal) * inBiTangent;
  34. tbnMatrix[2] = mat3(ubo.normal) * inNormal;
  35. outLightVec.xyz = vec3(ubo.lightPos.xyz - vertexPosition) * tbnMatrix;
  36. vec3 lightDist = ubo.lightPos.xyz - inPos;
  37. outLightVecB.x = dot(inTangent, lightDist);
  38. outLightVecB.y = dot(inBiTangent, lightDist);
  39. outLightVecB.z = dot(inNormal, lightDist);
  40. outViewVec.x = dot(inTangent, inPos);
  41. outViewVec.y = dot(inBiTangent, inPos);
  42. outViewVec.z = dot(inNormal, inPos);
  43. outUV = inUV;
  44. gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0);
  45. }