KaleidoShader.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/#manual/en/introduction/Installation." );
  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. THREE.KaleidoShader = {
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "sides": { value: 6.0 },
  15. "angle": { value: 0.0 }
  16. },
  17. vertexShader: [
  18. "varying vec2 vUv;",
  19. "void main() {",
  20. " vUv = uv;",
  21. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  22. "}"
  23. ].join( "\n" ),
  24. fragmentShader: [
  25. "uniform sampler2D tDiffuse;",
  26. "uniform float sides;",
  27. "uniform float angle;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. " vec2 p = vUv - 0.5;",
  31. " float r = length(p);",
  32. " float a = atan(p.y, p.x) + angle;",
  33. " float tau = 2. * 3.1416 ;",
  34. " a = mod(a, tau/sides);",
  35. " a = abs(a - tau/sides/2.) ;",
  36. " p = r * vec2(cos(a), sin(a));",
  37. " vec4 color = texture2D(tDiffuse, p + 0.5);",
  38. " gl_FragColor = color;",
  39. "}"
  40. ].join( "\n" )
  41. };