KaleidoShader.js 1.1 KB

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