No Description

scene.vert 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 vec3 inNormal;
  6. layout (location = 2) in vec2 inUV;
  7. layout (location = 3) in vec3 inColor;
  8. layout (set = 0, binding = 0) uniform UBO
  9. {
  10. mat4 projection;
  11. mat4 view;
  12. mat4 model;
  13. vec4 lightPos;
  14. } ubo;
  15. layout (location = 0) out vec3 outNormal;
  16. layout (location = 1) out vec3 outColor;
  17. layout (location = 2) out vec2 outUV;
  18. layout (location = 3) out vec3 outViewVec;
  19. layout (location = 4) out vec3 outLightVec;
  20. out gl_PerVertex
  21. {
  22. vec4 gl_Position;
  23. };
  24. void main()
  25. {
  26. outNormal = inNormal;
  27. outColor = inColor;
  28. outUV = inUV;
  29. mat4 modelView = ubo.view * ubo.model;
  30. gl_Position = ubo.projection * modelView * vec4(inPos.xyz, 1.0);
  31. vec4 pos = modelView * vec4(inPos, 0.0);
  32. outNormal = mat3(ubo.model) * inNormal;
  33. vec3 lPos = mat3(ubo.model) * ubo.lightPos.xyz;
  34. outLightVec = lPos - (ubo.model * vec4(inPos, 1.0)).xyz;
  35. outViewVec = -(ubo.model * vec4(inPos, 1.0)).xyz;
  36. }