edges.vert.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Slightly adapted from https://github.com/mrdoob/three.js
  3. * MIT License Copyright (c) 2010-2020 three.js authors
  4. *
  5. * WebGL port of Subpixel Morphological Antialiasing (SMAA) v2.8
  6. * Preset: SMAA 1x Medium (with color edge detection)
  7. * https://github.com/iryoku/smaa/releases/tag/v2.8
  8. */
  9. export const edges_vert = `
  10. precision highp float;
  11. attribute vec2 aPosition;
  12. uniform vec2 uQuadScale;
  13. uniform vec2 uTexSizeInv;
  14. uniform vec4 uViewport;
  15. varying vec2 vUv;
  16. varying vec4 vOffset[3];
  17. void SMAAEdgeDetectionVS(vec2 texCoord) {
  18. vOffset[0] = texCoord.xyxy + uTexSizeInv.xyxy * vec4(-1.0, 0.0, 0.0, 1.0); // WebGL port note: Changed sign in W component
  19. vOffset[1] = texCoord.xyxy + uTexSizeInv.xyxy * vec4(1.0, 0.0, 0.0, -1.0); // WebGL port note: Changed sign in W component
  20. vOffset[2] = texCoord.xyxy + uTexSizeInv.xyxy * vec4(-2.0, 0.0, 0.0, 2.0); // WebGL port note: Changed sign in W component
  21. }
  22. void main() {
  23. vec2 scale = uViewport.zw * uTexSizeInv;
  24. vec2 shift = uViewport.xy * uTexSizeInv;
  25. vUv = (aPosition + 1.0) * 0.5 * scale + shift;
  26. SMAAEdgeDetectionVS(vUv);
  27. vec2 position = aPosition * uQuadScale - vec2(1.0, 1.0) + uQuadScale;
  28. gl_Position = vec4(position, 0.0, 1.0);
  29. }
  30. `;