KaleidoShader.js 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. name: 'KaleidoShader',
  12. uniforms: {
  13. 'tDiffuse': { value: null },
  14. 'sides': { value: 6.0 },
  15. 'angle': { value: 0.0 }
  16. },
  17. vertexShader: /* glsl */`
  18. varying vec2 vUv;
  19. void main() {
  20. vUv = uv;
  21. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  22. }`,
  23. fragmentShader: /* glsl */`
  24. uniform sampler2D tDiffuse;
  25. uniform float sides;
  26. uniform float angle;
  27. varying vec2 vUv;
  28. void main() {
  29. vec2 p = vUv - 0.5;
  30. float r = length(p);
  31. float a = atan(p.y, p.x) + angle;
  32. float tau = 2. * 3.1416 ;
  33. a = mod(a, tau/sides);
  34. a = abs(a - tau/sides/2.) ;
  35. p = r * vec2(cos(a), sin(a));
  36. vec4 color = texture2D(tDiffuse, p + 0.5);
  37. gl_FragColor = color;
  38. }`
  39. };
  40. export { KaleidoShader };