KaleidoShader.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /** @module KaleidoShader */
  2. /**
  3. * Kaleidoscope Shader.
  4. * Radial reflection around center point
  5. * Ported from: {@link http://pixelshaders.com/editor/}
  6. * by [Toby Schachman]{@link http://tobyschachman.com/}
  7. *
  8. * sides: number of reflections
  9. * angle: initial angle in radians
  10. *
  11. * @constant
  12. * @type {Object}
  13. */
  14. const KaleidoShader = {
  15. name: 'KaleidoShader',
  16. uniforms: {
  17. 'tDiffuse': { value: null },
  18. 'sides': { value: 6.0 },
  19. 'angle': { value: 0.0 }
  20. },
  21. vertexShader: /* glsl */`
  22. varying vec2 vUv;
  23. void main() {
  24. vUv = uv;
  25. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  26. }`,
  27. fragmentShader: /* glsl */`
  28. uniform sampler2D tDiffuse;
  29. uniform float sides;
  30. uniform float angle;
  31. varying vec2 vUv;
  32. void main() {
  33. vec2 p = vUv - 0.5;
  34. float r = length(p);
  35. float a = atan(p.y, p.x) + angle;
  36. float tau = 2. * 3.1416 ;
  37. a = mod(a, tau/sides);
  38. a = abs(a - tau/sides/2.) ;
  39. p = r * vec2(cos(a), sin(a));
  40. vec4 color = texture2D(tDiffuse, p + 0.5);
  41. gl_FragColor = color;
  42. }`
  43. };
  44. export { KaleidoShader };
粤ICP备19079148号