SSAOBlur.glsl.js 2.4 KB

1234567891011121314151617181920212223242526272829303132
  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{i as e}from"./vec3.js";import{ScreenSpacePass as r}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.js";import{ReadLinearDepth as o}from"../views/3d/webgl-engine/core/shaderLibrary/output/ReadLinearDepth.glsl.js";import{Float2DrawUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Float2DrawUniform.js";import{Float2PassUniform as a}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{FloatPassUniform as n}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as s}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as l}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{Texture2DDrawUniform as i}from"../views/3d/webgl-engine/core/shaderModules/Texture2DDrawUniform.js";import{Texture2DPassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";const f=4;function c(){const c=new l,u=c.fragment;c.include(r);const m=(f+1)/2,p=1/(2*m*m);return u.include(o),u.uniforms.add([new d("depthMap",(e=>e.depthTexture)),new i("tex",(e=>e.colorTexture)),new t("blurSize",(e=>e.blurSize)),new n("projScale",((r,o)=>{const t=e(o.camera.eye,o.camera.center);return t>5e4?Math.max(0,r.projScale-(t-5e4)):r.projScale})),new a("nearFar",((e,r)=>r.camera.nearFar))]),u.code.add(s`
  6. void blurFunction(vec2 uv, float r, float center_d, float sharpness, inout float wTotal, inout float bTotal) {
  7. float c = texture2D(tex, uv).r;
  8. float d = linearDepthFromTexture(depthMap, uv, nearFar);
  9. float ddiff = d - center_d;
  10. float w = exp(-r * r * ${s.float(p)} - ddiff * ddiff * sharpness);
  11. wTotal += w;
  12. bTotal += w * c;
  13. }
  14. `),u.code.add(s`
  15. void main(void) {
  16. float b = 0.0;
  17. float w_total = 0.0;
  18. float center_d = linearDepthFromTexture(depthMap, uv, nearFar);
  19. float sharpness = -0.05 * projScale / center_d;
  20. for (int r = -${s.int(f)}; r <= ${s.int(f)}; ++r) {
  21. float rf = float(r);
  22. vec2 uvOffset = uv + rf * blurSize;
  23. blurFunction(uvOffset, rf, center_d, sharpness, w_total, b);
  24. }
  25. gl_FragColor = vec4(b / w_total);
  26. }
  27. `),c}const u=Object.freeze(Object.defineProperty({__proto__:null,build:c},Symbol.toStringTag,{value:"Module"}));export{u as S,c as b};