MirrorShader.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. console.warn( "THREE.MirrorShader: 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. * Mirror Shader
  6. * Copies half the input to the other half
  7. *
  8. * side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom)
  9. */
  10. THREE.MirrorShader = {
  11. uniforms: {
  12. "tDiffuse": { value: null },
  13. "side": { value: 1 }
  14. },
  15. vertexShader: [
  16. "varying vec2 vUv;",
  17. "void main() {",
  18. " vUv = uv;",
  19. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  20. "}"
  21. ].join( "\n" ),
  22. fragmentShader: [
  23. "uniform sampler2D tDiffuse;",
  24. "uniform int side;",
  25. "varying vec2 vUv;",
  26. "void main() {",
  27. " vec2 p = vUv;",
  28. " if (side == 0){",
  29. " if (p.x > 0.5) p.x = 1.0 - p.x;",
  30. " }else if (side == 1){",
  31. " if (p.x < 0.5) p.x = 1.0 - p.x;",
  32. " }else if (side == 2){",
  33. " if (p.y < 0.5) p.y = 1.0 - p.y;",
  34. " }else if (side == 3){",
  35. " if (p.y > 0.5) p.y = 1.0 - p.y;",
  36. " } ",
  37. " vec4 color = texture2D(tDiffuse, p);",
  38. " gl_FragColor = color;",
  39. "}"
  40. ].join( "\n" )
  41. };