KaleidoShader.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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:
  24. /* glsl */
  25. `
  26. varying vec2 vUv;
  27. void main() {
  28. vUv = uv;
  29. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  30. }`,
  31. fragmentShader:
  32. /* glsl */
  33. `
  34. uniform sampler2D tDiffuse;
  35. uniform float sides;
  36. uniform float angle;
  37. varying vec2 vUv;
  38. void main() {
  39. vec2 p = vUv - 0.5;
  40. float r = length(p);
  41. float a = atan(p.y, p.x) + angle;
  42. float tau = 2. * 3.1416 ;
  43. a = mod(a, tau/sides);
  44. a = abs(a - tau/sides/2.) ;
  45. p = r * vec2(cos(a), sin(a));
  46. vec4 color = texture2D(tDiffuse, p + 0.5);
  47. gl_FragColor = color;
  48. }`
  49. };
  50. THREE.KaleidoShader = KaleidoShader;
  51. } )();