KaleidoShader.js 1.0 KB

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. THREE.KaleidoShader = {
  11. uniforms: {
  12. "tDiffuse": { value: null },
  13. "sides": { value: 6.0 },
  14. "angle": { value: 0.0 }
  15. },
  16. vertexShader: [
  17. "varying vec2 vUv;",
  18. "void main() {",
  19. " vUv = uv;",
  20. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  21. "}"
  22. ].join( "\n" ),
  23. fragmentShader: [
  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. ].join( "\n" )
  40. };