MirrorShader.js 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. uniforms: {
  9. 'tDiffuse': { value: null },
  10. 'side': { value: 1 }
  11. },
  12. vertexShader: /* glsl */`
  13. varying vec2 vUv;
  14. void main() {
  15. vUv = uv;
  16. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  17. }`,
  18. fragmentShader: /* glsl */`
  19. uniform sampler2D tDiffuse;
  20. uniform int side;
  21. varying vec2 vUv;
  22. void main() {
  23. vec2 p = vUv;
  24. if (side == 0){
  25. if (p.x > 0.5) p.x = 1.0 - p.x;
  26. }else if (side == 1){
  27. if (p.x < 0.5) p.x = 1.0 - p.x;
  28. }else if (side == 2){
  29. if (p.y < 0.5) p.y = 1.0 - p.y;
  30. }else if (side == 3){
  31. if (p.y > 0.5) p.y = 1.0 - p.y;
  32. }
  33. vec4 color = texture2D(tDiffuse, p);
  34. gl_FragColor = color;
  35. }`
  36. };
  37. export { MirrorShader };