simple_shader.vert 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #version 450
  2. layout (location = 0) in vec3 inPosition;
  3. layout (location = 1) in vec3 inNormal;
  4. layout (location = 2) in vec4 inTangent;
  5. layout (location = 3) in vec2 inTexcoord;
  6. layout (location = 0) out struct VS_OUT
  7. {
  8. vec3 fragPos;
  9. vec2 texcoord;
  10. mat3 TBN;
  11. } vs_out;
  12. struct PointLight
  13. {
  14. vec4 position; // w is radius
  15. vec4 color; // w is intensity
  16. };
  17. layout (set = 0, binding = 0) uniform GlobalUBO
  18. {
  19. // MATRICES
  20. mat4 view;
  21. mat4 viewInverse;
  22. mat4 viewProjection;
  23. // LIGHTING
  24. vec4 globalLightDirection;
  25. vec4 ambientLighting;
  26. // POINT LIGHTS
  27. PointLight pointLights[8];
  28. int numLights;
  29. } ubo;
  30. layout (push_constant) uniform Push
  31. {
  32. mat4 model;
  33. } primitive;
  34. void main()
  35. {
  36. vec4 worldPos = primitive.model * vec4(inPosition, 1.0f);
  37. gl_Position = ubo.viewProjection * worldPos;
  38. vs_out.fragPos = worldPos.xyz;
  39. vs_out.texcoord = inTexcoord;
  40. // TBN
  41. vec3 T = normalize(mat3(primitive.model) * inTangent.xyz);
  42. vec3 N = normalize(mat3(primitive.model) * inNormal);
  43. T = normalize(T - dot(T, N) * N);
  44. vec3 B = cross(N, T) * inTangent.w;
  45. vs_out.TBN = mat3(T, B, N);
  46. }