No Description

particle.vert 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (location = 0) in vec4 inPos;
  5. layout (location = 1) in vec4 inColor;
  6. layout (location = 2) in float inAlpha;
  7. layout (location = 3) in float inSize;
  8. layout (location = 4) in float inRotation;
  9. layout (location = 5) in int inType;
  10. layout (location = 0) out vec4 outColor;
  11. layout (location = 1) out float outAlpha;
  12. layout (location = 2) out flat int outType;
  13. layout (location = 3) out float outRotation;
  14. layout (binding = 0) uniform UBO
  15. {
  16. mat4 projection;
  17. mat4 modelview;
  18. vec2 viewportDim;
  19. float pointSize;
  20. } ubo;
  21. out gl_PerVertex
  22. {
  23. vec4 gl_Position;
  24. float gl_PointSize;
  25. };
  26. void main ()
  27. {
  28. outColor = inColor;
  29. outAlpha = inAlpha;
  30. outType = inType;
  31. outRotation = inRotation;
  32. gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz, 1.0);
  33. // Base size of the point sprites
  34. float spriteSize = 8.0 * inSize;
  35. // Scale particle size depending on camera projection
  36. vec4 eyePos = ubo.modelview * vec4(inPos.xyz, 1.0);
  37. vec4 projectedCorner = ubo.projection * vec4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w);
  38. gl_PointSize = ubo.viewportDim.x * projectedCorner.x / projectedCorner.w;
  39. }