No Description

scene.vert 1.1KB

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