MirrorShader.js 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ( function () {
  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. const MirrorShader = {
  9. uniforms: {
  10. 'tDiffuse': {
  11. value: null
  12. },
  13. 'side': {
  14. value: 1
  15. }
  16. },
  17. vertexShader: `varying vec2 vUv;
  18. void main() {
  19. vUv = uv;
  20. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  21. }`,
  22. fragmentShader: `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. };
  40. THREE.MirrorShader = MirrorShader;
  41. } )();