MirrorShader.js 995 B

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