ShadowCastAccumulate.glsl.js 2.7 KB

123456789101112131415161718192021222324252627282930313233
  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{a as e,v as a}from"./mat4.js";import{c as r}from"./mat4f64.js";import{ScreenSpacePass as o}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.js";import{ReadLinearDepth as s}from"../views/3d/webgl-engine/core/shaderLibrary/output/ReadLinearDepth.glsl.js";import{ReadShadowMapBindParameters as i,ReadShadowMapPass as t}from"../views/3d/webgl-engine/core/shaderLibrary/shading/ReadShadowMap.glsl.js";import{CameraSpace as d}from"../views/3d/webgl-engine/core/shaderLibrary/util/CameraSpace.glsl.js";import{RgbaFloatEncoding as l}from"../views/3d/webgl-engine/core/shaderLibrary/util/RgbaFloatEncoding.glsl.js";import{Float2PassUniform as n}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{glsl as c}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{Matrix4PassUniform as p}from"../views/3d/webgl-engine/core/shaderModules/Matrix4PassUniform.js";import{ShaderBuilder as h}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{Texture2DPassUniform as m}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";class w extends i{}const u=255,g=1/u;function v(r){const i=new h,w=i.fragment;return w.include(l),w.include(s),i.include(d),i.include(o),i.include(t,r),w.uniforms.add([new m("depthMap",(e=>e.linearDepthTexture)),new p("inverseViewMatrix",((r,o)=>e(f,a(f,o.camera.viewMatrix,o.camera.center)))),new n("nearFar",((e,a)=>a.camera.nearFar))]),w.constants.add("sampleValue","float",g),w.code.add(c`void main(void) {
  6. float depth = rgba2float(texture2D(depthMap, uv));
  7. if (depth == 0.0) {
  8. discard;
  9. }
  10. float currentPixelDepth = linearDepthFromFloat(depth, nearFar);
  11. if (-currentPixelDepth > nearFar.y || -currentPixelDepth < nearFar.x) {
  12. discard;
  13. }
  14. vec4 currentPixelPos = vec4(reconstructPosition(gl_FragCoord.xy, currentPixelDepth), 1.0);
  15. vec4 worldSpacePos = inverseViewMatrix * currentPixelPos;
  16. mat4 shadowMatrix;
  17. float linearDepth = -currentPixelDepth;
  18. int i = chooseCascade(linearDepth, shadowMatrix);
  19. if (i >= numCascades) {
  20. discard;
  21. }
  22. vec3 lvpos = lightSpacePosition(worldSpacePos.xyz, shadowMatrix);
  23. if (lvpos.z >= 1.0 || lvpos.x < 0.0 || lvpos.x > 1.0 || lvpos.y < 0.0 || lvpos.y > 1.0) {
  24. discard;
  25. }
  26. vec2 uvShadow = cascadeCoordinates(i, lvpos);
  27. float depthShadow = readShadowMapDepth(uvShadow, shadowMapTex);
  28. bool shadow = depthShadow < lvpos.z;
  29. if (!shadow) {
  30. discard;
  31. }
  32. gl_FragColor = vec4(sampleValue);
  33. }`),i}const f=r(),x=Object.freeze(Object.defineProperty({__proto__:null,ShadowCastAccumulatePassParameters:w,shadowCastMaxSamples:u,build:v},Symbol.toStringTag,{value:"Module"}));export{w as S,x as a,v as b,u as s};