| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | /*All material copyright ESRI, All Rights Reserved, unless otherwise specified.See https://js.arcgis.com/4.25/esri/copyright.txt for details.*/import{unwrap as e}from"../core/maybe.js";import{s as r}from"./vec2.js";import{a as o}from"./vec2f64.js";import{ScreenSpacePass as t}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.js";import{ReadLinearDepth as a}from"../views/3d/webgl-engine/core/shaderLibrary/output/ReadLinearDepth.glsl.js";import{CameraSpace as n,getZScale as i}from"../views/3d/webgl-engine/core/shaderLibrary/util/CameraSpace.glsl.js";import{Float2PassUniform as s}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{FloatPassUniform as c}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as l}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as u}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{Texture2DPassUniform as f}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";const m=16,p=.5;function d(){const o=new u,d=o.fragment;return o.include(t),d.include(a),o.include(n),d.uniforms.add(new c("radius",((e,r)=>v(r)))),d.code.add(l`vec3 sphere[16];void fillSphere() {sphere[0] = vec3(0.186937, 0.0, 0.0);sphere[1] = vec3(0.700542, 0.0, 0.0);sphere[2] = vec3(-0.864858, -0.481795, -0.111713);sphere[3] = vec3(-0.624773, 0.102853, -0.730153);sphere[4] = vec3(-0.387172, 0.260319, 0.007229);sphere[5] = vec3(-0.222367, -0.642631, -0.707697);sphere[6] = vec3(-0.01336, -0.014956, 0.169662);sphere[7] = vec3(0.122575, 0.1544, -0.456944);sphere[8] = vec3(-0.177141, 0.85997, -0.42346);sphere[9] = vec3(-0.131631, 0.814545, 0.524355);sphere[10] = vec3(-0.779469, 0.007991, 0.624833);sphere[11] = vec3(0.308092, 0.209288,0.35969);sphere[12] = vec3(0.359331, -0.184533, -0.377458);sphere[13] = vec3(0.192633, -0.482999, -0.065284);sphere[14] = vec3(0.233538, 0.293706, -0.055139);sphere[15] = vec3(0.417709, -0.386701, 0.442449);}float fallOffFunction(float vv, float vn, float bias) {float f = max(radius * radius - vv, 0.0);return f * f * f * max(vn-bias, 0.0);}`),d.code.add(l`float aoValueFromPositionsAndNormal(vec3 C, vec3 n_C, vec3 Q) {vec3 v = Q - C;float vv = dot(v, v);float vn = dot(normalize(v), n_C);return fallOffFunction(vv, vn, 0.1);}`),d.uniforms.add([new s("nearFar",((e,r)=>r.camera.nearFar)),new f("normalMap",(e=>e.normalTexture)),new f("depthMap",(e=>e.depthTexture)),new s("zScale",((e,r)=>i(r))),new c("projScale",(e=>e.projScale)),new f("rnm",(e=>e.noiseTexture)),new s("rnmScale",((o,t)=>r(h,t.camera.fullWidth/e(o.noiseTexture).descriptor.width,t.camera.fullHeight/e(o.noiseTexture).descriptor.height))),new c("intensity",((e,r)=>4*p/v(r)**6)),new s("screenSize",((e,o)=>r(h,o.camera.fullWidth,o.camera.fullHeight)))]),d.code.add(l`    void main(void) {      fillSphere();      vec3 fres = normalize((texture2D(rnm, uv * rnmScale).xyz * 2.0) - vec3(1.0));      float currentPixelDepth = linearDepthFromTexture(depthMap, uv, nearFar);      if (-currentPixelDepth>nearFar.y || -currentPixelDepth<nearFar.x) {        gl_FragColor = vec4(0.0);        return;      }      vec3 currentPixelPos = reconstructPosition(gl_FragCoord.xy,currentPixelDepth);      // get the normal of current fragment      vec4 norm4 = texture2D(normalMap, uv);      vec3 norm = vec3(-1.0) + 2.0 * norm4.xyz;      bool isTerrain = norm4.w<0.5;      float sum = .0;      vec3 tapPixelPos;      // note: the factor 2.0 should not be necessary, but makes ssao much nicer.      // bug or deviation from CE somewhere else?      float ps = projScale / (2.0 * currentPixelPos.z * zScale.x + zScale.y);      for(int i = 0; i < ${l.int(m)}; ++i) {        vec2 unitOffset = reflect(sphere[i], fres).xy;        vec2 offset = vec2(-unitOffset * radius * ps);        //don't use current or very nearby samples        if ( abs(offset.x)<2.0 || abs(offset.y)<2.0) continue;        vec2 tc = vec2(gl_FragCoord.xy + offset);        if (tc.x < 0.0 || tc.y < 0.0 || tc.x > screenSize.x || tc.y > screenSize.y) continue;        vec2 tcTap = tc / screenSize;        float occluderFragmentDepth = linearDepthFromTexture(depthMap, tcTap, nearFar);        if (isTerrain) {          bool isTerrainTap = texture2D(normalMap, tcTap).w<0.5;          if (isTerrainTap) {            continue;          }        }        tapPixelPos = reconstructPosition(tc, occluderFragmentDepth);        sum+= aoValueFromPositionsAndNormal(currentPixelPos, norm, tapPixelPos);      }      // output the result      float A = max(1.0 - sum * intensity / float(${l.int(m)}),0.0);      // Anti-tone map to reduce contrast and drag dark region farther: (x^0.2 + 1.2 * x^4)/2.2      A = (pow(A, 0.2) + 1.2 * A*A*A*A) / 2.2;      gl_FragColor = vec4(A);    }  `),o}function v(e){return Math.max(10,20*e.camera.computeRenderPixelSizeAtDist(Math.abs(4*e.camera.relativeElevation)))}const h=o(),x=Object.freeze(Object.defineProperty({__proto__:null,build:d},Symbol.toStringTag,{value:"Module"}));export{x as S,d as b};
 |