KaleidoShader.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. console.warn( "THREE.KaleidoShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author felixturner / http://airtight.cc/
  4. *
  5. * Kaleidoscope Shader
  6. * Radial reflection around center point
  7. * Ported from: http://pixelshaders.com/editor/
  8. * by Toby Schachman / http://tobyschachman.com/
  9. *
  10. * sides: number of reflections
  11. * angle: initial angle in radians
  12. */
  13. THREE.KaleidoShader = {
  14. uniforms: {
  15. "tDiffuse": { value: null },
  16. "sides": { value: 6.0 },
  17. "angle": { value: 0.0 }
  18. },
  19. vertexShader: [
  20. "varying vec2 vUv;",
  21. "void main() {",
  22. " vUv = uv;",
  23. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  24. "}"
  25. ].join( "\n" ),
  26. fragmentShader: [
  27. "uniform sampler2D tDiffuse;",
  28. "uniform float sides;",
  29. "uniform float angle;",
  30. "varying vec2 vUv;",
  31. "void main() {",
  32. " vec2 p = vUv - 0.5;",
  33. " float r = length(p);",
  34. " float a = atan(p.y, p.x) + angle;",
  35. " float tau = 2. * 3.1416 ;",
  36. " a = mod(a, tau/sides);",
  37. " a = abs(a - tau/sides/2.) ;",
  38. " p = r * vec2(cos(a), sin(a));",
  39. " vec4 color = texture2D(tDiffuse, p + 0.5);",
  40. " gl_FragColor = color;",
  41. "}"
  42. ].join( "\n" )
  43. };