u-space 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.js +411 -373
- package/dist/plugins/atmosphere/index.cjs +1 -1
- package/dist/plugins/atmosphere/index.js +3255 -129
- package/dist/plugins/atmosphere/threeR185Compat.d.ts +2 -0
- package/dist/plugins/fire/FireEffect.d.ts +90 -0
- package/dist/plugins/fire/index.cjs +1 -0
- package/dist/plugins/fire/index.d.ts +1 -0
- package/dist/plugins/fire/index.js +433 -0
- package/dist/plugins/u-manager/index.cjs +60 -60
- package/dist/plugins/u-manager/index.d.ts +3 -0
- package/dist/plugins/u-manager/index.js +10070 -9660
- package/dist/plugins/u-manager/instances/SemanticInstanceObject.d.ts +37 -0
- package/dist/plugins/u-manager/instances/SemanticModelInstancedLayer.d.ts +33 -0
- package/dist/plugins/u-manager/instances/index.d.ts +2 -0
- package/dist/plugins/u-manager/loaders/SceneInstancedLayer.d.ts +13 -0
- package/dist/plugins/u-manager/loaders/SceneLoader.d.ts +5 -5
- package/dist/plugins/u-manager/loaders/UManagerLoader.d.ts +24 -0
- package/dist/plugins/u-manager/semantics/SemanticLoader.d.ts +2 -2
- package/dist/plugins/u-manager/semantics/SemanticParser.d.ts +3 -3
- package/dist/plugins/u-manager/semantics/index.d.ts +1 -1
- package/dist/plugins/u-manager/semantics/objects/BuildingGroup.d.ts +4 -10
- package/dist/plugins/u-manager/semantics/objects/FacilityInstancedLayer.d.ts +5 -24
- package/dist/plugins/u-manager/semantics/objects/FloorMesh.d.ts +30 -15
- package/dist/plugins/u-manager/semantics/objects/SemanticGroup.d.ts +26 -0
- package/dist/plugins/u-manager/semantics/types.d.ts +1 -0
- package/dist/src/effects/MaterialEffects.d.ts +1 -0
- package/dist/src/tools/AnnotationManager.d.ts +4 -1
- package/dist/src/viewers/RenderPipeline.d.ts +6 -5
- package/docs/api-effects.md +3 -0
- package/docs/api-interactions.md +1 -0
- package/docs/api-managers.md +1 -1
- package/docs/api-plugin-fire.md +174 -0
- package/docs/api-plugin-u-manager.md +249 -57
- package/docs/api-tools.md +1 -1
- package/docs/changelog.md +41 -8
- package/docs/examples-guide.md +39 -13
- package/docs/getting-started.md +1 -1
- package/docs/index.md +1 -0
- package/docs/mcp.md +34 -1
- package/package.json +4 -4
- package/dist/plugins/u-manager/semantics/objects/SemanticSceneGroup.d.ts +0 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("three/webgpu"),i=require("three/tsl"),o=require("@takram/three-geospatial/webgpu"),m=require("@takram/three-atmosphere"),d=require("@takram/three-atmosphere/webgpu"),p=require("@takram/three-geospatial"),x=i.mat3(i.vec3(1.6605,-.1246,-.0182),i.vec3(-.5876,1.1329,-.1006),i.vec3(-.0728,-.0083,1.1187)),y=i.mat3(i.vec3(.6274,.0691,.0164),i.vec3(.3293,.9195,.088),i.vec3(.0433,.0113,.8956)),C=o.FnVar(s=>{const e=s.pow2().toConst(),t=e.pow2().toConst();return i.add(t.mul(e).mul(15.5),t.mul(s).mul(-40.14),t.mul(31.96),e.mul(s).mul(-6.868),e.mul(.4298),s.mul(.1191),-.00232)}),M=i.mat3(i.vec3(.856627153315983,.137318972929847,.11189821299995),i.vec3(.0951212405381588,.761241990602591,.0767994186031903),i.vec3(.0482516061458583,.101439036467562,.811302368396859)),S=i.mat3(i.vec3(1.1271005818144368,-.1413297634984383,-.14132976349843826),i.vec3(-.11060664309660323,1.157823702216272,-.11060664309660294),i.vec3(-.016493938717834573,-.016493938717834257,1.2519364065950405)),v=-12.47393,T=4.026069,b=o.FnLayout({name:"agx",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]})(([s,e])=>{const t=s.toVar(),n=e;return t.mulAssign(n),t.assign(y.mul(t)),t.assign(M.mul(t)),t.assign(i.log2(t.max(1e-10))),t.assign(t.sub(v).div(i.float(T).sub(v))),t.assign(t.saturate()),t.assign(C(t)),t}),F=o.FnLayout({name:"agxEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]})(([s])=>{const e=s.toVar();return e.assign(S.mul(e)),e.assign(i.pow(e.max(0),i.float(2.2))),e.assign(x.mul(e)),e.assign(e.saturate()),e}),A=o.FnLayout({name:"agxPunchyToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]})(([s,e])=>{const t=s.toVar(),n=e;return t.assign(b(t,n.mul(1.5))),t.assign(i.cdl(t,i.vec3(1),i.vec3(0),i.vec3(1.35),i.float(1.2))),t.assign(F(t)),t}),w=100;function g(){const s=new Date;return s.setHours(8,0,0,0),s}const P={longitude:0,latitude:0,height:0,date:0,showSun:!0,showMoon:!0,showStars:!0,showGround:!1,useSkyEnvironment:!0,raymarchScattering:!0,lighting:!0,transmittance:!0,inscattering:!0,moonScattering:!0,lensFlare:!0,temporalAntialias:!0,dithering:!0,toneMapping:w,toneMappingExposure:3,castShadow:!0,shadowMapSize:4096,shadowCameraSize:180,shadowCameraNear:10,shadowCameraFar:6e3,shadowBias:-2e-5,shadowNormalBias:.001,shadowRadius:1.5,shadowDistance:3e3};class R{viewer;#r=!1;#e={...P,date:g()};#l=null;#i=null;#t=null;#s=null;#n=null;#h=null;#d=null;#a=[];#u=null;#g;#p;#v=!1;#c=!1;#w=new u.Matrix4;#m=new u.Vector3;constructor(e){this.viewer=e}get enabled(){return this.#r}get context(){return this.#i}get light(){return this.#t}enable(e={}){return this.#r?this.update(e):(this.#e=this.#f(e),this.#l=new d.AtmosphereParameters,this.#i=new d.AtmosphereContext(this.#l),this.#i.camera=this.viewer.camera,this.#E(),this.#R(),this.#L(),this.#D(),this.#k(),this.#O(),this.#V(),this.#I(),this.updateDate(this.#e.date),this.#M(),this.#r=!0,this.viewer.render(),this)}update(e={}){return this.#e=this.#f(e),this.#i?(this.#E(),this.#y(),this.#C(),this.#N(),this.#S(),this.#U(),this.updateDate(this.#e.date),this.#M(),this.viewer.render(),this):this}setLocation(e,t,n=this.#e.height){return this.update({longitude:e,latitude:t,height:n})}setDate(e){return this.updateDate(e)}updateDate(e=g()){return this.#e.date=e,this.#F(),this.viewer.render(),this}disable(){return this.#r?(this.#B(),this.#_(),this.viewer.renderPipeline.removeOutputEffect(this.#o),this.#T(),this.#o.includesTemporalAntialias=!1,this.viewer.renderPipeline.needsUpdate=!0,this.#b(),this.#t&&(this.#t.target.removeFromParent(),this.#t.removeFromParent(),this.#t.dispose(),this.#t=null),this.viewer.scene.backgroundNode=this.#g,this.viewer.scene.environmentNode=this.#p,this.#u&&(this.viewer.renderer.contextNode=this.#u,this.#u=null),this.viewer.renderer.highPrecision=this.#v,this.#i?.dispose(),this.#i=null,this.#l=null,this.#s=null,this.#n=null,this.#r=!1,this.viewer.render(),this):this}dispose(){return this.disable()}#f(e){return{...this.#e,...e,date:e.date??(this.#r?this.#e.date:g())}}#E(){if(!this.#i)return;const t=new p.Geodetic(p.radians(this.#e.longitude),p.radians(this.#e.latitude),this.#e.height).toECEF(new u.Vector3);p.Ellipsoid.WGS84.getNorthUpEastFrame(t,this.#w),this.#i.camera=this.viewer.camera,this.#i.showGround=this.#e.showGround,this.#i.raymarchScattering=this.#e.raymarchScattering,this.#i.matrixWorldToECEF.value.copy(this.#w)}#R(){if(!this.#i)return;const e=this.viewer.renderer;this.#u=e.contextNode,this.#v=e.highPrecision,e.highPrecision=!0,e.contextNode=i.context({...e.contextNode.value,getAtmosphere:()=>this.#i})}#L(){const e=this.viewer.renderer;e.library.addLight(d.AtmosphereLightNode,d.AtmosphereLight),e.shadowMap.enabled=!0,this.#t=new d.AtmosphereLight,this.#N(),this.viewer.scene.add(this.#t.target),this.#x(),this.viewer.scene.add(this.#t)}#N(){if(!this.#t)return;const{castShadow:e,shadowMapSize:t,shadowCameraSize:n,shadowCameraNear:r,shadowCameraFar:c,shadowBias:a,shadowNormalBias:f,shadowRadius:E,shadowDistance:N}=this.#e,l=n/2,h=this.#t.shadow.camera;this.#t.castShadow=e,this.#t.distance=N,this.#t.shadow.mapSize.setScalar(t),this.#t.shadow.bias=a,this.#t.shadow.normalBias=f,this.#t.shadow.radius=E,h.left=-l,h.right=l,h.top=l,h.bottom=-l,h.near=r,h.far=c,h.updateProjectionMatrix(),this.#t.shadow.needsUpdate=!0}#x(){this.#t&&(this.viewer.controls.getTarget(this.#t.target.position),this.#t.target.updateMatrixWorld())}#D(){this.#g=this.viewer.scene.backgroundNode,this.#p=this.viewer.scene.environmentNode,this.#s=d.skyBackground(),this.#C(),this.#y(),this.viewer.scene.backgroundNode=this.#s}#y(){this.#s&&(this.#s.showSun=this.#e.showSun,this.#s.showMoon=this.#e.showMoon,this.#s.showStars=this.#e.showStars,this.#s.moonScattering=this.#e.moonScattering)}#C(){if(!this.#e.useSkyEnvironment){this.#n&&this.viewer.scene.environmentNode===this.#n&&(this.viewer.scene.environmentNode=this.#p),this.#n=null;return}this.#n??=d.skyEnvironment(),this.viewer.scene.environmentNode=this.#n}#M(){for(const e of[this.#s,this.#n])e&&(e.needsUpdate=!0);this.viewer.renderPipeline.needsUpdateOutputNode=!0}#k(){this.viewer.renderer.library.addToneMapping(A,w)}#O(){this.#o.includesOutputTransform=!0,this.#S(),this.viewer.renderPipeline.addOutputEffect(this.#o)}#S(){if(this.#o.includesTemporalAntialias=this.#e.temporalAntialias,this.#e.temporalAntialias){this.#c||(this.viewer.renderPipeline.addMRTChannel("atmosphereVelocity",o.highpVelocity),this.#c=!0);return}this.#T()}#T(){this.#c&&(this.viewer.renderPipeline.removeMRTChannel("atmosphereVelocity"),this.#c=!1)}#U(){this.#r&&(this.viewer.renderPipeline.needsUpdateOutputNode=!0)}#b(){for(const e of this.#a)e.dispose();this.#a=[],this.#h=null,this.#d=null}#o=(e,t)=>{const n=e.getTextureNode("depth");this.#b();let r=t;if(this.#e.lensFlare&&(this.#h=o.lensFlare(r),this.#a.push(this.#h),r=this.#h),this.#e.toneMapping!==!1&&this.#e.toneMapping!==u.NoToneMapping){const a=i.toneMapping(this.#e.toneMapping,this.#e.toneMappingExposure,r);this.#a.push(a),r=a}if(this.#e.temporalAntialias){const a=e.getTextureNode("atmosphereVelocity");this.#d=o.temporalAntialias(r,n,a,this.viewer.camera),this.#a.push(this.#d),r=this.#d}if(this.#e.dithering){const a=i.add(r,o.dithering);this.#a.push(a),r=a}const c=i.renderOutput(r,u.NoToneMapping);return this.#a.push(c),c};#F(){if(!this.#i)return;this.viewer.camera.updateMatrixWorld(),this.#m.setFromMatrixPosition(this.viewer.camera.matrixWorld).applyMatrix4(this.#i.matrixWorldToECEF.value);const e=this.#i.matrixECIToECEF.value;m.getECIToECEFRotationMatrix(this.#e.date,e),m.getSunDirectionECI(this.#e.date,this.#i.sunDirectionECEF.value,this.#m).applyMatrix4(e),m.getMoonDirectionECI(this.#e.date,this.#i.moonDirectionECEF.value,this.#m).applyMatrix4(e)}#V(){this.viewer.addEventListener("cameraChange",this.#A)}#B(){this.viewer.removeEventListener("cameraChange",this.#A)}#I(){this.viewer.addEventListener("beforeRender",this.#P)}#_(){this.viewer.removeEventListener("beforeRender",this.#P)}#A=({camera:e})=>{this.#i&&(this.#i.camera=e,this.updateDate(this.#e.date))};#P=()=>{this.#x(),this.#F()}}exports.Atmosphere=R;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("three/webgpu"),t=require("three/tsl"),x=require("three");require("three/examples/jsm/csm/CSMShadowNode.js");const _e=require("three/src/nodes/core/NodeUtils.js"),be=require("@takram/three-atmosphere"),q=require("@takram/three-geospatial");var jt="Invariant failed";function V(s,e){if(!s)throw new Error(jt)}let Me;function pe(s,e,i){Me??=new WeakMap;let r=Me.get(s);return r==null&&(r={},Me.set(s,r)),r[e]??=i()}const Wt=s=>s!=null?pe(s,"projectionMatrix",()=>t.reference("projectionMatrix","mat4",s).setName("projectionMatrix")):t.cameraProjectionMatrix,Ht=s=>s!=null?pe(s,"inverseProjectionMatrix",()=>t.reference("projectionMatrixInverse","mat4",s).setName("inverseProjectionMatrix")):t.cameraProjectionMatrixInverse,_t=s=>s!=null?pe(s,"inverseViewMatrix",()=>t.reference("matrixWorld","mat4",s).setName("inverseViewMatrix")):t.cameraWorldMatrix,he=s=>s!=null?pe(s,"cameraNear",()=>t.reference("near","float",s).setName("cameraNear")):t.cameraNear,me=s=>s!=null?pe(s,"cameraFar",()=>t.reference("far","float",s).setName("cameraFar")):t.cameraFar;t.Fn(()=>t.positionView.z).once()().toVar("viewZ");class Qt extends T.TextureNode{static get type(){return"OutputTextureNode"}constructor(e,i){super(i),this.owner=e,this.setUpdateMatrix(!1)}setup(e){return this.owner.build(e),super.setup(e)}clone(){const e=new this.constructor(this.owner,this.value);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}const ae=(...s)=>new Qt(...s);let Ce=class extends T.TempNode{constructor(e){super("vec4"),this.resolutionScale=1,this.renderTargets=[],this.updateBeforeType=T.NodeUpdateType.FRAME,this.inputNode=e}static get type(){return"FilterNode"}createRenderTarget(e){const i=new x.RenderTarget(1,1,{depthBuffer:!1,type:x.HalfFloatType,format:x.RGBAFormat}),r=i.texture;r.minFilter=x.LinearFilter,r.magFilter=x.LinearFilter,r.generateMipmaps=!1;const n=this.constructor.type;return r.name=e!=null?`${n}_${e}`:n,this.renderTargets.push(i),i}getTextureNode(){return V(this.textureNode!=null),this.textureNode}get outputTexture(){return this.textureNode?.value??null}set outputTexture(e){this.textureNode=e!=null?ae(this,e):void 0}setup(e){const{inputNode:i,textureNode:r}=this;return V(i!=null),V(r!=null),r.uvNode=i.uvNode,r}dispose(){for(const e of this.renderTargets)e.dispose();super.dispose()}};const{resetRendererState:Zt,restoreRendererState:Kt}=T.RendererUtils;let Jt=class extends Ce{constructor(e,i){super(e),this.downsampleRTs=[],this.upsampleRTs=[],this.downsampleMaterial=new T.NodeMaterial,this.upsampleMaterial=new T.NodeMaterial,this.mesh=new T.QuadMesh,this.inputTexelSize=t.uniform("vec2"),this.downsampleNode=t.texture();const r=this.constructor.type.replace(/Node$/,"");this.downsampleMaterial.name=`${r}_downsample`,this.upsampleMaterial.name=`${r}_upsample`,this.mesh.name=r;for(let n=0;n<i;++n)this.downsampleRTs[n]=this.createRenderTarget(`downsample${n}`),n<i-1&&(this.upsampleRTs[n]=this.createRenderTarget(`upsample${n}`));this.outputTexture=this.upsampleRTs[0].texture}setSize(e,i){const{resolutionScale:r}=this;let n=Math.max(Math.round(e*r),1),a=Math.max(Math.round(i*r),1);const{downsampleRTs:o,upsampleRTs:u}=this;for(let c=0;c<o.length;++c)n=Math.max(Math.round(n/2),1),a=Math.max(Math.round(a/2),1),o[c].setSize(n,a),c<u.length&&u[c].setSize(n,a);return this}updateBefore({renderer:e}){if(e==null)return;const{downsampleRTs:i,upsampleRTs:r,mesh:n,inputNode:a,inputTexelSize:o,downsampleNode:u}=this;V(a!=null);const{width:c,height:l}=a.value;this.setSize(c,l);const d=a.value;this.rendererState=Zt(e,this.rendererState),n.material=this.downsampleMaterial;for(const h of i){const{width:m,height:p}=a.value;o.value.set(1/m,1/p),e.setRenderTarget(h),n.render(e),a.value=h.texture}n.material=this.upsampleMaterial;for(let h=r.length-1;h>=0;--h){const m=r[h],{width:p,height:g}=a.value;o.value.set(1/p,1/g),u.value=i[h].texture,e.setRenderTarget(m),n.render(e),a.value=m.texture}Kt(e,this.rendererState),a.value=d}setup(e){const{inputNode:i}=this;V(i!=null);const{downsampleMaterial:r,upsampleMaterial:n}=this;return r.fragmentNode=this.setupDownsampleNode(e),n.fragmentNode=this.setupUpsampleNode(e),r.needsUpdate=!0,n.needsUpdate=!0,super.setup(e)}dispose(){for(const e of this.downsampleRTs)e.dispose();for(const e of this.upsampleRTs)e.dispose();this.downsampleMaterial.dispose(),this.upsampleMaterial.dispose(),this.mesh.geometry.dispose(),super.dispose()}};const Xt=(s,e)=>{const i=t.uv(),r=t.vec4(1,1,-1,-1).mul(e.xyxy).add(i.xyxy).toVertexStage(),n=t.vec4(2,2,-2,-2).mul(e.xyxy).add(i.xyxy).toVertexStage(),a=r.zy,o=r.xy,u=r.zw,c=r.xw,l=t.vec2(i.x,n.y),d=t.vec2(n.z,i.y),h=t.vec2(n.x,i.y),m=t.vec2(i.x,n.w),p=n.zy,g=n.xy,y=n.zw,f=n.xw;return t.add(t.add(s.sample(i),s.sample(a),s.sample(o),s.sample(u),s.sample(c)).mul(1/8),t.add(s.sample(l),s.sample(d),s.sample(h),s.sample(m)).mul(1/16),t.add(s.sample(p),s.sample(g),s.sample(y),s.sample(f)).mul(1/32))},{resetRendererState:Yt,restoreRendererState:ei}=T.RendererUtils;class ti extends Ce{constructor(e){super(e),this.material=new T.NodeMaterial,this.mesh=new T.QuadMesh(this.material),this.inputTexelSize=t.uniform("vec2");const i=this.constructor.type.replace(/Node$/,"");this.material.name=i,this.mesh.name=i,this.renderTarget=this.createRenderTarget(),this.outputTexture=this.renderTarget.texture}setSize(e,i){const{resolutionScale:r}=this,n=Math.max(Math.round(e*r),1),a=Math.max(Math.round(i*r),1);return this.renderTarget.setSize(n,a),this}updateBefore({renderer:e}){if(e==null)return;const{inputNode:i}=this;V(i!=null);const{width:r,height:n}=i.value;this.setSize(r,n),this.inputTexelSize.value.set(1/r,1/n),this.rendererState=Yt(e,this.rendererState),e.setRenderTarget(this.renderTarget),this.mesh.render(e),ei(e,this.rendererState)}setup(e){const{inputNode:i}=this;V(i!=null);const{material:r}=this;return r.fragmentNode=this.setupOutputNode(e),r.needsUpdate=!0,super.setup(e)}dispose(){this.renderTarget.dispose(),this.material.dispose(),this.mesh.geometry.dispose(),super.dispose()}}let ii=class extends ti{constructor(e){super(e),this.thresholdLevel=t.uniform(5),this.thresholdRange=t.uniform(1),this.resolutionScale=.5}static get type(){return"DownsampleThresholdNode"}setupOutputNode(){const{inputNode:e,thresholdLevel:i,thresholdRange:r,inputTexelSize:n}=this;V(e!=null);const a=Xt(e,n),o=t.luminance(a.rgb),u=t.smoothstep(i,i.add(r),o);return t.vec4(a.rgb,o).mul(u)}};const Re=s=>{const e=t.OnBeforeObjectUpdate(s);return e.updateBeforeType=T.NodeUpdateType.FRAME,e};function tt(s){if(typeof s=="string")return s;if(typeof s=="function"&&typeof s.name=="string"&&s.name.length>0)return s.name;if("layout"in s&&s.layout instanceof T.StructTypeNode){if(s.layout.name==null)throw new Error("Struct name is required.");return s.layout.name}throw new Error(`Unsupported layout type: ${s}`)}function M({typeOnly:s=!1,...e}){return s?i=>t.Fn(i):i=>t.Fn(i).setLayout({...e,type:tt(e.type),inputs:e.inputs?.map(r=>({...r,type:tt(r.type)}))??[]})}function A(s){return t.Fn((e,i)=>{const r=s(...e);return typeof r=="function"?r(i):r})}const{resetRendererState:si,restoreRendererState:ri}=T.RendererUtils;class ni extends Ce{constructor(e){super(e),this.iterations=1,this.material=new T.NodeMaterial,this.mesh=new T.QuadMesh(this.material),this.inputTexelSize=t.uniform("vec2"),this.direction=t.uniform("vec2");const i=this.constructor.type.replace(/Node$/,"");this.material.name=i,this.mesh.name=i,this.horizontalRT=this.createRenderTarget("horizontal"),this.verticalRT=this.createRenderTarget("vertical"),this.outputTexture=this.verticalRT.texture}setSize(e,i){const{resolutionScale:r}=this,n=Math.max(Math.round(e*r),1),a=Math.max(Math.round(i*r),1);return this.horizontalRT.setSize(n,a),this.verticalRT.setSize(n,a),this}updateBefore({renderer:e}){if(e==null)return;const{horizontalRT:i,verticalRT:r,mesh:n,inputNode:a,direction:o}=this;V(a!=null);const{width:u,height:c}=a.value;this.setSize(u,c),this.inputTexelSize.value.set(1/u,1/c);const l=a.value;this.rendererState=si(e,this.rendererState);for(let d=0;d<this.iterations;++d)o.value.set(1,0),e.setRenderTarget(i),n.render(e),a.value=i.texture,o.value.set(0,1),e.setRenderTarget(r),n.render(e),a.value=r.texture;ri(e,this.rendererState),a.value=l}setup(e){const{inputNode:i}=this;V(i!=null);const{material:r}=this;return r.fragmentNode=this.setupOutputNode(e),r.needsUpdate=!0,super.setup(e)}dispose(){this.horizontalRT.dispose(),this.verticalRT.dispose(),this.material.dispose(),this.mesh.geometry.dispose(),super.dispose()}}function it(s){if(V(s>=0),s===0)return new Float64Array(0);if(s===1)return new Float64Array([1]);let e=new Float64Array(s),i=new Float64Array(s),r=i;for(let n=1;n<=s;++n){for(let a=0;a<n;++a)i[a]=a===0||a===n-1?1:e[a-1]+e[a];r=i,i=e,e=r}return r}function ai(s,e=2){V(s>=3);const i=s+e*2,r=e>0?it(i).slice(e,-e):it(i),n=Math.floor((r.length-1)/2),a=r.reduce((h,m)=>h+m,0),o=r.slice(n),u=[...Array(n+1).keys()],c=new Float64Array(Math.floor(u.length/2)),l=new Float64Array(c.length);c[0]=o[0]/a;for(let h=1,m=1;h<u.length-1;h+=2,++m){const p=u[h],g=u[h+1],y=o[h],f=o[h+1],v=y+f,S=(p*y+g*f)/v;c[m]=v/a,l[m]=S}const d=(c.reduce((h,m)=>h+m,0)-c[0]*.5)*2;if(d!==0){const h=1/d;for(let m=0;m<c.length;++m)c[m]*=h}return{offsets:l,weights:c}}class oi extends ni{static get type(){return"GaussianBlurNode"}constructor(e,i=35){super(e),this.kernelSize=i}setupOutputNode(e){const{inputNode:i,inputTexelSize:r,direction:n}=this;V(i!=null);const{offsets:a,weights:o}=ai(this.kernelSize);return t.Fn(()=>{const u=t.uv(),c=n.mul(r).toVertexStage(),l=i.sample(u).mul(o[0]);for(let d=1;d<a.length;++d){const h=c.mul(a[d]);l.addAssign(t.add(i.sample(u.add(h)),i.sample(u.sub(h))).mul(o[d]))}return l})()}}const ui=s=>s.dot(t.vec2(.06711056,.00583715)).fract().mul(52.9829189).fract(),ci=t.Fn(()=>{const s=t.vec2(t.screenCoordinate.xy).add(t.time.fract().mul(1337)),e=ui(s);return t.vec3(e,e.oneMinus(),e).sub(.5).div(255)}).once()();class li extends T.TempNode{constructor(){super("vec3"),this.currentProjectionMatrix=t.uniform("mat4"),this.previousProjectionMatrix=t.uniform("mat4"),this.currentModelViewMatrix=t.uniform("mat4"),this.previousModelViewMatrix=t.uniform("mat4"),this.objectModelViewMatrices=new WeakMap,this.updateType=T.NodeUpdateType.FRAME,this.updateBeforeType=T.NodeUpdateType.OBJECT,this.updateAfterType=T.NodeUpdateType.OBJECT}static get type(){return"HighpVelocityNode"}setProjectionMatrix(e){return this.projectionMatrix=e,this}update({camera:e}){if(e==null)return;const{currentProjectionMatrix:i,previousProjectionMatrix:r}=this,n=this.projectionMatrix??e.projectionMatrix;r.value==null?r.value=new x.Matrix4().copy(n):r.value.copy(i.value),i.value.copy(n)}updateBefore({object:e,camera:i}){if(e==null||i==null)return;const{currentModelViewMatrix:r,previousModelViewMatrix:n,objectModelViewMatrices:a}=this;r.value.multiplyMatrices(i.matrixWorldInverse,e.matrixWorld),n.value=a.get(e)??r.value}updateAfter({object:e}){if(e==null)return;const{currentModelViewMatrix:i,objectModelViewMatrices:r}=this;let n=r.get(e);n==null&&(n=new x.Matrix4,r.set(e,n)),n.copy(i.value)}setup(e){const i=this.currentProjectionMatrix.mul(this.currentModelViewMatrix).mul(t.positionLocal).toVertexStage(),r=this.previousProjectionMatrix.mul(this.previousModelViewMatrix).mul(t.positionPrevious).toVertexStage(),n=i.xyz.div(i.w),a=r.xyz.div(r.w);return t.sub(n,a)}}const je=t.nodeImmutable(li);class di extends T.TempNode{constructor(e){super("vec3"),this.intensity=t.uniform(1e-5),this.inputNode=e}static get type(){return"LensGhostNode"}setup(e){const{inputNode:i,intensity:r}=this;V(i!=null);const n=M({name:"sampleGhost",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"direction",type:"vec2"},{name:"color",type:"vec3"},{name:"offset",type:"float"}]})(([u,c,l,d])=>{const h=c.mul(d).add(u.oneMinus()).saturate(),m=i.sample(h).rgb.mul(l),p=t.sub(.5,h).length().mul(1/(Math.SQRT2/4)).saturate();return m.mulAssign(p.oneMinus().pow(3)),m}),a=t.uv(),o=a.sub(.5);return t.add(n(a,o,t.vec3(.8,.8,1),-5),n(a,o,t.vec3(1,.8,.4),-1.5),n(a,o,t.vec3(.9,1,.8),-.4),n(a,o,t.vec3(1,.8,.4),-.2),n(a,o,t.vec3(.9,.7,.7),-.1),n(a,o,t.vec3(.5,1,.4),.7),n(a,o,t.vec3(.5,.5,.5),1),n(a,o,t.vec3(1,1,.6),2.5),n(a,o,t.vec3(.5,.8,1),10)).mul(r)}}const{resetRendererState:hi,restoreRendererState:mi}=T.RendererUtils;function pi(){const s=document.createElement("canvas");s.width=256,s.height=32;const e=s.getContext("2d");V(e!=null),e.beginPath(),e.moveTo(0,32/2),e.lineTo(256/2,5),e.lineTo(256,32/2),e.lineTo(256/2,27),e.closePath();const i=e.createLinearGradient(0,0,256,0);return i.addColorStop(0,"#000000"),i.addColorStop(.5,"#ffffff"),i.addColorStop(1,"#000000"),e.fillStyle=i,e.fill(),new x.CanvasTexture(s)}const st=t.struct({color:"vec3",luminance:"float",position:"vec2",scale:"float",sin:"float",cos:"float"});class gi extends Ce{constructor(e){super(e),this.spikePairCount=6,this.wireframe=!1,this.intensity=t.uniform(1e-5),this.sizeScale=t.uniform(new x.Vector2(1.5,.01)),this.luminanceThreshold=t.uniform(100),this.indirectBuffer=new T.IndirectStorageBufferAttribute(new Uint32Array([6,0,0,0,0]),1),this.instanceBuffer=t.instancedArray(1,st),this.renderTarget=this.createRenderTarget(),this.material=new T.MeshBasicNodeMaterial({depthTest:!1,depthWrite:!1,transparent:!0,blending:x.AdditiveBlending}),this.mesh=new x.Mesh(new x.PlaneGeometry(1,1),this.material),this.camera=new x.PerspectiveCamera,this.inputTexelSize=t.uniform("vec2"),this.outputTexelSize=t.uniform("vec2"),this.geometryRatio=t.uniform("vec2"),this.material.name="LensGlare",this.inputNode=e,this.resolutionScale=.5,this.outputTexture=this.renderTarget.texture,this.mesh.geometry.indirect=this.indirectBuffer}customCacheKey(){return _e.hash(this.spikePairCount,+this.wireframe)}setSize(e,i){const{resolutionScale:r}=this,n=Math.max(Math.round(e*r),1),a=Math.max(Math.round(i*r),1);this.renderTarget.setSize(n,a);const o=Math.floor(n/2),u=Math.floor(a/2),c=o*u;return this.instanceBuffer.bufferCount<c&&(this.instanceBuffer.dispose(),this.instanceBuffer=t.instancedArray(c,st),this.setupCompute(o,u),this.setupMaterial()),this}updateBefore({renderer:e}){if(e==null)return;const{inputNode:i}=this;V(i!=null);const{width:r,height:n}=i.value;this.setSize(r,n);const{computeNode:a,indirectBuffer:o,renderTarget:u}=this;V(a!=null),this.inputTexelSize.value.set(1/r,1/n);const c=r/n;c>1?this.geometryRatio.value.set(1/c,1):this.geometryRatio.value.set(1,c);const{width:l,height:d}=u;this.outputTexelSize.value.set(1/l,1/d),o.array[1]=0,o.needsUpdate=!0,e.compute(a),this.rendererState=hi(e,this.rendererState),e.setRenderTarget(u),e.render(this.mesh,this.camera),mi(e,this.rendererState)}setupCompute(e,i){const{spikePairCount:r,inputNode:n,indirectBuffer:a,instanceBuffer:o,outputTexelSize:u}=this;V(n!=null);const c=t.storage(a,"uint",a.count).toAtomic();this.computeNode=t.Fn(()=>{const l=t.uvec2(e,i);t.If(t.globalId.xy.greaterThanEqual(l).any(),()=>{t.Return()});const d=t.vec2(t.globalId.xy).mul(u).mul(2),h=n.sample(d),m=h.a;t.If(m.greaterThan(.1),()=>{const p=t.atomicAdd(c.element(1),r);for(let g=0;g<r;++g){const y=o.element(p.add(g));y.get("color").assign(h.rgb),y.get("luminance").assign(m),y.get("position").assign(t.globalId.xy),y.get("scale").assign(g%2===0?1:.5);const f=Math.PI*(3-Math.sqrt(5)),v=Math.PI/r*g+f;y.get("sin").assign(Math.sin(v)),y.get("cos").assign(Math.cos(v))}})})().compute([Math.ceil(e/8),Math.ceil(i/8),1],[8,8,1])}setupMaterial(){const{inputNode:e,spikeNode:i,instanceBuffer:r,luminanceThreshold:n,intensity:a,sizeScale:o,outputTexelSize:u,geometryRatio:c}=this;V(e!=null),V(i!=null);const l=r.element(t.instanceIndex);this.material.colorNode=this.wireframe?t.vec4(1):i.mul(l.get("color").mul(a)),this.material.vertexNode=t.Fn(()=>{const d=l.get("sin"),h=l.get("cos"),m=t.mat3(h,d,0,d.negate(),h,0,0,0,1),p=l.get("position").mul(u).mul(2),g=p.flipY().mul(2).sub(1),y=l.get("luminance").div(n).saturate(),f=t.vec2(y,1).mul(l.get("scale"),o,p.sub(.5).length().mul(2).oneMinus().mul(.5).add(.5)),v=m.mul(t.positionGeometry.mul(t.vec4(f,1,1))).mul(c).add(t.vec3(g,0));return t.vec4(v,1)})(),this.material.wireframe=this.wireframe,this.material.needsUpdate=!0}setup(e){if(this.spikeNode==null){const i=pi();i.colorSpace=x.SRGBColorSpace,this.spikeNode=t.texture(i)}return this.setupMaterial(),super.setup(e)}dispose(){this.renderTarget.dispose(),this.material.dispose(),this.mesh.geometry.dispose(),super.dispose()}}const xi=new x.Vector2;class yi extends T.TempNode{constructor(e){super("vec3"),this.intensity=t.uniform(1e-5),this.chromaticAberration=t.uniform(.005),this.aspectRatio=t.uniform(0),this.updateBeforeType=T.NodeUpdateType.FRAME,this.inputNode=e}static get type(){return"LensHaloNode"}updateBefore({renderer:e}){if(e==null)return;const{width:i,height:r}=e.getDrawingBufferSize(xi);this.aspectRatio.value=i/r}setup(e){const{inputNode:i,intensity:r,chromaticAberration:n,aspectRatio:a}=this;V(i!=null);const o=M({name:"cubicRingMask",type:"float",inputs:[{name:"x",type:"float"},{name:"radius",type:"float"},{name:"thickness",type:"float"}]})(([l,d,h])=>{const m=t.min(t.abs(l.sub(d)).div(h),1);return t.mul(m,m,t.sub(3,m.mul(2))).oneMinus()}),u=M({name:"sampleHalo",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"radius",type:"float"}]})(([l,d])=>{const h=t.vec2(a,1),m=l.sub(.5).mul(h).normalize().div(h),p=t.vec3(n).mul(t.vec3(-1,0,1)),g=t.fract(m.mul(d).add(l.oneMinus())),y=t.vec3(i.sample(m.mul(p.r).add(g)).r,i.sample(m.mul(p.g).add(g)).g,i.sample(m.mul(p.b).add(g)).b),f=l.sub(t.vec2(.5,0)).mul(h).add(t.vec2(.5,0)),v=t.distance(f,t.vec2(.5)).saturate();return y.mulAssign(o(v,.45,.25)),y}),c=t.uv();return u(c,.3).mul(r)}}const G=s=>s.greaterThanEqual(0).all().and(s.lessThanEqual(1).all()).toFloat();let fi=class extends Jt{constructor(e,i=4){super(e,i),this.blendAmount=t.uniform(.85),this.resolutionScale=.5}static get type(){return"MipmapSurfaceBlurNode"}setupDownsampleNode(e){const{inputNode:i,inputTexelSize:r}=this;return V(i!=null),t.Fn(()=>{const n=t.uv(),a=t.vec4(1,1,-1,-1).mul(r.xyxy).add(n.xyxy).toVertexStage(),o=t.vec4(2,2,-2,-2).mul(r.xyxy).add(n.xyxy).toVertexStage(),u=a.zy,c=a.xy,l=a.zw,d=a.xw,h=o.zy,m=o.xy,p=o.zw,g=o.xw,y=t.vec2(n.x,o.y),f=t.vec2(o.z,n.y),v=t.vec2(o.x,n.y),S=t.vec2(n.x,o.w),b=1/4/2,C=1/9/2,N=i.sample(n).mul(C);let w;return w=t.vec4(G(u),G(c),G(l),G(d)).mul(b),N.addAssign(i.sample(u).mul(w.x),i.sample(c).mul(w.y),i.sample(l).mul(w.z),i.sample(d).mul(w.w)),w=t.vec4(G(h),G(m),G(p),G(g)).mul(C),N.addAssign(i.sample(h).mul(w.x),i.sample(m).mul(w.y),i.sample(p).mul(w.z),i.sample(g).mul(w.w)),w=t.vec4(G(y),G(f),G(v),G(S)).mul(C),N.addAssign(i.sample(y).mul(w.x),i.sample(f).mul(w.y),i.sample(v).mul(w.z),i.sample(S).mul(w.w)),N})()}setupUpsampleNode(e){const{inputNode:i,inputTexelSize:r,downsampleNode:n}=this;V(i!=null);const a=t.uv(),o=t.vec4(1,1,-1,-1).mul(r.xyxy).add(a.xyxy).toVertexStage(),u=t.vec2(a.x,o.y),c=t.vec2(o.z,a.y),l=t.vec2(o.x,a.y),d=t.vec2(a.x,o.w),h=o.zy,m=o.xy,p=o.zw,g=o.xw,y=t.add(i.sample(a).mul(1/4),t.add(i.sample(u),i.sample(c),i.sample(l),i.sample(d)).mul(1/8),t.add(i.sample(h),i.sample(m),i.sample(p),i.sample(g)).mul(1/16));return t.mix(n.sample(a),y,this.blendAmount)}};function Qe(s){return(s instanceof T.NodeBuilder?s.renderer.backend:"backend"in s?s.backend:s).isWebGPUBackend===!0}class vi extends T.TempNode{constructor(e){super("vec4"),this.bloomIntensity=t.uniform(.05),this.inputNode=e,this.thresholdNode=new ii,this.blurNode=new oi,this.ghostNode=new di,this.haloNode=new yi,this.bloomNode=new fi(null,8),this.glareNode=new gi,this.featuresNode=t.rtt(t.add(this.ghostNode,this.haloNode)),this.featuresNode.value.name="LensFlare_features",this.featuresNode.pixelRatio=.5,this.blurNode.resolutionScale=1,this.bloomNode.resolutionScale=1,this.glareNode.resolutionScale=1}static get type(){return"LensFlareNode"}setup(e){const{inputNode:i,thresholdNode:r,blurNode:n,ghostNode:a,haloNode:o,bloomNode:u,featuresNode:c,glareNode:l}=this;V(i!=null);const d=r.getTextureNode(),h=n.getTextureNode();r.inputNode=i,n.inputNode=d,a.inputNode=h,o.inputNode=h,u.inputNode=d,l.inputNode=d;const m=u.getTextureNode().mul(this.bloomIntensity),p=l.getTextureNode();return t.Fn(()=>{const g=i;return g.addAssign(m),Qe(e)&&g.addAssign(p),g.add(c)})()}dispose(){this.thresholdNode.dispose(),this.blurNode.dispose(),this.ghostNode.dispose(),this.haloNode.dispose(),this.bloomNode.dispose(),this.glareNode.dispose(),this.featuresNode.dispose(),super.dispose()}}const Ti=s=>new vi(s!=null?t.convertToTexture(s):null);let wi=class extends T.Texture3DNode{static get type(){return"OutputTexture3DNode"}constructor(e,i){super(i),this.owner=e,this.setUpdateMatrix(!1)}setup(e){return this.owner.build(e),super.setup(e)}clone(){const e=new this.constructor(this.owner,this.value);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}};const ze=(...s)=>new wi(...s),Si=A((s,e,i,r)=>n=>{i??=he(e),r??=me(e);const a=e?.isPerspectiveCamera===!0;return n.renderer.logarithmicDepthBuffer?t.logarithmicDepthToViewZ(s,i,r):a?t.perspectiveDepthToViewZ(s,i,r):t.orthographicDepthToViewZ(s,i,r)}),rt=(s,e,i)=>{e??=t.cameraNear,i??=t.cameraFar;const r=t.logarithmicDepthToViewZ(s,e,i);return t.viewZToPerspectiveDepth(r,e,i)},Ee=[[58.1375,2.7747,26.8183],[-150.5666,4.2109,-88.5066],[130.5887,-14.0195,109.0745],[-42.3277,4.8052,-60.1097],[4.5974,2.1856,12.5925],[.1357,.0914,.1067]],Ci=M({name:"turbo",type:"vec3",inputs:[{name:"x",type:"float"}]})(([s])=>{const e=t.vec3(...Ee[0]).toVar();for(let i=1;i<Ee.length;++i)e.assign(t.vec3(...Ee[i]).add(s.mul(e)));return e});A((s,e,i,r)=>{i??=he(e),r??=me(e);const n=Si(s,e,i,r);return Ci(t.viewZToLogarithmicDepth(n,i,r))});const Ni=M({name:"equirectToDirectionWorld",type:"vec3",inputs:[{name:"uv",type:"vec2"}]})(([s])=>{const e=t.sub(.5,s.x).mul(t.PI2),i=t.sub(s.y,.5).mul(t.PI),r=t.cos(i);return t.vec3(r.mul(t.cos(e)),t.sin(i),r.mul(t.sin(e)))});function nt(s,e){let i=1,r=0;for(;s>0;)i/=e,r+=i*(s%e),s=Math.floor(s/e);return r}const at=Array.from({length:16},(s,e)=>new x.Vector2(nt(e+1,2),nt(e+1,3))),{resetRendererState:bi,restoreRendererState:Mi}=T.RendererUtils;function Ri(s){return s.isPerspectiveCamera===!0||s.isOrthographicCamera===!0||"updateProjectionMatrix"in s&&"setViewOffset"in s&&"clearViewOffset"in s}const zi=M({name:"clipAABB",type:"vec4",inputs:[{name:"current",type:"vec4"},{name:"history",type:"vec4"},{name:"minColor",type:"vec4"},{name:"maxColor",type:"vec4"}]})(([s,e,i,r])=>{const n=r.rgb.add(i.rgb).mul(.5).toConst(),a=r.rgb.sub(i.rgb).mul(.5).add(1e-7),o=e.sub(t.vec4(n,s.a)).toConst(),u=o.xyz.div(a).abs().toConst(),c=t.max(u.x,u.y,u.z).toConst();return c.greaterThan(1).select(t.vec4(n,s.a).add(o.div(c)),e)}),ot=[[-1,-1],[-1,1],[1,-1],[1,1],[1,0],[0,-1],[0,1],[-1,0]],Ei=A((s,e,i,r,n)=>{const a=i.toVar(),o=i.pow2().toVar();for(const[m,p]of ot){const g=s.load(e.add(t.ivec2(m,p))).toConst();a.addAssign(g),o.addAssign(g.pow2())}const u=ot.length+1,c=a.div(u).toConst(),l=t.sqrt(o.div(u).sub(c.pow2()).max(0)).mul(n).toConst(),d=c.sub(l).toConst(),h=c.add(l).toConst();return zi(c.clamp(d,h),r,d,h)}),Fi=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]],Ai=t.struct({closestCoord:"ivec2",closestDepth:"float"}),Vi=A((s,e)=>i=>{const r=t.ivec2(0).toVar(),n=t.float(1).toVar();for(const[a,o]of Fi){const u=e.add(t.ivec2(a,o)).toConst();let c=s.load(u).r;i.renderer.reversedDepthBuffer&&(c=c.oneMinus()),c=c.toConst(),t.If(c.lessThan(n),()=>{r.assign(u),n.assign(c)})}return Ai(r,n)}),Li=A((s,e)=>{const i=s.mul(e).fract().abs(),r=t.max(i,i.oneMinus());return r.x.mul(r.y).oneMinus().div(.75)}),ut=new x.Vector2,Pi=new x.DepthTexture(1,1);class ct extends T.TempNode{constructor(e,i,r,n){if(super("vec4"),this.temporalAlpha=t.uniform(.05),this.varianceGamma=t.uniform(1),this.velocityThreshold=t.uniform(.1),this.depthError=t.uniform(.001),this.debugShowRejection=!1,this.resolveRT=this.createRenderTarget("resolve"),this.historyRT=this.createRenderTarget("history"),this.resolveMaterial=new T.NodeMaterial,this.mesh=new T.QuadMesh,this.needsSyncRenderPipeline=!1,this.needsClearHistory=!1,this.resolveNode=t.texture(this.resolveRT.texture),this.historyNode=t.texture(this.historyRT.texture),this.previousDepthNode=t.texture(Pi),this.originalProjectionMatrix=new x.Matrix4,this.jitterIndex=0,this.updateBeforeType=T.NodeUpdateType.FRAME,this.resolveMaterial.name="TemporalAntialias_resolve",this.mesh.name="TemporalAntialias",this.inputNode=e,this.depthNode=i,this.velocityNode=r,!Ri(n))throw new Error("The provided camera is not supported.");this.camera=n,this.textureNode=ae(this,this.resolveRT.texture)}static get type(){return"TemporalAntialiasNode"}customCacheKey(){return _e.hash(this.camera.id,+this.debugShowRejection)}createRenderTarget(e){const i=new x.RenderTarget(1,1,{depthBuffer:!1,type:x.HalfFloatType,format:x.RGBAFormat}),r=i.texture;r.minFilter=x.LinearFilter,r.magFilter=x.LinearFilter,r.generateMipmaps=!1;const n=this.constructor.type;return r.name=e!=null?`${n}_${e}`:n,i}getTextureNode(){return this.textureNode}setSize(e,i){const{resolveRT:r,historyRT:n}=this;return(e!==n.width||i!==n.height)&&(r.setSize(e,i),n.setSize(e,i),this.needsClearHistory=!0),this}clearHistory(e){e.setRenderTarget(this.resolveRT),e.clear(),e.setRenderTarget(this.historyRT),e.clear(),this.needsClearHistory=!1}setViewOffset(e,i){const{camera:r}=this;r.updateProjectionMatrix(),this.originalProjectionMatrix.copy(r.projectionMatrix),je.setProjectionMatrix(this.originalProjectionMatrix);const n=at[this.jitterIndex],a=n.x-.5,o=n.y-.5;r.setViewOffset(e,i,a,o,e,i)}clearViewOffset(){this.camera.clearViewOffset(),je.setProjectionMatrix(null),this.jitterIndex=(this.jitterIndex+1)%at.length}copyDepthTexture(e){const i=this.depthNode.value,r=this.previousDepthTexture??=i.clone();(r.image.width!==i.width||r.image.height!==i.height)&&(r.image.width=i.width,r.image.height=i.height,r.needsUpdate=!0),e.copyTextureToTexture(i,r),this.previousDepthNode.value=r}swapBuffers(){const{resolveRT:e,historyRT:i}=this;this.resolveRT=i,this.historyRT=e,this.resolveNode.value=i.texture,this.historyNode.value=e.texture,this.textureNode.value=e.texture}updateBefore({renderer:e}){if(e==null)return;const i=e.getDrawingBufferSize(ut);this.setSize(i.x,i.y),this.rendererState=bi(e,this.rendererState),this.needsClearHistory&&this.clearHistory(e),e.setRenderTarget(this.resolveRT),this.mesh.material=this.resolveMaterial,this.mesh.render(e),Mi(e,this.rendererState),Qe(e)&&this.copyDepthTexture(e),this.swapBuffers(),this.needsSyncRenderPipeline&&this.clearViewOffset()}setupResolveNode({renderer:e}){const i=r=>{const{previousDepthNode:n}=this,a=n.load(t.ivec2(r.mul(n.size()).sub(.5))).toConst();return e.logarithmicDepthBuffer?rt(a,he(this.camera),me(this.camera)):e.reversedDepthBuffer?a.oneMinus():a};return t.Fn(()=>{const r=t.ivec2(t.screenCoordinate),n=t.screenUV,a=Vi(this.depthNode,r).toConst(),o=a.get("closestCoord"),u=a.get("closestDepth"),c=this.velocityNode.load(o).xyz.mul(t.vec3(.5,-.5,.5)).toConst(),l=c.xy.length().div(this.velocityThreshold).oneMinus().saturate(),d=n.sub(c.xy).toConst(),h=i(d),m=e.logarithmicDepthBuffer?rt(u,he(this.camera),me(this.camera)):u,p=t.step(m.add(c.z),h.add(this.depthError)),g=l.mul(p),y=t.and(d.greaterThanEqual(0).all(),d.lessThanEqual(1).all()).toFloat(),f=u.notEqual(1).toFloat(),v=this.inputNode.load(r).toVar();return t.If(y.mul(f).mul(g).greaterThan(0),()=>{const S=t.texture(this.historyNode,d),b=Ei(this.inputNode,r,v,S,this.varianceGamma),C=t.mix(this.temporalAlpha,.4,Li(c.xy,t.textureSize(this.inputNode))).saturate();v.assign(t.mix(b,v,C))}).Else(()=>{this.debugShowRejection&&v.assign(t.vec3(1,0,0))}),v})()}setup(e){const i=()=>{const n=e.renderer.getDrawingBufferSize(ut);this.setViewOffset(n.width,n.height)};if(e.context.renderPipeline!=null){const{context:n}=e.context.renderPipeline;n.onBeforeRenderPipeline=i,this.needsSyncRenderPipeline=!0}if(e.context.postProcessing!=null){const{context:n}=e.context.postProcessing;n.onBeforePostProcessing=i,this.needsSyncRenderPipeline=!0}const{resolveMaterial:r}=this;return r.fragmentNode=this.setupResolveNode(e),r.needsUpdate=!0,this.textureNode.uvNode=this.inputNode.uvNode,this.textureNode}dispose(){this.resolveRT.dispose(),this.historyRT.dispose(),this.previousDepthTexture?.dispose(),this.resolveMaterial.dispose(),this.mesh.geometry.dispose(),super.dispose()}}function Di(...s){if(s.length===1)return(a,o,u,c)=>new ct(t.convertToTexture(a),o,u,c);const[e,i,r,n]=s;return new ct(t.convertToTexture(e),i,r,n)}const Ui="eac103980f20c0956f2d3215833e73514be08462",Ii=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${Ui}/packages/atmosphere/assets/stars.bin`,Bi=new x.Vector3;function Oi(s,e,i,r){const n=i.projectOnSurface(s,Bi);return n!=null?i.getOsculatingSphereCenter(n,e,r).negate():r.setScalar(0)}var qi="Invariant failed";function Q(s,e){if(!s)throw new Error(qi)}const lt=typeof window<"u"&&window.requestIdleCallback!=null?window.requestIdleCallback:function(s,e={}){const i=e.timeout??1,r=performance.now();return setTimeout(()=>{s({get didTimeout(){return e.timeout!=null?!1:performance.now()-r-1>i},timeRemaining(){return Math.max(0,1+(performance.now()-r))}})},1)},D="float",ki="float",z="float",dt="float",Gi="float",vt="float",$i="vec3",te="vec3",ue="vec3",Tt="vec3",J="vec3",wt="vec3",Te=t.struct({width:D,expTerm:z,expScale:dt,linearTerm:dt,constantTerm:z},"DensityProfileLayer"),oe=t.struct({layer0:Te.name,layer1:Te.name},"DensityProfile"),We={worldToUnit:z,solarIrradiance:ue,sunAngularRadius:ki,bottomRadius:D,topRadius:D,rayleighDensity:oe.name,rayleighScattering:J,mieDensity:oe.name,mieScattering:J,mieExtinction:J,miePhaseFunctionG:z,absorptionDensity:oe.name,absorptionExtinction:J,groundAlbedo:te,minCosLight:z,sunRadianceToLuminance:te,skyRadianceToLuminance:te,luminanceScale:z,transmittanceTextureSize:"uvec2",irradianceTextureSize:"uvec2",multipleScatteringTextureSize:"uvec2",scatteringTextureRadiusSize:"uint",scatteringTextureCosViewSize:"uint",scatteringTextureCosLightSize:"uint",scatteringTextureCosViewLightSize:"uint"},B=t.struct(We,"AtmosphereParameters");function ht(s,e){const{width:i,expTerm:r,expScale:n,linearTerm:a,constantTerm:o}=s;return Te({width:t.float(i*e),expTerm:t.float(r),expScale:t.float(n/e),linearTerm:t.float(a/e),constantTerm:t.float(o)})}function Fe(s,e){return oe({layer0:ht(s.layers[0],e),layer1:ht(s.layers[1],e)})}const mt=Symbol("DESTRUCTIBLE");function U(s){if(q.reinterpretType(s),s[mt]===!0)return s;for(const e in We)Object.hasOwn(We,e)&&(s[e]=s.get(e));return s[mt]=!0,s}class Ze{constructor(e){this.parameters=e;const{worldToUnit:i,solarIrradiance:r,sunAngularRadius:n,bottomRadius:a,topRadius:o,rayleighDensity:u,rayleighScattering:c,mieDensity:l,mieScattering:d,mieExtinction:h,miePhaseFunctionG:m,absorptionDensity:p,absorptionExtinction:g,groundAlbedo:y,minCosLight:f,sunRadianceToLuminance:v,skyRadianceToLuminance:S,luminanceScale:b,transmittanceTextureSize:C,irradianceTextureSize:N,multipleScatteringTextureSize:w,scatteringTextureRadiusSize:R,scatteringTextureCosViewSize:E,scatteringTextureCosLightSize:L,scatteringTextureCosViewLightSize:F}=e;this.parametersNode=U(B({worldToUnit:t.float(i),solarIrradiance:t.vec3(r),sunAngularRadius:t.float(n),bottomRadius:t.float(a*i),topRadius:t.float(o*i),rayleighDensity:Fe(u,i),rayleighScattering:t.vec3(c.x/i,c.y/i,c.z/i),mieDensity:Fe(l,i),mieScattering:t.vec3(d.x/i,d.y/i,d.z/i),mieExtinction:t.vec3(h.x/i,h.y/i,h.z/i),miePhaseFunctionG:t.float(m),absorptionDensity:Fe(p,i),absorptionExtinction:t.vec3(g.x/i,g.y/i,g.z/i),groundAlbedo:t.vec3(y),minCosLight:t.float(f),sunRadianceToLuminance:t.vec3(v),skyRadianceToLuminance:t.vec3(S),luminanceScale:t.float(b),transmittanceTextureSize:t.ivec2(C),irradianceTextureSize:t.ivec2(N),multipleScatteringTextureSize:t.uvec2(w),scatteringTextureRadiusSize:t.uint(R),scatteringTextureCosViewSize:t.uint(E),scatteringTextureCosLightSize:t.uint(L),scatteringTextureCosViewLightSize:t.uint(F)}).toConst("atmosphereParameters"))}dispose(){}}function j(s){if(typeof s.context.getAtmosphere!="function")throw new Error("getAtmosphere() was not found in the builder context.");const e=s.context.getAtmosphere();if(!(e instanceof Ze))throw new Error("getAtmosphere() must return an instanceof AtmosphereContextBase.");return e}class St extends Ze{constructor(e,i){super(e),this.lambdas=t.uniform(new x.Vector3(680,550,440)),this.luminanceFromRadiance=t.uniform("mat3"),this.textureType=i}}class Ct{setup(e,i){this.parameters=e,this.textureType=i}dispose(){}}const _=M({name:"clampCosine",type:z,inputs:[{name:"cosine",type:z}]})(([s])=>t.clamp(s,-1,1)),Nt=M({name:"clampDistance",type:z,inputs:[{name:"cosine",type:z}]})(([s])=>t.max(s,0)),Ne=M({name:"clampRadius",type:D,inputs:[{name:"parameters",type:B},{name:"radius",type:D}]})(([s,e])=>{const{topRadius:i,bottomRadius:r}=U(s);return t.clamp(e,r,i)}),ie=M({name:"sqrtSafe",type:z,inputs:[{name:"area",type:Gi}]})(([s])=>t.sqrt(t.max(s,0))),ce=M({name:"distanceToTopAtmosphereBoundary",type:D,inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i])=>{const{topRadius:r}=U(s),n=e.pow2().mul(i.pow2().sub(1)).add(r.pow2());return Nt(e.negate().mul(i).add(ie(n)))}),ji=M({name:"distanceToBottomAtmosphereBoundary",type:D,inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i])=>{const{bottomRadius:r}=U(s),n=e.pow2().mul(i.pow2().sub(1)).add(r.pow2());return Nt(e.negate().mul(i).sub(ie(n)))}),bt=M({name:"distanceToNearestAtmosphereBoundary",type:D,inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z},{name:"intersectsGround",type:"bool"}]})(([s,e,i,r])=>r.select(ji(s,e,i),ce(s,e,i))),Mt=M({name:"rayIntersectsGround",type:"bool",inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i])=>{const{bottomRadius:r}=U(s);return i.lessThan(0).and(e.pow2().mul(i.pow2().sub(1)).add(r.pow2()).greaterThanEqual(0))}),X=M({name:"getTextureCoordFromUnitRange",type:"float",inputs:[{name:"unit",type:"float"},{name:"textureSize",type:"float"}]})(([s,e])=>t.div(.5,e).add(s.mul(e.reciprocal().oneMinus()))),Wi=M({name:"getTransmittanceTextureUV",type:"vec2",inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i])=>{const{topRadius:r,bottomRadius:n,transmittanceTextureSize:a}=U(s),o=t.sqrt(r.pow2().sub(n.pow2())).toConst(),u=ie(e.pow2().sub(n.pow2())).toConst(),c=ce(s,e,i),l=r.sub(e).toConst(),d=u.add(o),h=c.remap(l,d),m=u.div(o);return t.vec2(X(h,a.x),X(m,a.y))}),ne=A((s,e,i)=>r=>{const n=j(r),{parametersNode:a}=n,o=Wi(a,e,i);return s.sample(o).rgb}),Hi=A((s,e,i,r,n)=>a=>{const o=j(a),{parametersNode:u}=o,c=Ne(u,t.sqrt(r.pow2().add(t.mul(2,e,i,r)).add(e.pow2()))).toConst(),l=_(e.mul(i).add(r).div(c)).toConst(),d=t.vec3(0).toVar();return t.If(n,()=>{d.assign(ne(s,c,l.negate()).div(ne(s,e,i.negate())).min(1))}).Else(()=>{d.assign(ne(s,e,i).div(ne(s,c,l)).min(1))}),d}),we=A((s,e,i)=>r=>{const n=j(r),{parametersNode:a}=n,{sunAngularRadius:o,bottomRadius:u}=a,c=u.div(e).toConst(),l=t.sqrt(t.max(c.pow2().oneMinus(),0)).negate();return ne(s,e,i).mul(t.smoothstep(c.negate().mul(o),c.mul(o),i.sub(l)))}),Ke=M({name:"rayleighPhaseFunction",type:vt,inputs:[{name:"cosViewLight",type:z}]})(([s])=>t.div(3,t.mul(16,t.PI)).mul(s.pow2().add(1))),Rt=M({name:"miePhaseFunction",type:vt,inputs:[{name:"g",type:z},{name:"cosViewLight",type:z}]})(([s,e])=>t.div(3,t.PI.mul(8)).mul(s.pow2().oneMinus()).div(s.pow2().add(2)).mul(e.pow2().add(1)).div(s.pow2().sub(s.mul(2).mul(e)).add(1).pow(1.5))),zt=M({name:"getScatteringTextureCoord",type:"vec4",inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z},{name:"cosLight",type:z},{name:"cosViewLight",type:z},{name:"intersectsGround",type:"bool"}]})(([s,e,i,r,n,a])=>{const{topRadius:o,bottomRadius:u,minCosLight:c,scatteringTextureRadiusSize:l,scatteringTextureCosViewSize:d,scatteringTextureCosLightSize:h}=U(s),m=t.sqrt(o.pow2().sub(u.pow2())).toConst(),p=ie(e.pow2().sub(u.pow2())).toConst(),g=X(p.div(m),l),y=e.mul(i).toConst(),f=y.pow2().sub(e.pow2()).add(u.pow2()).toConst(),v=t.float(0).toVar();t.If(a,()=>{const E=y.negate().sub(ie(f)),L=e.sub(u).toConst(),F=p;v.assign(X(F.equal(L).select(0,E.remap(L,F)),d.div(2)).oneMinus().mul(.5))}).Else(()=>{const E=y.negate().add(ie(f.add(m.pow2()))),L=o.sub(e).toConst(),F=p.add(m);v.assign(X(E.remap(L,F),d.div(2)).add(1).mul(.5))});const S=o.sub(u).toConst(),b=m,C=ce(s,u,r).remap(S,b).toConst(),N=ce(s,u,c).remap(S,b),w=X(t.max(C.div(N).oneMinus(),0).div(C.add(1)),h),R=n.add(1).mul(.5);return t.vec4(R,w,v,g)}),Et=A((s,e,i,r,n,a)=>o=>{const u=j(o),{parametersNode:c}=u,{scatteringTextureCosViewLightSize:l}=c,d=zt(c,e,i,r,n,a).toConst(),h=d.x.mul(l.sub(1)).toConst(),m=t.floor(h).toConst(),p=h.sub(m).toConst(),g=t.vec3(m.add(d.y).div(l),d.z,d.w),y=t.vec3(m.add(1).add(d.y).div(l),d.z,d.w);return s.sample(g).mul(p.oneMinus()).add(s.sample(y).mul(p)).rgb}),_i=M({name:"getIrradianceTextureUV",type:"vec2",inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosLight",type:z}]})(([s,e,i])=>{const{topRadius:r,bottomRadius:n,irradianceTextureSize:a}=U(s),o=e.remap(n,r),u=i.mul(.5).add(.5);return t.vec2(X(u,a.x),X(o,a.y))}),Qi=A((s,e,i)=>r=>{const n=j(r),{parametersNode:a}=n,o=_i(a,e,i);return s.sample(o).rgb}),pt=M({name:"getLayerDensity",type:z,inputs:[{name:"layer",type:Te},{name:"altitude",type:D}]})(([s,e])=>{const i=s.get("expTerm"),r=s.get("expScale"),n=s.get("linearTerm"),a=s.get("constantTerm");return i.mul(t.exp(r.mul(e))).add(n.mul(e)).add(a).saturate()}),fe=M({name:"getProfileDensity",type:z,inputs:[{name:"layer",type:oe},{name:"altitude",type:D}]})(([s,e])=>e.lessThan(s.get("layer0").get("width")).select(pt(s.get("layer0"),e),pt(s.get("layer1"),e))),Y=M({name:"getUnitRangeFromTextureCoord",type:"float",inputs:[{name:"coord",type:"float"},{name:"textureSize",type:"float"}]})(([s,e])=>{const i=e.reciprocal();return s.sub(i.mul(.5)).div(i.oneMinus())}),Se=t.struct({radius:D,cosView:z,cosLight:z,cosViewLight:z,intersectsGround:"bool"},"ScatteringParams"),Zi=M({typeOnly:!0,name:"getParamsFromScatteringTextureCoord",type:Se,inputs:[{name:"parameters",type:B},{name:"coord",type:"vec4"}]})(([s,e])=>{const{bottomRadius:i,topRadius:r,minCosLight:n,scatteringTextureRadiusSize:a,scatteringTextureCosViewSize:o,scatteringTextureCosLightSize:u}=U(s),c=t.sqrt(r.pow2().sub(i.pow2())).toConst(),l=c.mul(Y(e.w,a)).toConst(),d=t.sqrt(l.pow2().add(i.pow2())),h=t.float(0).toVar(),m=t.bool().toVar();t.If(e.z.lessThan(.5),()=>{const N=d.sub(i).toConst(),w=l,R=N.add(w.sub(N).mul(Y(e.z.mul(2).oneMinus(),o.div(2)))).toConst();h.assign(R.equal(0).select(-1,_(l.pow2().add(R.pow2()).negate().div(t.mul(2,d,R))))),m.assign(t.bool(!0))}).Else(()=>{const N=r.sub(d).toConst(),w=l.add(c),R=N.add(w.sub(N).mul(Y(e.z.mul(2).sub(1),o.div(2)))).toConst();h.assign(R.equal(0).select(1,_(c.pow2().sub(l.pow2()).sub(R.pow2()).div(t.mul(2,d,R))))),m.assign(t.bool(!1))});const p=Y(e.y,u).toConst(),g=r.sub(i).toConst(),y=c,f=ce(s,i,n).remap(g,y).toConst(),v=f.sub(p.mul(f)).div(p.mul(f).add(1)),S=g.add(t.min(v,f).mul(y.sub(g))).toConst(),b=S.equal(0).select(1,_(c.pow2().sub(S.pow2()).div(t.mul(2,i,S)))),C=_(e.x.mul(2).sub(1));return Se(d,h,b,C,m)}),Ki=M({typeOnly:!0,name:"getParamsFromScatteringTextureFragCoord",type:Se,inputs:[{name:"parameters",type:B},{name:"fragCoord",type:"vec3"}]})(([s,e])=>{const{scatteringTextureRadiusSize:i,scatteringTextureCosViewSize:r,scatteringTextureCosLightSize:n,scatteringTextureCosViewLightSize:a}=U(s),o=t.floor(e.x.div(n)),u=e.x.mod(n),c=t.vec4(a.sub(1),n,r,i),l=t.vec4(o,u,e.y,e.z).div(c),d=Zi(s,l).toConst(),h=d.get("radius"),m=d.get("cosView"),p=d.get("cosLight"),g=d.get("cosViewLight").toVar(),y=d.get("intersectsGround"),f=t.sqrt(m.pow2().oneMinus().mul(p.pow2().oneMinus())).toConst();return g.assign(t.clamp(g,m.mul(p).sub(f),m.mul(p).add(f))),Se(h,m,p,g,y)}),Ji=M({name:"getExtrapolatedSingleMieScattering",type:ue,inputs:[{name:"scattering",type:"vec4"},{name:"rayleighScattering",type:"vec3"},{name:"mieScattering",type:"vec3"}]})(([s,e,i])=>{const r=t.vec3(0).toVar();return t.If(s.r.greaterThanEqual(1e-5),()=>{r.assign(s.rgb.mul(s.a).div(s.r).mul(e.r.div(i.r)).mul(i.div(e)))}),r}),Xi=t.struct({scattering:ue,singleMieScattering:ue},"CombinedScattering"),ve=A((s,e,i,r,n,a,o,u)=>c=>{const l=j(c),{rayleighScattering:d,mieScattering:h,scatteringTextureCosViewLightSize:m}=U(s),p=zt(s,r,n,a,o,u).toConst(),g=p.x.mul(m.sub(1)).toConst(),y=t.floor(g).toConst(),f=g.sub(y).toConst(),v=t.vec3(y.add(p.y).div(m),p.z,p.w).toConst(),S=t.vec3(y.add(1).add(p.y).div(m),p.z,p.w).toConst(),b=t.vec3(0).toVar(),C=t.vec3(0).toVar();if(l.parameters.combinedScatteringTextures){const N=t.add(e.sample(v).mul(f.oneMinus()),e.sample(S).mul(f)).toConst();b.assign(N.rgb),C.assign(Ji(N,d,h))}else b.assign(t.add(e.sample(v).mul(f.oneMinus()),e.sample(S).mul(f)).rgb),C.assign(t.add(i.sample(v).mul(f.oneMinus()),i.sample(S).mul(f)).rgb);return Xi(b,C)}),Yi=t.struct({radiance:Tt,transmittance:te},"RadianceTransfer"),es=M({name:"getSubUVFromTextureUnit",type:"vec2",inputs:[{name:"unit",type:"vec2"},{name:"textureSize",type:"vec2"}]})(([s,e])=>s.add(t.float(.5).div(e)).mul(e.div(e.add(1)))),Ft=M({name:"getTextureUnitFromSubUV",type:"vec2",inputs:[{name:"subUV",type:"vec2"},{name:"textureSize",type:"vec2"}]})(([s,e])=>s.sub(t.float(.5).div(e)).mul(e.div(e.sub(1)))),gt=t.struct({rayleighScattering:J,mieScattering:J,scattering:J,extinction:J},"AtmosphereMedium"),At=M({name:"sampleAtmosphereMedium",type:gt,inputs:[{name:"parameters",type:B},{name:"altitude",type:D}]})(([s,e])=>{const i=U(s),r=fe(i.rayleighDensity,e),n=fe(i.mieDensity,e),a=fe(i.absorptionDensity,e),o=r.mul(i.rayleighScattering),u=o,c=n.mul(i.mieScattering),l=n.mul(i.mieExtinction),d=a.mul(i.absorptionExtinction),h=t.add(o,c),m=t.add(u,l,d);return gt(o,c,h,m)}),ts=t.struct({multipleScattering:Tt,transferFactor:te},"MultipleScattering"),Vt=A((s,e,i,r,n,a)=>{const{solarIrradiance:o,bottomRadius:u,groundAlbedo:c}=U(s),l=Mt(s,i,r).toConst(),d=bt(s,i,r,l).toConst(),h=t.vec3(0).toVar(),m=t.vec3(0).toVar(),p=t.vec3(1).toVar(),g=t.float(0).toVar(),y=20;return t.Loop({type:"float",start:0,end:y},({i:f})=>{const v=d.mul(f.add(.3)).div(y).toConst(),S=v.sub(g).toConst();g.assign(v);const b=Ne(s,t.sqrt(v.pow2().add(t.mul(2,i,r,v)).add(i.pow2()))).toConst(),C=_(i.mul(n).add(v.mul(a)).div(b)).toConst(),N=b.sub(u),w=At(s,N).toConst(),R=w.get("scattering"),E=w.get("extinction"),L=E.mul(S).toConst(),F=t.exp(L.negate()).toConst(),O=we(e,b,C).toConst(),I=R.sub(R.mul(F)).div(E).toConst();m.addAssign(p.mul(I));const k=O.mul(R.mul(1/(4*Math.PI))).toConst(),W=k.sub(k.mul(F)).div(E).toConst();h.addAssign(p.mul(W)),p.mulAssign(F)}),t.If(l,()=>{const f=_(i.mul(n).add(d.mul(a)).div(u)).toConst(),v=we(e,u,f).toConst();h.addAssign(o.mul(v,p,f.saturate(),c,1/Math.PI))}),ts(h,m)}),is=A((s,e,i,r)=>{const{topRadius:n,bottomRadius:a,multipleScatteringTextureSize:o}=U(s),u=es(t.vec2(r.mul(.5).add(.5),i.sub(a).div(n.sub(a))).saturate(),o);return e.sample(u).rgb}),ss=t.struct({scattering:ue,singleMieScattering:ue,higherOrderScattering:$i},"Scattering"),Lt=A((s,e,i)=>r=>{const n=j(r),{parametersNode:a}=n,{solarIrradiance:o,bottomRadius:u}=a,c=Ki(a,i).toConst(),l=c.get("radius"),d=c.get("cosView"),h=c.get("cosLight"),m=c.get("cosViewLight"),p=c.get("intersectsGround"),g=bt(a,l,d,p).toConst(),y=t.mix(14,30,g.mul(1/100)).toConst(),f=y.floor().toConst(),v=f.reciprocal().toConst(),S=g.mul(f).div(y).toConst(),b=Ke(m).toConst(),C=t.vec3(0).toVar(),N=t.vec3(0).toVar(),w=t.vec3(0).toVar(),R=t.vec3(1).toVar();return t.Loop({type:"float",start:0,end:y},({i:E})=>{const L=E.mul(v).toVar(),F=E.add(1).mul(v).toVar();L.mulAssign(L),F.mulAssign(F),L.mulAssign(S),F.assign(F.greaterThan(1).select(g,S.mul(F)));const O=F.sub(L),I=L.add(O.mul(.3)),k=Ne(a,t.sqrt(I.pow2().add(t.mul(2,l,d,I)).add(l.pow2()))).toConst(),W=_(l.mul(h).add(I.mul(m)).div(k)).toConst(),le=k.sub(u),P=At(a,le).toConst(),ee=P.get("rayleighScattering"),se=P.get("mieScattering"),Z=P.get("scattering"),H=P.get("extinction"),qt=H.mul(O),xe=t.exp(qt.negate()).toConst(),Je=we(s,k,W).toConst(),Xe=is(a,e,k,W).mul(Z).toConst();let re=Je.mul(ee);n.parameters.higherOrderScatteringTexture||(re=re.add(Xe.div(b))),re=o.mul(re).toConst();const kt=re.sub(re.mul(xe)).div(H).toConst();C.addAssign(R.mul(kt));const Ye=o.mul(Je.mul(se)).toConst(),Gt=Ye.sub(Ye.mul(xe)).div(H).toConst();N.addAssign(R.mul(Gt));const et=o.mul(Xe),$t=et.sub(et.mul(xe)).div(H).toConst();w.addAssign(R.mul($t)),R.mulAssign(xe)}),ss(C,N,w)}),Ae=M({name:"computeOpticalDepthToTopAtmosphereBoundary",type:D,inputs:[{name:"parameters",type:B},{name:"profile",type:oe},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i,r])=>{const{bottomRadius:n}=U(s),a=500,o=ce(s,i,r).div(a).toConst(),u=t.float(0).toVar();return t.Loop({start:0,end:a,condition:"<="},({i:c})=>{const l=t.float(c).mul(o).toConst(),d=t.sqrt(t.add(l.pow2(),t.mul(2,i,r,l),i.pow2())).toConst(),h=fe(e,d.sub(n)),m=t.vec2(c).equal(t.vec2(0,a)).any().select(.5,1);u.addAssign(h.mul(m).mul(o))}),u}),rs=M({name:"computeTransmittanceToTopAtmosphereBoundary",type:te,inputs:[{name:"parameters",type:B},{name:"radius",type:D},{name:"cosView",type:z}]})(([s,e,i])=>{const{rayleighDensity:r,rayleighScattering:n,mieDensity:a,mieExtinction:o,absorptionDensity:u,absorptionExtinction:c}=U(s),l=Ae(s,r,e,i),d=Ae(s,a,e,i),h=Ae(s,u,e,i),m=t.add(n.mul(l),o.mul(d),c.mul(h)).toConst();return t.exp(m.negate())}),ns=M({typeOnly:!0,name:"getParamsFromTransmittanceTextureUV",type:"vec2",inputs:[{name:"parameters",type:B},{name:"uv",type:"vec2"}]})(([s,e])=>{const{topRadius:i,bottomRadius:r,transmittanceTextureSize:n}=U(s),a=Y(e.x,n.x),o=Y(e.y,n.y),u=t.sqrt(i.pow2().sub(r.pow2())).toConst(),c=u.mul(o).toConst(),l=t.sqrt(c.pow2().add(r.pow2())),d=i.sub(l).toConst(),h=c.add(u),m=d.add(a.mul(h.sub(d))).toConst(),p=m.equal(0).select(1,u.pow2().sub(c.pow2()).sub(m.pow2()).div(t.mul(2,l,m)));return t.vec2(l,p)}),Pt=A(s=>e=>{const i=j(e),{parametersNode:r}=i,{transmittanceTextureSize:n}=r,a=ns(r,s.div(n)).toConst(),o=a.x,u=a.y;return rs(r,o,u)}),as=M({typeOnly:!0,name:"getParamsFromIrradianceTextureUV",type:"vec2",inputs:[{name:"parameters",type:B},{name:"uv",type:"vec2"}]})(([s,e])=>{const{topRadius:i,bottomRadius:r,irradianceTextureSize:n}=U(s),a=Y(e.x,n.x),o=Y(e.y,n.y),u=r.add(o.mul(i.sub(r))),c=_(a.mul(2).sub(1));return t.vec2(u,c)}),Dt=A((s,e,i)=>r=>{const n=j(r),{parametersNode:a}=n,{miePhaseFunctionG:o,irradianceTextureSize:u}=a,c=as(a,i.div(u)).toConst(),l=c.x,d=c.y,h=32,m=Math.PI/h,p=Math.PI/h,g=t.vec3(0).toVar(),y=t.vec3(t.sqrt(d.pow2().oneMinus()),0,d).toConst();return t.Loop({start:0,end:h/2,name:"j"},({j:f})=>{const v=t.float(f).add(.5).mul(p).toConst();t.Loop({start:0,end:h*2},({i:S})=>{const b=t.float(S).add(.5).mul(m).toConst(),C=t.vec3(t.cos(b).mul(t.sin(v)),t.sin(b).mul(t.sin(v)),t.cos(v)).toConst(),N=t.sin(v).mul(p*m),w=C.dot(y),R=ve(a,s,s,l,C.z,d,w,t.bool(!1));let E=t.vec3(0);n.parameters.higherOrderScatteringTexture&&(E=Et(e,l,C.z,d,w,t.bool(!1)));const L=R.get("scattering"),F=R.get("singleMieScattering"),O=Ke(w),I=Rt(o,w);g.addAssign(L.mul(O).add(F.mul(I)).add(E).mul(C.z,N))})}),g});function Ve(s){const e=new x.RenderTarget(1,1,{depthBuffer:!1,format:x.RGBAFormat}),i=e.texture;return i.minFilter=x.LinearFilter,i.magFilter=x.LinearFilter,i.colorSpace=x.NoColorSpace,i.generateMipmaps=!1,i.name=s,e}function Le(s){const e=new x.RenderTarget3D(1,1,1,{depthBuffer:!1,format:x.RGBAFormat}),i=e.texture;return i.minFilter=x.LinearFilter,i.magFilter=x.LinearFilter,i.colorSpace=x.NoColorSpace,i.generateMipmaps=!1,i.name=s,e}function Pe(s,e,i){s.texture.type=e,s.setSize(i.x,i.y)}function De(s,e,i){s.texture.type=e,s.setSize(i.x,i.y,i.z),s.texture.isArrayTexture=!1}class os extends St{}class us extends Ct{constructor(){super(),this.mesh=new T.QuadMesh,this.layer=t.uniform(0),this.mesh.name="AtmosphereLUTTexturesWebGL",this.transmittanceRT=Ve("transmittance"),this.multipleScatteringRT=Ve("multipleScattering"),this.scatteringRT=Le("scattering"),this.singleMieScatteringRT=Le("singleMieScattering"),this.higherOrderScatteringRT=Le("higherOrderScattering"),this.irradianceRT=Ve("irradiance")}get(e){return this[`${e}RT`].texture}createContext(){return Q(this.parameters!=null),Q(this.textureType!=null),new os(this.parameters,this.textureType)}renderToRenderTarget(e,i,r){r!=null&&i.textures.push(...r.filter(n=>n!=null)),e.setRenderTarget(i),this.mesh.render(e),i.textures.length=1}renderToRenderTarget3D(e,i,r,n){n!=null&&i.textures.push(...n.filter(a=>a!=null));for(let a=0;a<i.depth;++a)r.value=a,e.setRenderTarget(i,a),this.mesh.render(e);i.textures.length=1}createMaterial(e){const i=new T.NodeMaterial;return i.fragmentNode=e,i.needsUpdate=!0,i}computeTransmittance(e,i){this.transmittanceMaterial?.dispose(),this.transmittanceMaterial=this.createMaterial(t.mrt({transmittance:Pt(t.screenCoordinate).context({getAtmosphere:()=>i})})),this.mesh.material=this.transmittanceMaterial,this.renderToRenderTarget(e,this.transmittanceRT)}computeMultipleScattering(e,i){const{parameters:r,parametersNode:n}=i,a=64,o=A(c=>{const l=t.float(c),d=l.mul(2*Math.PI/((1+Math.sqrt(5))/2)),h=t.acos(l.add(.5).mul(2/a).oneMinus()),m=t.cos(h),p=t.sin(h),g=t.cos(d),y=t.sin(d);return t.vec3(g.mul(p),y.mul(p),m)}),u=t.Fn(()=>{const c=t.vec2(r.multipleScatteringTextureSize),l=Ft(t.screenCoordinate.div(c),c).toConst(),{topRadius:d,bottomRadius:h}=n,m=l.x.mul(2).sub(1).toConst(),p=t.vec3(0,t.sqrt(m.pow2().oneMinus().saturate()),m).toConst(),g=0,y=h.add(l.y.add(g).saturate().mul(d.sub(h).sub(g))).toConst(),f=t.vec3(0).toVar(),v=t.vec3(0).toVar();return t.Loop({start:0,end:a},({i:S})=>{const b=o(S).toConst(),C=b.z,N=b.dot(p).toConst(),w=Vt(n,t.texture(this.transmittanceRT.texture),y,C,m,N).context({getAtmosphere:()=>i}).toConst();f.addAssign(w.get("multipleScattering").div(a)),v.addAssign(w.get("transferFactor").div(a))}),f.mul(v.oneMinus().reciprocal())});this.multipleScatteringMaterial?.dispose(),this.multipleScatteringMaterial=this.createMaterial(t.mrt({multipleScattering:t.vec4(u(),1)})),this.mesh.material=this.multipleScatteringMaterial,this.renderToRenderTarget(e,this.multipleScatteringRT)}computeScattering(e,i){const{parameters:r}=i;this.scatteringMaterial?.dispose(),this.scatteringMaterial=this.createMaterial((()=>{const a=Lt(t.texture(this.transmittanceRT.texture),t.texture(this.multipleScatteringRT.texture),t.vec3(t.screenCoordinate,this.layer.add(.5))).context({getAtmosphere:()=>i}).toConst(),o=a.get("scattering"),u=a.get("singleMieScattering"),c=a.get("higherOrderScattering"),l={};return r.combinedScatteringTextures?l.scattering=t.vec4(o,u.r):(l.scattering=t.vec4(o,u.r),l.singleMieScattering=t.vec4(u,1)),r.higherOrderScatteringTexture&&(l.higherOrderScattering=t.vec4(c,1)),t.mrt(l)})()),this.mesh.material=this.scatteringMaterial;const n=[];r.combinedScatteringTextures||n.push(this.singleMieScatteringRT.texture),r.higherOrderScatteringTexture&&n.push(this.higherOrderScatteringRT.texture),this.renderToRenderTarget3D(e,this.scatteringRT,this.layer,n)}computeIrradiance(e,i){this.irradianceMaterial?.dispose(),this.irradianceMaterial=this.createMaterial(t.mrt({irradiance:Dt(t.texture3D(this.scatteringRT.texture),t.texture3D(this.higherOrderScatteringRT.texture),t.screenCoordinate).context({getAtmosphere:()=>i})})),this.mesh.material=this.irradianceMaterial,this.renderToRenderTarget(e,this.irradianceRT)}setup(e,i){Pe(this.transmittanceRT,i,e.transmittanceTextureSize),Pe(this.multipleScatteringRT,i,e.multipleScatteringTextureSize),De(this.scatteringRT,i,e.scatteringTextureSize),e.combinedScatteringTextures||De(this.singleMieScatteringRT,i,e.scatteringTextureSize),e.higherOrderScatteringTexture&&De(this.higherOrderScatteringRT,i,e.scatteringTextureSize),Pe(this.irradianceRT,i,e.irradianceTextureSize),super.setup(e,i)}dispose(){this.transmittanceRT.dispose(),this.multipleScatteringRT.dispose(),this.scatteringRT.dispose(),this.irradianceRT.dispose(),this.transmittanceMaterial?.dispose(),this.multipleScatteringMaterial?.dispose(),this.scatteringMaterial?.dispose(),this.irradianceMaterial?.dispose(),this.mesh.geometry.dispose(),super.dispose()}}function Ue(s){const e=new T.StorageTexture(1,1);return e.minFilter=x.LinearFilter,e.magFilter=x.LinearFilter,e.colorSpace=x.NoColorSpace,e.generateMipmaps=!1,e.name=s,e}function Ie(s){const e=new T.Storage3DTexture(1,1,1);return e.minFilter=x.LinearFilter,e.magFilter=x.LinearFilter,e.colorSpace=x.NoColorSpace,e.generateMipmaps=!1,e.name=s,e}function Be(s,e,i){s.type=e,q.reinterpretType(s.image),s.image.width=i.x,s.image.height=i.y}function Oe(s,e,i){s.type=e,q.reinterpretType(s.image),s.image.width=i.x,s.image.height=i.y,s.image.depth=i.z}class cs extends St{}class ls extends Ct{constructor(){super(),this.transmittance=Ue("transmittance"),this.multipleScattering=Ue("multipleScattering"),this.scattering=Ie("scattering"),this.singleMieScattering=Ie("singleMieScattering"),this.higherOrderScattering=Ie("higherOrderScattering"),this.irradiance=Ue("irradiance")}get(e){return this[e]}createContext(){return Q(this.parameters!=null),Q(this.textureType!=null),new cs(this.parameters,this.textureType)}computeTransmittance(e,i){const{parameters:r}=i,{x:n,y:a}=r.transmittanceTextureSize;this.transmittanceNode?.dispose(),this.transmittanceNode=t.Fn(()=>{const o=t.uvec2(n,a);t.If(t.globalId.xy.greaterThanEqual(o).any(),()=>{t.Return()});const u=Pt(t.vec2(t.globalId.xy).add(.5));t.textureStore(this.transmittance,t.globalId.xy,u)})().context({getAtmosphere:()=>i}).computeKernel([8,8,1]).setName("transmittance"),e.compute(this.transmittanceNode,[Math.ceil(n/8),Math.ceil(a/8),1])}computeMultipleScattering(e,i){const{parameters:r,parametersNode:n}=i,{x:a,y:o}=r.multipleScatteringTextureSize,u=64,c=A(l=>{const d=t.float(l),h=d.mul(2*Math.PI/((1+Math.sqrt(5))/2)),m=t.acos(d.add(.5).mul(2/u).oneMinus()),p=t.cos(m),g=t.sin(m),y=t.cos(h),f=t.sin(h);return t.vec3(y.mul(g),f.mul(g),p)});this.multipleScatteringNode?.dispose(),this.multipleScatteringNode=t.Fn(()=>{const l=t.workgroupArray("vec3",u),d=t.workgroupArray("vec3",u),h=t.vec2(a,o).toConst(),m=t.vec2(t.globalId.xy).add(.5),p=Ft(m.div(h),h).toConst(),g=t.globalId.z,{topRadius:y,bottomRadius:f}=n,v=p.x.mul(2).sub(1).toConst(),S=t.vec3(0,t.sqrt(v.pow2().oneMinus().saturate()),v).toConst(),b=0,C=f.add(p.y.add(b).saturate().mul(y.sub(f).sub(b))).toConst(),N=c(g).toConst(),w=N.z,R=N.dot(S).toConst(),E=Vt(n,t.texture(this.transmittance),C,w,v,R).toConst();l.element(g).assign(E.get("multipleScattering").div(u)),d.element(g).assign(E.get("transferFactor").div(u)),t.workgroupBarrier();for(let O=u>>1;O>0;O>>>=1){const I=t.uint(O);t.If(g.lessThan(I),()=>{l.element(g).addAssign(l.element(g.add(I))),d.element(g).addAssign(d.element(g.add(I)))}),t.workgroupBarrier()}t.If(g.greaterThan(0),()=>{t.Return()});const L=l.element(t.uint(0)),F=d.element(t.uint(0));t.textureStore(this.multipleScattering,t.globalId.xy,t.vec4(L.mul(F.oneMinus().reciprocal()),1))})().context({getAtmosphere:()=>i}).computeKernel([1,1,u]).setName("multipleScattering"),e.compute(this.multipleScatteringNode,[a,o,1])}computeScattering(e,i){const{parameters:r}=i,{x:n,y:a,z:o}=r.scatteringTextureSize;this.scatteringNode?.dispose(),this.scatteringNode=t.Fn(()=>{const u=t.uvec3(n,a,o);t.If(t.globalId.greaterThanEqual(u).any(),()=>{t.Return()});const c=Lt(t.texture(this.transmittance),t.texture(this.multipleScattering),t.vec3(t.globalId).add(.5)).toConst(),l=c.get("scattering"),d=c.get("singleMieScattering");if(r.combinedScatteringTextures?t.textureStore(this.scattering,t.globalId,t.vec4(l,d.r)):(t.textureStore(this.scattering,t.globalId,t.vec4(l,1)),t.textureStore(this.singleMieScattering,t.globalId,t.vec4(d,1))),r.higherOrderScatteringTexture){const h=c.get("higherOrderScattering");t.textureStore(this.higherOrderScattering,t.globalId,t.vec4(h,1))}})().context({getAtmosphere:()=>i}).computeKernel([4,4,4]).setName("scattering"),e.compute(this.scatteringNode,[Math.ceil(n/4),Math.ceil(a/4),Math.ceil(o/4)])}computeIrradiance(e,i){const{parameters:r}=i,{x:n,y:a}=r.irradianceTextureSize;this.irradianceNode?.dispose(),this.irradianceNode=t.Fn(()=>{const o=t.uvec2(n,a);t.If(t.globalId.xy.greaterThanEqual(o).any(),()=>{t.Return()});const u=Dt(t.texture3D(this.scattering),t.texture3D(this.higherOrderScattering),t.vec2(t.globalId.xy).add(.5));t.textureStore(this.irradiance,t.globalId.xy,u)})().context({getAtmosphere:()=>i}).computeKernel([8,8,1]).setName("irradiance"),e.compute(this.irradianceNode,[Math.ceil(n/8),Math.ceil(a/8),1])}setup(e,i){Be(this.transmittance,i,e.transmittanceTextureSize),Be(this.multipleScattering,i,e.multipleScatteringTextureSize),Oe(this.scattering,i,e.scatteringTextureSize),e.combinedScatteringTextures||Oe(this.singleMieScattering,i,e.scatteringTextureSize),e.higherOrderScatteringTexture&&Oe(this.higherOrderScattering,i,e.scatteringTextureSize),Be(this.irradiance,i,e.irradianceTextureSize),super.setup(e,i)}dispose(){this.transmittance.dispose(),this.multipleScattering.dispose(),this.scattering.dispose(),this.singleMieScattering.dispose(),this.higherOrderScattering.dispose(),this.irradiance.dispose(),this.transmittanceNode?.dispose(),this.multipleScatteringNode?.dispose(),this.scatteringNode?.dispose(),this.irradianceNode?.dispose(),super.dispose()}}class K{constructor(e=0,i=0,r=0,n=0,a=0){this.width=e,this.expTerm=i,this.expScale=r,this.linearTerm=n,this.constantTerm=a}copy(e){return this.width=e.width,this.expTerm=e.expTerm,this.expScale=e.expScale,this.linearTerm=e.linearTerm,this.constantTerm=e.constantTerm,this}clone(){return new K().copy(this)}}class de{constructor(e){this.layers=e}copy(e){return this.layers=[e.layers[0].clone(),e.layers[1].clone()],this}clone(){return new de([this.layers[0].clone(),this.layers[1].clone()])}}const ds=new x.Vector3(.2126,.7152,.0722);class ge{constructor(){this.worldToUnit=.001,this.solarIrradiance=new x.Vector3(1.474,1.8504,1.91198),this.sunAngularRadius=.004675,this.bottomRadius=636e4,this.topRadius=642e4,this.rayleighDensity=new de([new K,new K(0,1,-1/8e3)]),this.rayleighScattering=new x.Vector3(5802e-9,13558e-9,331e-7),this.mieDensity=new de([new K,new K(0,1,-1/1200)]),this.mieScattering=new x.Vector3().setScalar(3996e-9),this.mieExtinction=new x.Vector3().setScalar(444e-8),this.miePhaseFunctionG=.8,this.absorptionDensity=new de([new K(25e3,0,0,1/15e3,-2/3),new K(0,0,0,-1/15e3,8/3)]),this.absorptionExtinction=new x.Vector3(65e-8,1881e-9,85e-9),this.groundAlbedo=new x.Vector3().setScalar(.3),this.minCosLight=Math.cos(q.radians(120)),this.sunRadianceToLuminance=new x.Vector3(98242.786222,69954.398112,66475.012354),this.skyRadianceToLuminance=new x.Vector3(114974.91644,71305.954816,65310.548555),this.luminanceScale=1/ds.dot(this.sunRadianceToLuminance),this.combinedScatteringTextures=!0,this.higherOrderScatteringTexture=!0,this.transmittanceTextureSize=new x.Vector2(256,64),this.irradianceTextureSize=new x.Vector2(64,16),this.multipleScatteringTextureSize=new x.Vector2(64,64),this.scatteringTextureRadiusSize=32,this.scatteringTextureCosViewSize=128,this.scatteringTextureCosLightSize=32,this.scatteringTextureCosViewLightSize=8,this.scatteringTextureSize=new x.Vector3,this.update()}copy(e){return this.worldToUnit=e.worldToUnit,this.solarIrradiance.copy(e.solarIrradiance),this.sunAngularRadius=e.sunAngularRadius,this.bottomRadius=e.bottomRadius,this.topRadius=e.topRadius,this.rayleighDensity.copy(e.rayleighDensity),this.rayleighScattering.copy(e.rayleighScattering),this.mieDensity.copy(e.mieDensity),this.mieScattering.copy(e.mieScattering),this.mieExtinction.copy(e.mieExtinction),this.miePhaseFunctionG=e.miePhaseFunctionG,this.absorptionDensity.copy(e.absorptionDensity),this.absorptionExtinction.copy(e.absorptionExtinction),this.groundAlbedo.copy(e.groundAlbedo),this.minCosLight=e.minCosLight,this.sunRadianceToLuminance.copy(e.sunRadianceToLuminance),this.skyRadianceToLuminance.copy(e.skyRadianceToLuminance),this.luminanceScale=e.luminanceScale,this.combinedScatteringTextures=e.combinedScatteringTextures,this.transmittanceTextureSize.copy(e.transmittanceTextureSize),this.irradianceTextureSize.copy(e.irradianceTextureSize),this.multipleScatteringTextureSize.copy(e.multipleScatteringTextureSize),this.scatteringTextureRadiusSize=e.scatteringTextureRadiusSize,this.scatteringTextureCosViewSize=e.scatteringTextureCosViewSize,this.scatteringTextureCosLightSize=e.scatteringTextureCosLightSize,this.scatteringTextureCosViewLightSize=e.scatteringTextureCosViewLightSize,this.scatteringTextureSize.copy(e.scatteringTextureSize),this}update(){return this.scatteringTextureSize.set(this.scatteringTextureCosViewLightSize*this.scatteringTextureCosLightSize,this.scatteringTextureCosViewSize,this.scatteringTextureRadiusSize),this}clone(){return new ge().copy(this)}get minCosSun(){return this.minCosLight}set minCosSun(e){this.minCosLight=e}get scatteringTextureCosSunSize(){return this.scatteringTextureCosLightSize}set scatteringTextureCosSunSize(e){this.scatteringTextureCosLightSize=e}get scatteringTextureCosViewSunSize(){return this.scatteringTextureCosViewLightSize}set scatteringTextureCosViewSunSize(e){this.scatteringTextureCosViewLightSize=e}get transmittancePrecisionLog(){return!1}set transmittancePrecisionLog(e){}}const{resetRendererState:hs,restoreRendererState:ms}=T.RendererUtils;async function ps(s){const e=s[Symbol.iterator]();return await new Promise((i,r)=>{const n=()=>{try{const{value:a,done:o}=e.next();o===!0?i(a):lt(n)}catch(a){r(a instanceof Error?a:new Error)}};lt(n)})}let qe;function ye(s,e){return qe=hs(s,qe),s.setClearColor(0,0),s.autoClear=!1,e(),ms(s,qe),!0}const ke=new x.Texture,Ge=(()=>{const s=new x.Data3DTexture(new Uint8Array(4));return s.format=x.RGBAFormat,s.needsUpdate=!0,s})(),gs={type:"update"};class xs extends T.Node{constructor(e=new ge,i){super(null),this.textureNodes={transmittance:ae(this,ke),multipleScattering:ae(this,ke),scattering:ze(this,Ge),singleMieScattering:ze(this,Ge),higherOrderScattering:ze(this,Ge),irradiance:ae(this,ke)},this.updating=!1,this.updateBeforeType=T.NodeUpdateType.FRAME,this.parameters=e,this.textureType=i}static get type(){return"AtmosphereLUTNode"}getTextureNode(e){return this.textureNodes[e]}dispatchUpdate(){this.dispatchEvent(gs)}*performCompute(e,i){const{textures:r}=this;Q(r!=null),yield ye(e,()=>{r.computeTransmittance(e,i),this.dispatchUpdate()}),yield ye(e,()=>{r.computeMultipleScattering(e,i),this.dispatchUpdate()}),yield ye(e,()=>{r.computeScattering(e,i),this.dispatchUpdate()}),yield ye(e,()=>{r.computeIrradiance(e,i),this.dispatchUpdate()})}async updateTextures(e){Q(this.textures!=null);const i=this.textures.createContext();this.updating=!0;try{await ps(this.performCompute(e,i))}finally{this.updating=!1,i.dispose(),this.disposeQueue?.()}}updateBefore({renderer:e}){e==null||this.version===this.currentVersion||(this.currentVersion=this.version,this.updateTextures(e).catch(i=>{throw i instanceof Error?i:new Error}))}setup(e){if(this.textures==null){this.textures=Qe(e)?new ls:new us;const{transmittance:r,irradiance:n,multipleScattering:a,scattering:o,singleMieScattering:u,higherOrderScattering:c}=this.textureNodes;r.value=this.textures.get("transmittance"),a.value=this.textures.get("multipleScattering"),o.value=this.textures.get("scattering"),u.value=this.textures.get("singleMieScattering"),c.value=this.textures.get("higherOrderScattering"),n.value=this.textures.get("irradiance")}const i=q.isFloatLinearSupported(e.renderer)?this.textureType??x.FloatType:x.HalfFloatType;return this.parameters.update(),this.textures.setup(this.parameters,i),super.setup(e)}dispose(){if(this.updating){this.disposeQueue=()=>{this.dispose(),this.disposeQueue=void 0};return}this.textures?.dispose(),this.textures=void 0,super.dispose()}}const ys=new x.Vector3,fs=new q.Geodetic;class Ut extends Ze{constructor(e=new ge,i=new xs(e)){super(e),this.matrixWorldToECEF=t.uniform("mat4").setName("matrixWorldToECEF"),this.matrixECIToECEF=t.uniform("mat4").setName("matrixECIToECEF"),this.sunDirectionECEF=t.uniform("vec3").setName("sunDirectionECEF"),this.moonDirectionECEF=t.uniform("vec3").setName("moonDirectionECEF"),this.matrixMoonFixedToECEF=t.uniform("mat4").setName("matrixMoonFixedToECEF"),this.scatteringSampleCount=t.uniform(new x.Vector2(4,14)),this.matrixECEFToWorld=t.uniform("mat4").setName("matrixECEFToWorld").onRenderUpdate((r,{value:n})=>{n.copy(this.matrixWorldToECEF.value).transpose()}),this.cameraPositionECEF=t.uniform("vec3").setName("cameraPositionECEF").onRenderUpdate((r,{value:n})=>{const a=this.camera??r.camera;a!=null&&n.setFromMatrixPosition(a.matrixWorld).applyMatrix4(this.matrixWorldToECEF.value)}),this.altitudeCorrectionECEF=t.uniform("vec3").setName("altitudeCorrectionECEF").onRenderUpdate((r,{value:n})=>{const a=this.camera??r.camera;a!=null&&Oi(n.setFromMatrixPosition(a.matrixWorld).applyMatrix4(this.matrixWorldToECEF.value),this.parameters.bottomRadius,this.ellipsoid,n)}),this.cameraHeight=t.uniform(0).setName("cameraHeight").onRenderUpdate((r,n)=>{const a=this.camera??r.camera;if(a==null)return;const o=ys.setFromMatrixPosition(a.matrixWorld).applyMatrix4(this.matrixWorldToECEF.value);n.value=fs.setFromECEF(o).height}),this.cameraPositionUnit=this.cameraPositionECEF.mul(this.parametersNode.worldToUnit).toConst("cameraPositionUnit"),this.altitudeCorrectionUnit=this.altitudeCorrectionECEF.mul(this.parametersNode.worldToUnit).toConst("altitudeCorrectionUnit"),this.ellipsoid=q.Ellipsoid.WGS84,this.correctAltitude=!0,this.constrainCamera=!0,this.showGround=!0,this.accurateShadowScattering=!0,this.raymarchScattering=!0,this.lutNode=i}dispose(){this.lutNode.dispose(),super.dispose()}}function $(s){if(typeof s.context.getAtmosphere!="function")throw new Error("getAtmosphere() was not found in the builder context.");const e=s.context.getAtmosphere();if(!(e instanceof Ut))throw new Error("getAtmosphere() must return an instanceof AtmosphereContext.");return e}t.Fn(s=>{const{parametersNode:e}=$(s),{worldToUnit:i}=e;return t.positionView.z.mul(i)}).once()().toVar("viewZUnit");const vs=(s,e,i,r,n,a)=>{const o=Ne(s,t.sqrt(a.pow2().add(t.mul(2,e,i,a)).add(e.pow2()))).toConst(),u=e.mul(i).add(a).div(o).toConst(),c=e.mul(r).add(a.mul(n)).div(o).toConst();return{radius:o,cosView:u,cosLight:c}},Ts=A((s,e,i,r,n)=>{const{lutNode:a,parametersNode:o}=s,u=a.getTextureNode("transmittance"),c=a.getTextureNode("scattering"),l=a.getTextureNode("singleMieScattering"),{topRadius:d,bottomRadius:h,miePhaseFunctionG:m}=o,p=e.length().toVar();e=e.toVar(),s.constrainCamera&&t.If(p.lessThan(h),()=>{p.assign(h),e.assign(e.normalize().mul(p))});const g=e.dot(i).toVar(),y=g.negate().sub(ie(g.pow2().sub(p.pow2()).add(d.pow2()))).toConst();r=r.toVar(),t.If(y.greaterThan(0),()=>{e.assign(e.add(i.mul(y))),p.assign(d),g.addAssign(y),r.y.assign(r.y.sub(y).max(0))});const f=t.vec3(0).toVar(),v=t.vec3(1).toVar();return t.If(p.lessThanEqual(d),()=>{const S=g.div(p).toConst(),b=e.dot(n).div(p).toConst(),C=i.dot(n).toConst(),N=Mt(o,p,S).toVar();v.assign(N.select(0,ne(u,p,S))),s.showGround||N.assign(t.bool(!1));const w=t.vec3(0).toVar(),R=t.vec3(0).toVar(),E=P=>{const ee=vs(o,p,S,b,C,P),se=ve(o,c,l,ee.radius,ee.cosView,ee.cosLight,C,N).toConst(),Z=Hi(u,p,S,P,N);return{S:se.get("scattering"),M:se.get("singleMieScattering"),T:Z}},L=r.y.add(r.x).toConst(),F=()=>{const P=E(r.x);w.assign(P.T.mul(P.S)),R.assign(P.T.mul(P.M))},O=()=>{const P=ve(o,c,l,p,S,b,C,N).toConst(),ee=P.get("scattering"),se=P.get("singleMieScattering"),Z=E(r.y),H=E(L);w.assign(ee.sub(Z.T.mul(Z.S).sub(H.T.mul(H.S)).max(0))),R.assign(se.sub(Z.T.mul(Z.M).sub(H.T.mul(H.M)).max(0)))},I=t.If(r.x.equal(0),()=>{const P=ve(o,c,l,p,S,b,C,N).toConst();w.assign(P.get("scattering")),R.assign(P.get("singleMieScattering"))});s.accurateShadowScattering?I.Else(O):I.Else(F);let k=t.vec3(0);if(s.parameters.higherOrderScatteringTexture){const P=a.getTextureNode("higherOrderScattering");k=Et(P,p,S,b,C,N)}const W=Ke(C),le=Rt(m,C);f.assign(w.mul(W).add(R.mul(le)).add(k))}),Yi(f,v)}),ws=A((s,e,i,r)=>{const{lutNode:n}=s,a=n.getTextureNode("irradiance"),o=e.length().toConst(),u=e.dot(r).div(o).toConst();return Qi(a,o,u).mul(i.dot(e).div(o).add(1).mul(.5))}),Ss=A(()=>s=>{const e=j(s),{parametersNode:i}=e,{solarIrradiance:r,sunAngularRadius:n,sunRadianceToLuminance:a,luminanceScale:o}=i;return r.div(t.PI.mul(n.pow2())).mul(a.mul(o))}),Cs=t.struct({luminance:wt,transmittance:te},"LuminanceTransfer"),xt=A((s,e,i,r)=>n=>{const a=$(n),{parametersNode:o}=a,{skyRadianceToLuminance:u,luminanceScale:c}=o,l=Ts(a,s,e,i,r),d=l.get("radiance").mul(u.mul(c));return Cs(d,l.get("transmittance"))}),Ns=A((s,e,i)=>r=>{const n=$(r),{parametersNode:a}=n,{skyRadianceToLuminance:o,luminanceScale:u}=a;return ws(n,s,e,i).mul(o.mul(u))}),bs=M({name:"getLunarRadiance",type:wt,inputs:[{name:"parameters",type:B},{name:"moonAngularRadius",type:"float"}]})(([s,e])=>{const{solarIrradiance:i,sunRadianceToLuminance:r,luminanceScale:n}=U(s);return i.mul(25e-7).div(t.PI.mul(e.pow2())).mul(r.mul(n))}),Ms=M({name:"raySphereIntersectionNormal",type:"vec3",inputs:[{name:"rayDirection",type:"vec3"},{name:"centerDirection",type:"vec3"},{name:"angularRadius",type:"float"}]})(([s,e,i])=>{const r=e.dot(s),n=e.sub(s.mul(r)).negate().toConst(),a=t.sqrt(i.pow2().sub(n.dot(n)).max(0));return n.sub(s.mul(a)).div(i)}),Rs=M({name:"orenNayarDiffuse",type:"float",inputs:[{name:"lightDirection",type:"vec3"},{name:"viewDirection",type:"vec3"},{name:"normal",type:"vec3"}]})(([s,e,i])=>{const r=i.dot(s).toConst(),n=i.dot(e).toConst(),a=s.dot(e).sub(r.mul(n)).toConst(),o=t.mix(1,t.max(r,n).max(.1),a.smoothstep(0,.1)),u=1/Math.PI*(1-.5*(1/1.33)+.17*(1/1.13)),c=1/Math.PI*(.45*(1/1.09));return r.max(0).mul(a.div(o).mul(c).add(u))});class zs extends T.TempNode{constructor(){super("vec4"),this.angularRadius=t.uniform(.0045),this.intensity=t.uniform(1),this.displacementScale=t.uniform(65535*.5/1727400)}static get type(){return"MoonNode"}setup(e){const i=$(e),{rayDirectionECEF:r}=this;if(r==null)return;const{sunDirectionECEF:n,moonDirectionECEF:a,matrixMoonFixedToECEF:o}=i;return t.Fn(()=>{const u=t.cos(this.angularRadius).oneMinus().mul(2),c=r.sub(a),l=c.dot(c),d=t.fwidth(l),h=t.vec2().toVar(),m=t.vec3().toVar(),p=t.vec3().toVar();t.If(l.lessThan(u),()=>{m.assign(Ms(r,a,this.angularRadius)),p.assign(o.transpose().mul(t.vec4(m,0)).xyz),h.assign(t.equirectUV(p.xzy))});const g=t.dFdx(h).toConst(),y=t.dFdy(h).toConst(),f=t.dFdx(p).toConst(),v=t.dFdy(p).toConst(),S=t.vec4(0).toVar();return t.If(l.lessThan(u),()=>{if(this.displacementNode!=null){const w=this.displacementNode.sample(h.add(g)).x,R=this.displacementNode.sample(h.sub(g)).x,E=this.displacementNode.sample(h.add(y)).x,L=this.displacementNode.sample(h.sub(y)).x,F=w.sub(R).mul(.5),O=E.sub(L).mul(.5),I=v.cross(p).toConst(),k=p.cross(f).toConst(),W=f.dot(I).toConst(),le=I.mul(F).add(k.mul(O)).mul(W.sign()),P=p.mul(W.abs()).sub(le.mul(this.displacementScale)).normalize();p.assign(t.mix(p,P,m.dot(r.negate()).smoothstep(0,.3))),m.assign(o.mul(t.vec4(p,0)).xyz)}const b=this.colorNode?.sample(h).xyz??1,C=Rs(n,r.negate(),m),N=t.smoothstep(u,u.sub(d),l);S.assign(t.vec4(bs(i.parametersNode,this.angularRadius).mul(this.intensity).mul(b).mul(C),N))}),S})()}}const{resetRendererState:Es,restoreRendererState:Fs}=T.RendererUtils;function As(){const s=new T.RenderTarget(1,1,{depthBuffer:!1,type:x.HalfFloatType,format:x.RGBAFormat}),e=s.texture;return e.minFilter=x.LinearFilter,e.magFilter=x.LinearFilter,e.generateMipmaps=!1,e.name="Stars",s}const Vs=M({name:"log10",type:"float",inputs:[{name:"x",type:"float"}]})(([s])=>t.log(s).mul(1/Math.log(10))),Ls=A((s,e)=>{const i=s.add(Vs(e.mul(425e8)).mul(2.5)).toConst();return t.pow(10,i.mul(-.4)).mul(108e3)}),Ps=new x.Vector2;class Ds extends T.TempNode{constructor(e=Ii){super("vec3"),this.pointSize=t.uniform(1),this.intensity=t.uniform(1e3),this.magnitudeRange=t.uniform(new x.Vector2(-2,8)),this.material=new T.PointsNodeMaterial,this.points=new x.Sprite(this.material),this.updateBeforeType=T.NodeUpdateType.FRAME,this.material.name="Stars",this.data=e,this.renderTarget=As(),this.textureNode=ae(this,this.renderTarget.texture)}static get type(){return"StarsNode"}getTextureNode(){return this.textureNode}setSize(e,i){return this.renderTarget.setSize(e,i),this}updateBefore(e){const{renderer:i}=e,r=this.camera??e.camera;if(i==null||r==null)return;const n=i.getDrawingBufferSize(Ps);this.setSize(n.x,n.y),this.rendererState=Es(i,this.rendererState),this.points.position.copy(r.position),i.setRenderTarget(this.renderTarget),i.render(this.points,r),Fs(i,this.rendererState)}createBuffers(e){const i=e.byteLength/10,r=new Float32Array(i*3),n=new Float32Array(i),a=new Float32Array(i*3),o=new Int16Array(e),u=new Uint8Array(e);for(let c=0,l=0,d=0,h=0;c<i;++c,l+=3,d+=5,h+=10)r[l+0]=o[d+0]/32767,r[l+1]=o[d+1]/32767,r[l+2]=o[d+2]/32767,n[c]=u[h+6]/255,a[l+0]=u[h+7]/255,a[l+1]=u[h+8]/255,a[l+2]=u[h+9]/255;this.positionBuffer=new x.InstancedBufferAttribute(r,3),this.magnitudeBuffer=new x.InstancedBufferAttribute(n,1),this.colorBuffer=new x.InstancedBufferAttribute(a,3),this.points.count=i}setupMaterial(e){const i=$(e),r=i.camera??e.camera;if(r==null)return;const{material:n,positionBuffer:a,magnitudeBuffer:o,colorBuffer:u}=this;Q(a!=null),Q(o!=null),Q(u!=null);const c=t.instancedBufferAttribute(a,"vec3"),l=t.instancedBufferAttribute(o,"float"),d=t.instancedBufferAttribute(u,"vec3"),{matrixECIToECEF:h,matrixECEFToWorld:m,parametersNode:p}=i,{luminanceScale:g}=p,y=h.mul(t.vec4(c,0)).xyz,f=m.mul(t.vec4(y,0)).xyz;n.positionNode=f.mul(he(r).add(me(r)).mul(.5));const v=t.mix(this.magnitudeRange.x,this.magnitudeRange.y,l.x),S=this.pointSize.mul(2).div(t.screenSize.y.mul(Wt(r)[1][1])).pow2(),b=Ls(v,S);n.colorNode=b.mul(g).mul(d).mul(this.intensity).toVertexStage(),n.needsUpdate=!0}setup(e){typeof this.data=="string"?this.dataPromise??=new q.ArrayBufferLoader().loadAsync(this.data).then(n=>{this.createBuffers(n),this.setupMaterial(e)}).catch(n=>{console.error(n)}):(this.createBuffers(this.data),this.setupMaterial(e));const{material:i}=this;i.sizeNode=this.pointSize,i.sizeAttenuation=!1,i.depthTest=!1,i.depthWrite=!1,i.transparent=!0,i.blending=x.AdditiveBlending,i.needsUpdate=!0,this.points.frustumCulled=!1;const r=$(e);return this.camera=r.camera,this.textureNode.uvNode=t.screenUV,this.textureNode}dispose(){this.renderTarget.dispose(),this.material.dispose(),super.dispose()}}class Us extends T.TempNode{constructor(){super("vec4"),this.angularRadius=t.uniform(.004675),this.intensity=t.uniform(1)}static get type(){return"SunNode"}setup(e){const i=$(e),{rayDirectionECEF:r}=this;if(r==null)return;const{sunDirectionECEF:n}=i;return t.Fn(()=>{const a=t.cos(this.angularRadius).oneMinus().mul(2),o=r.sub(n),u=o.dot(o),c=t.fwidth(u),l=t.vec4(0).toVar();return t.If(u.lessThan(a),()=>{const d=t.smoothstep(a,a.sub(c),u);l.assign(t.vec4(Ss().mul(this.intensity),d))}),l})()}}const Is=s=>{const e=Ht(s).mul(t.vec4(t.positionGeometry,1)).xyz;return _t(s).mul(t.vec4(e,0)).xyz},He="CAMERA",It="EQUIRECTANGULAR";class Bt extends T.TempNode{constructor(e,i){super("vec3"),this.scope=He,this.showSun=!0,this.showMoon=!0,this.showStars=!0,this.moonScattering=!1,this.useContextCamera=!0,this.scope=e,this.shadowLengthNode=i,this.sunNode=new Us,this.moonNode=new zs,this.starsNode=new Ds}static get type(){return"SkyNode"}customCacheKey(){return _e.hash(+this.showSun,+this.showMoon,+this.showStars,+this.moonScattering,+this.useContextCamera)}setup(e){const i=$(e),{matrixWorldToECEF:r,sunDirectionECEF:n,moonDirectionECEF:a,cameraPositionUnit:o,altitudeCorrectionUnit:u}=i;let c;switch(this.scope){case He:{c=Is(this.useContextCamera?i.camera:null);break}case It:c=Ni(t.uv());break}if(c!=null)return t.Fn(()=>{const l=r.mul(t.vec4(c,0)).xyz.toVertexStage().normalize().toConst(),d=xt(o.add(u),l,this.shadowLengthNode??t.vec2(0),n).toConst(),h=d.get("transmittance");let m=d.get("luminance");if(this.moonScattering){const g=xt(o.add(u),l,this.shadowLengthNode??t.vec2(0),a);m=m.add(g.get("luminance").mul(25e-7))}const p=t.vec3(0).toVar();if(this.showStars&&p.addAssign(this.starsNode),this.showSun){const{sunNode:g}=this;g.rayDirectionECEF=l,p.assign(t.mix(p,g.rgb,g.a))}if(this.showMoon){const{moonNode:g}=this;g.rayDirectionECEF=l,p.assign(t.mix(p,g.rgb,g.a))}return p.mul(h).add(m)})()}}const Bs=t.nodeProxy(Bt,He),Os=t.nodeProxy(Bt,It);class yt extends x.DirectionalLight{constructor(e=1,i="sun"){super(),this.type="AtmosphereLight",this.direct=t.uniform(!0),this.indirect=t.uniform(!0),this.distance=e,this.body=i}}const qs=new x.Matrix3;class ks extends T.AnalyticLightNode{constructor(e){super(e),this.intensity=t.uniform(1),this.directionECEF=t.uniform("vec3"),this.updateBeforeType=T.NodeUpdateType.FRAME}static get type(){return"AtmosphereLightNode"}updateBefore(e){const{light:i,atmosphereContext:r}=this;if(i==null||r==null)return;const{matrixECEFToWorld:n}=r;i.position.copy(this.directionECEF.value).applyMatrix3(qs.setFromMatrix4(n.value)).multiplyScalar(i.distance).add(i.target.position)}update(e){super.update(e);const{light:i,atmosphereContext:r}=this;if(!(i==null||r==null))switch(i.body){case"sun":this.intensity.value=i.intensity,this.directionECEF.value.copy(r.sunDirectionECEF.value);break;case"moon":this.intensity.value=i.intensity*25e-7,this.directionECEF.value.copy(r.moonDirectionECEF.value);break}}setup(e){return this.atmosphereContext=$(e),super.setup(e)}setupDirect(e){const{light:i,atmosphereContext:r}=this;if(i==null||r==null)return;const{intensity:n,directionECEF:a}=this,{direct:o,indirect:u}=i,{worldToUnit:c,solarIrradiance:l,sunRadianceToLuminance:d,luminanceScale:h}=r.parametersNode,{matrixWorldToECEF:m,matrixECEFToWorld:p,altitudeCorrectionECEF:g}=r,y=m.mul(t.vec4(t.normalWorld,0)).xyz;let f=m.mul(t.vec4(t.positionWorld,1)).xyz;r.correctAltitude&&(f=f.add(g));const v=f.mul(c).toConst(),S=Ns(v,y,a).mul(u.select(1,0));e.context.irradiance.addAssign(S.mul(n));const b=p.mul(t.vec4(a,0)).xyz,C=t.cameraViewMatrix.mul(t.vec4(b,0)).xyz,N=v.length().toConst(),w=v.dot(a).div(N),R=we(r.lutNode.getTextureNode("transmittance"),N,w),E=l.mul(R).mul(d.mul(h)).mul(n).mul(o.select(1,0));return{lightDirection:C,lightColor:E.mul(this.colorNode)}}}const{resetRendererState:ar,restoreRendererState:or}=T.RendererUtils,{resetRendererState:ur,restoreRendererState:cr}=T.RendererUtils,{resetRendererState:lr,restoreRendererState:dr}=T.RendererUtils,{resetRendererState:hr,restoreRendererState:mr}=T.RendererUtils,{resetRendererState:pr,restoreRendererState:gr}=T.RendererUtils,{resetRendererState:xr,restoreRendererState:yr}=T.RendererUtils;class Gs extends T.TempNode{constructor(e=64){super("vec3"),this.distanceThreshold=1e3,this.angularThreshold=q.radians(.1),this.material=new T.NodeMaterial,this.mesh=new x.Mesh(new q.QuadGeometry,this.material),this.updateBeforeType=T.NodeUpdateType.FRAME,this.material.name="SkyEnvironment",this.skyNode=Bs(),this.skyNode.showSun=!1,this.skyNode.showMoon=!1,this.skyNode.showStars=!1,this.skyNode.useContextCamera=!1,this.renderTarget=new x.WebGLCubeRenderTarget(e,{depthBuffer:!1,type:x.HalfFloatType,format:x.RGBAFormat}),this.cubeCamera=new x.CubeCamera(.1,1e3,this.renderTarget)}static get type(){return"SkyEnvironmentNode"}updateBefore({renderer:e}){e==null||this.version===this.currentVersion||(this.currentVersion=this.version,this.cubeCamera.update(e,this.mesh))}setup(e){const i=$(e),{camera:r}=i;if(r!=null){const u=new x.Vector3,c=new x.Vector3;Re(()=>{u.copy(r.position).divideScalar(this.distanceThreshold).round(),c.equals(u)||(c.copy(u),this.needsUpdate=!0)})}const n=i.sunDirectionECEF.value.clone();Re(()=>{const{value:u}=i.sunDirectionECEF;n.angleTo(u)>this.angularThreshold&&(n.copy(u),this.needsUpdate=!0)});const a=i.moonDirectionECEF.value.clone();Re(()=>{const{value:u}=i.moonDirectionECEF;a.angleTo(u)>this.angularThreshold&&(a.copy(u),this.needsUpdate=!0)});const o=()=>{this.needsUpdate=!0};return i.lutNode.addEventListener("update",o),this.removeLUTUpdateListener?.(),this.removeLUTUpdateListener=()=>{i.lutNode.removeEventListener("update",o)},this.material.vertexNode=t.vec4(t.positionGeometry.xy,0,1),this.material.fragmentNode=this.skyNode,t.pmremTexture(this.renderTarget.texture)}dispose(){this.removeLUTUpdateListener?.(),this.renderTarget.dispose(),this.skyNode.dispose(),this.material.dispose(),this.mesh.geometry.dispose(),super.dispose()}}const $s=(...s)=>new Gs(...s),js=t.mat3(t.vec3(1.6605,-.1246,-.0182),t.vec3(-.5876,1.1329,-.1006),t.vec3(-.0728,-.0083,1.1187)),Ws=t.mat3(t.vec3(.6274,.0691,.0164),t.vec3(.3293,.9195,.088),t.vec3(.0433,.0113,.8956)),Hs=A(s=>{const e=s.pow2().toConst(),i=e.pow2().toConst();return t.add(i.mul(e).mul(15.5),i.mul(s).mul(-40.14),i.mul(31.96),e.mul(s).mul(-6.868),e.mul(.4298),s.mul(.1191),-.00232)}),_s=t.mat3(t.vec3(.856627153315983,.137318972929847,.11189821299995),t.vec3(.0951212405381588,.761241990602591,.0767994186031903),t.vec3(.0482516061458583,.101439036467562,.811302368396859)),Qs=t.mat3(t.vec3(1.1271005818144368,-.1413297634984383,-.14132976349843826),t.vec3(-.11060664309660323,1.157823702216272,-.11060664309660294),t.vec3(-.016493938717834573,-.016493938717834257,1.2519364065950405)),ft=-12.47393,Zs=4.026069,Ks=M({name:"agx",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]})(([s,e])=>{const i=s.toVar(),r=e;return i.mulAssign(r),i.assign(Ws.mul(i)),i.assign(_s.mul(i)),i.assign(t.log2(i.max(1e-10))),i.assign(i.sub(ft).div(t.float(Zs).sub(ft))),i.assign(i.saturate()),i.assign(Hs(i)),i}),Js=M({name:"agxEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]})(([s])=>{const e=s.toVar();return e.assign(Qs.mul(e)),e.assign(t.pow(e.max(0),t.float(2.2))),e.assign(js.mul(e)),e.assign(e.saturate()),e}),Xs=M({name:"agxPunchyToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]})(([s,e])=>{const i=s.toVar(),r=e;return i.assign(Ks(i,r.mul(1.5))),i.assign(t.cdl(i,t.vec3(1),t.vec3(0),t.vec3(1.35),t.float(1.2))),i.assign(Js(i)),i}),Ot=100;function $e(){const s=new Date;return s.setHours(8,0,0,0),s}const Ys={longitude:0,latitude:0,height:0,date:0,showSun:!0,showMoon:!0,showStars:!0,showGround:!1,useSkyEnvironment:!0,raymarchScattering:!0,lighting:!0,transmittance:!0,inscattering:!0,moonScattering:!0,lensFlare:!0,temporalAntialias:!0,dithering:!0,toneMapping:Ot,toneMappingExposure:3,castShadow:!0,shadowMapSize:4096,shadowCameraSize:180,shadowCameraNear:10,shadowCameraFar:6e3,shadowBias:-2e-5,shadowNormalBias:.001,shadowRadius:1.5,shadowDistance:3e3};class er{viewer;#r=!1;#e={...Ys,date:$e()};#h=null;#i=null;#t=null;#s=null;#n=null;#u=null;#c=null;#a=[];#l=null;#g;#m;#x=!1;#d=!1;#y=new T.Matrix4;#p=new T.Vector3;constructor(e){this.viewer=e}get enabled(){return this.#r}get context(){return this.#i}get light(){return this.#t}enable(e={}){return this.#r?this.update(e):(this.#e=this.#f(e),this.#h=new ge,this.#i=new Ut(this.#h),this.#i.camera=this.viewer.camera,this.#v(),this.#A(),this.#V(),this.#L(),this.#P(),this.#D(),this.#I(),this.#O(),this.updateDate(this.#e.date),this.#N(),this.#r=!0,this.viewer.render(),this)}update(e={}){return this.#e=this.#f(e),this.#i?(this.#v(),this.#S(),this.#C(),this.#T(),this.#b(),this.#U(),this.updateDate(this.#e.date),this.#N(),this.viewer.render(),this):this}setLocation(e,i,r=this.#e.height){return this.update({longitude:e,latitude:i,height:r})}setDate(e){return this.updateDate(e)}updateDate(e=$e()){return this.#e.date=e,this.#z(),this.viewer.render(),this}disable(){return this.#r?(this.#B(),this.#q(),this.viewer.renderPipeline.removeOutputEffect(this.#o),this.#M(),this.#o.includesTemporalAntialias=!1,this.viewer.renderPipeline.needsUpdate=!0,this.#R(),this.#t&&(this.#t.target.removeFromParent(),this.#t.removeFromParent(),this.#t.dispose(),this.#t=null),this.viewer.scene.backgroundNode=this.#g,this.viewer.scene.environmentNode=this.#m,this.#l&&(this.viewer.renderer.contextNode=this.#l,this.#l=null),this.viewer.renderer.highPrecision=this.#x,this.#i?.dispose(),this.#i=null,this.#h=null,this.#s=null,this.#n=null,this.#r=!1,this.viewer.render(),this):this}dispose(){return this.disable()}#f(e){return{...this.#e,...e,date:e.date??(this.#r?this.#e.date:$e())}}#v(){if(!this.#i)return;const i=new q.Geodetic(q.radians(this.#e.longitude),q.radians(this.#e.latitude),this.#e.height).toECEF(new T.Vector3);q.Ellipsoid.WGS84.getNorthUpEastFrame(i,this.#y),this.#i.camera=this.viewer.camera,this.#i.showGround=this.#e.showGround,this.#i.raymarchScattering=this.#e.raymarchScattering,this.#i.matrixWorldToECEF.value.copy(this.#y)}#A(){if(!this.#i)return;const e=this.viewer.renderer;this.#l=e.contextNode,this.#x=e.highPrecision,e.highPrecision=!0,e.contextNode=t.context({...e.contextNode.value,getAtmosphere:()=>this.#i})}#V(){const e=this.viewer.renderer;e.library.addLight(ks,yt),e.shadowMap.enabled=!0,this.#t=new yt,this.#T(),this.viewer.scene.add(this.#t.target),this.#w(),this.viewer.scene.add(this.#t)}#T(){if(!this.#t)return;const{castShadow:e,shadowMapSize:i,shadowCameraSize:r,shadowCameraNear:n,shadowCameraFar:a,shadowBias:o,shadowNormalBias:u,shadowRadius:c,shadowDistance:l}=this.#e,d=r/2,h=this.#t.shadow.camera;this.#t.castShadow=e,this.#t.distance=l,this.#t.shadow.mapSize.setScalar(i),this.#t.shadow.bias=o,this.#t.shadow.normalBias=u,this.#t.shadow.radius=c,h.left=-d,h.right=d,h.top=d,h.bottom=-d,h.near=n,h.far=a,h.updateProjectionMatrix(),this.#t.shadow.needsUpdate=!0}#w(){this.#t&&(this.viewer.controls.getTarget(this.#t.target.position),this.#t.target.updateMatrixWorld())}#L(){this.#g=this.viewer.scene.backgroundNode,this.#m=this.viewer.scene.environmentNode,this.#s=Os(),this.#C(),this.#S(),this.viewer.scene.backgroundNode=this.#s}#S(){this.#s&&(this.#s.showSun=this.#e.showSun,this.#s.showMoon=this.#e.showMoon,this.#s.showStars=this.#e.showStars,this.#s.moonScattering=this.#e.moonScattering)}#C(){if(!this.#e.useSkyEnvironment){this.#n&&this.viewer.scene.environmentNode===this.#n&&(this.viewer.scene.environmentNode=this.#m),this.#n=null;return}this.#n??=$s(),this.viewer.scene.environmentNode=this.#n}#N(){for(const e of[this.#s,this.#n])e&&(e.needsUpdate=!0);this.viewer.renderPipeline.needsUpdateOutputNode=!0}#P(){this.viewer.renderer.library.addToneMapping(Xs,Ot)}#D(){this.#o.includesOutputTransform=!0,this.#b(),this.viewer.renderPipeline.addOutputEffect(this.#o)}#b(){if(this.#o.includesTemporalAntialias=this.#e.temporalAntialias,this.#e.temporalAntialias){this.#d||(this.viewer.renderPipeline.addMRTChannel("atmosphereVelocity",je),this.#d=!0);return}this.#M()}#M(){this.#d&&(this.viewer.renderPipeline.removeMRTChannel("atmosphereVelocity"),this.#d=!1)}#U(){this.#r&&(this.viewer.renderPipeline.needsUpdateOutputNode=!0)}#R(){for(const e of this.#a)e.dispose();this.#a=[],this.#u=null,this.#c=null}#o=(e,i)=>{const r=e.getTextureNode("depth");this.#R();let n=i;if(this.#e.lensFlare&&(this.#u=Ti(n),this.#a.push(this.#u),n=this.#u),this.#e.toneMapping!==!1&&this.#e.toneMapping!==T.NoToneMapping){const o=t.toneMapping(this.#e.toneMapping,this.#e.toneMappingExposure,n);this.#a.push(o),n=o}if(this.#e.temporalAntialias){const o=e.getTextureNode("atmosphereVelocity");this.#c=Di(n,r,o,this.viewer.camera),this.#a.push(this.#c),n=this.#c}if(this.#e.dithering){const o=t.add(n,ci);this.#a.push(o),n=o}const a=t.renderOutput(n,T.NoToneMapping);return this.#a.push(a),a};#z(){if(!this.#i)return;this.viewer.camera.updateMatrixWorld(),this.#p.setFromMatrixPosition(this.viewer.camera.matrixWorld).applyMatrix4(this.#i.matrixWorldToECEF.value);const e=this.#i.matrixECIToECEF.value;be.getECIToECEFRotationMatrix(this.#e.date,e),be.getSunDirectionECI(this.#e.date,this.#i.sunDirectionECEF.value,this.#p).applyMatrix4(e),be.getMoonDirectionECI(this.#e.date,this.#i.moonDirectionECEF.value,this.#p).applyMatrix4(e)}#I(){this.viewer.addEventListener("cameraChange",this.#E)}#B(){this.viewer.removeEventListener("cameraChange",this.#E)}#O(){this.viewer.addEventListener("beforeRender",this.#F)}#q(){this.viewer.removeEventListener("beforeRender",this.#F)}#E=({camera:e})=>{this.#i&&(this.#i.camera=e,this.updateDate(this.#e.date))};#F=()=>{this.#w(),this.#z()}}exports.Atmosphere=er;
|