MirrorShader.js 914 B

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