KaleidoShader.js 989 B

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