Nenhuma descrição

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 (location = 4) in vec4 inBoneWeights;
  9. layout (location = 5) in ivec4 inBoneIDs;
  10. #define MAX_BONES 64
  11. layout (binding = 0) uniform UBO
  12. {
  13. mat4 projection;
  14. mat4 view;
  15. mat4 model;
  16. mat4 bones[MAX_BONES];
  17. vec4 lightPos;
  18. vec4 viewPos;
  19. } ubo;
  20. layout (location = 0) out vec3 outNormal;
  21. layout (location = 1) out vec3 outColor;
  22. layout (location = 2) out vec2 outUV;
  23. layout (location = 3) out vec3 outViewVec;
  24. layout (location = 4) out vec3 outLightVec;
  25. out gl_PerVertex
  26. {
  27. vec4 gl_Position;
  28. };
  29. void main()
  30. {
  31. mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0];
  32. boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1];
  33. boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2];
  34. boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3];
  35. outColor = inColor;
  36. outUV = inUV;
  37. gl_Position = ubo.projection * ubo.view * ubo.model * boneTransform * vec4(inPos.xyz, 1.0);
  38. vec4 pos = ubo.model * vec4(inPos, 1.0);
  39. outNormal = mat3(inverse(transpose(ubo.model * boneTransform))) * inNormal;
  40. outLightVec = ubo.lightPos.xyz - pos.xyz;
  41. outViewVec = ubo.viewPos.xyz - pos.xyz;
  42. }