particles.vertex.fx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Attributes
  2. attribute vec3 position;
  3. attribute vec4 color;
  4. attribute vec4 options;
  5. // Uniforms
  6. uniform mat4 view;
  7. uniform mat4 projection;
  8. // Output
  9. varying vec2 vUV;
  10. varying vec4 vColor;
  11. #ifdef CLIPPLANE
  12. uniform vec4 vClipPlane;
  13. uniform mat4 invView;
  14. varying float fClipDistance;
  15. #endif
  16. void main(void) {
  17. vec3 viewPos = (view * vec4(position, 1.0)).xyz;
  18. vec3 cornerPos;
  19. float size = options.y;
  20. float angle = options.x;
  21. vec2 offset = options.zw;
  22. cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;
  23. // Rotate
  24. vec3 rotatedCorner;
  25. rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);
  26. rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);
  27. rotatedCorner.z = 0.;
  28. // Position
  29. viewPos += rotatedCorner;
  30. gl_Position = projection * vec4(viewPos, 1.0);
  31. vColor = color;
  32. vUV = offset;
  33. // Clip plane
  34. #ifdef CLIPPLANE
  35. vec4 worldPos = invView * vec4(viewPos, 1.0);
  36. fClipDistance = dot(worldPos, vClipPlane);
  37. #endif
  38. }