particles.vs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 430
  2. uniform mat4 proj;
  3. uniform mat4 view;
  4. uniform float time;
  5. uniform float timeFactor;
  6. uniform float age;
  7. uniform vec3 position;
  8. uniform int seedBase;
  9. int seed = 0;
  10. out vec3 varOffsetA;
  11. out vec3 varOffsetB;
  12. out float varFade;
  13. float random() {
  14. seed = seed * 534534569 + 42334571;
  15. return float(seed & 0xFFFFFF) / float(0xFFFFFF);
  16. }
  17. void main(void) {
  18. seed = gl_VertexID * 3895924481 + seedBase * 2434483;
  19. float lengthAngle = random() * 6.283185307;
  20. float widthAngle = random() * 3.141592654 - 1.570796327;
  21. float sinWidth = sin(widthAngle);
  22. float cosWidth = cos(widthAngle);
  23. float sinLength = sin(lengthAngle);
  24. float cosLength = cos(lengthAngle);
  25. vec3 v = vec3(cosWidth * cosLength, sinWidth, -sinLength * cosWidth) * random();
  26. float realTime = max(time - age, 0.0) * timeFactor;
  27. float life = random() * 20.0 * float(realTime > 0.0);
  28. varFade = max(life - realTime, 0.0f) / life;
  29. varOffsetA = vec3(random(), random(), random()) * 2.0 - 1.0;
  30. varOffsetB = vec3(random(), random(), random()) * 2.0 - 1.0;
  31. gl_Position = vec4(position + v * realTime, 1.0);
  32. }