Blur.glsl.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{glsl as e}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as o}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{Texture2DPassUniform as r}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{VertexAttribute as t}from"../views/3d/webgl-engine/lib/VertexAttribute.js";import{addResolutionUniform as s}from"../views/3d/webgl-engine/shaders/SMAAPassParameters.js";function d(){const d=new o,{attributes:f,varyings:i,vertex:n,fragment:x}=d;return f.add(t.POSITION,"vec2"),i.add("fTexCoord","vec2"),i.add("fOffset[2]","vec4"),s(n),n.code.add(e`void SMAANeighborhoodBlendingVS( vec2 texcoord ) {
  6. fOffset[0] = texcoord.xyxy + resolution.xyxy * vec4( -1.0, 0.0, 0.0, 1.0 );
  7. fOffset[1] = texcoord.xyxy + resolution.xyxy * vec4( 1.0, 0.0, 0.0, -1.0 );
  8. }
  9. void main() {
  10. fTexCoord = (position + 1.0 ) * 0.5;
  11. gl_Position = vec4(position, 0, 1);
  12. SMAANeighborhoodBlendingVS(fTexCoord);
  13. }`),x.uniforms.add(new r("tBlendWeights",(e=>e.blend.colorTexture))),x.uniforms.add(new r("tColor",(e=>e.colorTexture))),s(x),x.code.add(e`vec4 SMAANeighborhoodBlendingPS( vec2 texcoord, vec4 offset[ 2 ], sampler2D colorTex, sampler2D blendTex ) {
  14. vec4 a;
  15. a.xz = texture2D( blendTex, texcoord ).xz;
  16. a.y = texture2D( blendTex, offset[ 1 ].zw ).g;
  17. a.w = texture2D( blendTex, offset[ 1 ].xy ).a;
  18. if ( dot(a, vec4( 1.0, 1.0, 1.0, 1.0 )) < 1e-5 ) {
  19. return texture2D( colorTex, texcoord, 0.0 );
  20. } else {
  21. vec2 offset;
  22. offset.x = a.a > a.b ? a.a : -a.b;
  23. offset.y = a.g > a.r ? -a.g : a.r;
  24. if ( abs( offset.x ) > abs( offset.y )) {
  25. offset.y = 0.0;
  26. } else {
  27. offset.x = 0.0;
  28. }
  29. vec4 C = texture2D( colorTex, texcoord, 0.0 );
  30. texcoord += sign( offset ) * resolution.xy;
  31. vec4 Cop = texture2D( colorTex, texcoord, 0.0 );
  32. float s = abs( offset.x ) > abs( offset.y ) ? abs( offset.x ) : abs( offset.y );
  33. vec4 mixed = mix(C, Cop, s);
  34. return mixed;
  35. }
  36. }
  37. void main() {
  38. gl_FragColor = SMAANeighborhoodBlendingPS( fTexCoord, fOffset, tColor, tBlendWeights );
  39. }`),d}const f=Object.freeze(Object.defineProperty({__proto__:null,build:d},Symbol.toStringTag,{value:"Module"}));export{f as B,d as b};