MirrorShader.js 961 B

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