gpuRenderParticles.vertex.fx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #version 300 es
  2. uniform vec4 colorDead;
  3. uniform mat4 view;
  4. uniform mat4 projection;
  5. // Particles state
  6. in vec3 position;
  7. in float age;
  8. in float life;
  9. in vec3 size;
  10. in vec4 color;
  11. in vec2 offset;
  12. in vec2 uv;
  13. in vec2 angle;
  14. out vec2 vUV;
  15. out vec4 vColor;
  16. #ifdef CLIPPLANE
  17. uniform vec4 vClipPlane;
  18. uniform mat4 invView;
  19. out float fClipDistance;
  20. #endif
  21. void main() {
  22. vUV = uv;
  23. float ratio = age / life;
  24. vColor = color * vec4(1.0 - ratio) + colorDead * vec4(ratio);
  25. vec2 cornerPos = offset * size.yz * size.x;
  26. // Rotate
  27. vec4 rotatedCorner;
  28. rotatedCorner.x = cornerPos.x * cos(angle.x) - cornerPos.y * sin(angle.x);
  29. rotatedCorner.y = cornerPos.x * sin(angle.x) + cornerPos.y * cos(angle.x);
  30. rotatedCorner.z = 0.;
  31. rotatedCorner.w = 0.;
  32. // Expand position
  33. vec4 viewPosition = view * vec4(position, 1.0);
  34. gl_Position = projection * (viewPosition + rotatedCorner);
  35. // Clip plane
  36. #ifdef CLIPPLANE
  37. vec4 worldPos = invView * viewPosition;
  38. fClipDistance = dot(worldPos, vClipPlane);
  39. #endif
  40. }