MirrorShader.js 952 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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:
  18. /* glsl */
  19. `
  20. varying vec2 vUv;
  21. void main() {
  22. vUv = uv;
  23. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  24. }`,
  25. fragmentShader:
  26. /* glsl */
  27. `
  28. uniform sampler2D tDiffuse;
  29. uniform int side;
  30. varying vec2 vUv;
  31. void main() {
  32. vec2 p = vUv;
  33. if (side == 0){
  34. if (p.x > 0.5) p.x = 1.0 - p.x;
  35. }else if (side == 1){
  36. if (p.x < 0.5) p.x = 1.0 - p.x;
  37. }else if (side == 2){
  38. if (p.y < 0.5) p.y = 1.0 - p.y;
  39. }else if (side == 3){
  40. if (p.y > 0.5) p.y = 1.0 - p.y;
  41. }
  42. vec4 color = texture2D(tDiffuse, p);
  43. gl_FragColor = color;
  44. }`
  45. };
  46. THREE.MirrorShader = MirrorShader;
  47. } )();