particles.vertex.fx 1.1 KB

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