MirrorShader.js 1.2 KB

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