KaleidoShader.js 1.0 KB

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