Geen omschrijving

indirectdraw.vert 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. // Vertex attributes
  5. layout (location = 0) in vec4 inPos;
  6. layout (location = 1) in vec3 inNormal;
  7. layout (location = 2) in vec2 inUV;
  8. layout (location = 3) in vec3 inColor;
  9. // Instanced attributes
  10. layout (location = 4) in vec3 instancePos;
  11. layout (location = 5) in vec3 instanceRot;
  12. layout (location = 6) in float instanceScale;
  13. layout (location = 7) in int instanceTexIndex;
  14. layout (binding = 0) uniform UBO
  15. {
  16. mat4 projection;
  17. mat4 modelview;
  18. } ubo;
  19. layout (location = 0) out vec3 outNormal;
  20. layout (location = 1) out vec3 outColor;
  21. layout (location = 2) out vec3 outUV;
  22. layout (location = 3) out vec3 outViewVec;
  23. layout (location = 4) out vec3 outLightVec;
  24. out gl_PerVertex
  25. {
  26. vec4 gl_Position;
  27. };
  28. void main()
  29. {
  30. outColor = inColor;
  31. outUV = vec3(inUV, instanceTexIndex);
  32. outUV.t = 1.0 - outUV.t;
  33. mat4 mx, my, mz;
  34. // rotate around x
  35. float s = sin(instanceRot.x);
  36. float c = cos(instanceRot.x);
  37. mx[0] = vec4(c, s, 0.0, 0.0);
  38. mx[1] = vec4(-s, c, 0.0, 0.0);
  39. mx[2] = vec4(0.0, 0.0, 1.0, 0.0);
  40. mx[3] = vec4(0.0, 0.0, 0.0, 1.0);
  41. // rotate around y
  42. s = sin(instanceRot.y);
  43. c = cos(instanceRot.y);
  44. my[0] = vec4(c, 0.0, s, 0.0);
  45. my[1] = vec4(0.0, 1.0, 0.0, 0.0);
  46. my[2] = vec4(-s, 0.0, c, 0.0);
  47. my[3] = vec4(0.0, 0.0, 0.0, 1.0);
  48. // rot around z
  49. s = sin(instanceRot.z);
  50. c = cos(instanceRot.z);
  51. mz[0] = vec4(1.0, 0.0, 0.0, 0.0);
  52. mz[1] = vec4(0.0, c, s, 0.0);
  53. mz[2] = vec4(0.0, -s, c, 0.0);
  54. mz[3] = vec4(0.0, 0.0, 0.0, 1.0);
  55. mat4 rotMat = mz * my * mx;
  56. outNormal = inNormal * mat3(rotMat);
  57. vec4 pos = vec4((inPos.xyz * instanceScale) + instancePos, 1.0) * rotMat;
  58. gl_Position = ubo.projection * ubo.modelview * pos;
  59. vec4 wPos = ubo.modelview * vec4(pos.xyz, 1.0);
  60. vec4 lPos = vec4(0.0, -5.0, 0.0, 1.0);
  61. outLightVec = lPos.xyz - pos.xyz;
  62. outViewVec = -pos.xyz;
  63. }