@takram/three-clouds 0.3.0 → 0.4.0

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/build/shared.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";const C=require("postprocessing"),n=require("three"),H=require("@takram/three-atmosphere"),h=require("@takram/three-geospatial"),b=require("@takram/three-atmosphere/shaders"),y=require("@takram/three-geospatial/shaders");class I{constructor(e=0,t=0,a=0,i=0){this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=i}set(e=0,t=0,a=0,i=0){return this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=i,this}clone(){return new I(this.expTerm,this.exponent,this.linearTerm,this.constantTerm)}copy(e){return this.expTerm=e.expTerm,this.exponent=e.exponent,this.linearTerm=e.linearTerm,this.constantTerm=e.constantTerm,this}}const me=["channel","altitude","height","densityScale","shapeAmount","shapeDetailAmount","weatherExponent","shapeAlteringBias","coverageFilterWidth","shadow","densityProfile"];function ve(o,e){if(e!=null)for(const t of me){const a=e[t];a!=null&&(o[t]instanceof I?o[t].copy(a):o[t]=a)}}const R=class R{constructor(e){this.channel="r",this.altitude=0,this.height=0,this.densityScale=.2,this.shapeAmount=1,this.shapeDetailAmount=1,this.weatherExponent=1,this.shapeAlteringBias=.35,this.coverageFilterWidth=.6,this.densityProfile=new I(0,0,.75,.25),this.shadow=!1,this.set(e)}set(e){return ve(this,e),this}clone(){return new R(this)}copy(e){return this.channel=e.channel,this.altitude=e.altitude,this.height=e.height,this.densityScale=e.densityScale,this.shapeAmount=e.shapeAmount,this.shapeDetailAmount=e.shapeDetailAmount,this.weatherExponent=e.weatherExponent,this.shapeAlteringBias=e.shapeAlteringBias,this.coverageFilterWidth=e.coverageFilterWidth,this.densityProfile.copy(e.densityProfile),this.shadow=e.shadow,this}};R.DEFAULT=new R;let x=R;const A=Array.from({length:8},()=>({value:0,flag:0})),P=Array.from({length:3},()=>({min:0,max:0}));function ge(o,e){return o.value!==e.value?o.value-e.value:o.flag-e.flag}const U=class U extends Array{constructor(e){super(new x(e==null?void 0:e[0]),new x(e==null?void 0:e[1]),new x(e==null?void 0:e[2]),new x(e==null?void 0:e[3]))}set(e){return this[0].set(e==null?void 0:e[0]),this[1].set(e==null?void 0:e[1]),this[2].set(e==null?void 0:e[2]),this[3].set(e==null?void 0:e[3]),this}reset(){return this[0].copy(x.DEFAULT),this[1].copy(x.DEFAULT),this[2].copy(x.DEFAULT),this[3].copy(x.DEFAULT),this}clone(){return new U(this)}copy(e){return this[0].copy(e[0]),this[1].copy(e[1]),this[2].copy(e[2]),this[3].copy(e[3]),this}get localWeatherChannels(){return this[0].channel+this[1].channel+this[2].channel+this[3].channel}packValues(e,t){return t.set(this[0][e],this[1][e],this[2][e],this[3][e])}packSums(e,t,a){return a.set(this[0][e]+this[0][t],this[1][e]+this[1][t],this[2][e]+this[2][t],this[3][e]+this[3][t])}packDensityProfiles(e,t){return t.set(this[0].densityProfile[e],this[1].densityProfile[e],this[2].densityProfile[e],this[3].densityProfile[e])}packIntervalHeights(e,t){for(let s=0;s<4;++s){const l=this[s];let u=A[s];u.value=l.altitude,u.flag=0,u=A[s+4],u.value=l.altitude+l.height,u.flag=1}A.sort(ge);let a=0,i=0;for(let s=0;s<A.length;++s){const{value:l,flag:u}=A[s];if(i===0&&s>0){const d=P[a++];d.min=A[s-1].value,d.max=l}i+=u===0?1:-1}for(;a<3;++a){const s=P[a];s.min=0,s.max=0}let r=P[0];e.x=r.min,t.x=r.max,r=P[1],e.y=r.min,t.y=r.max,r=P[2],e.z=r.min,t.z=r.max}};U.DEFAULT=new U([{channel:"r",altitude:750,height:650,densityScale:.2,shapeAmount:1,shapeDetailAmount:1,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.6,shadow:!0},{channel:"g",altitude:1e3,height:1200,densityScale:.2,shapeAmount:1,shapeDetailAmount:1,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.6,shadow:!0},{channel:"b",altitude:7500,height:500,densityScale:.003,shapeAmount:.4,shapeDetailAmount:0,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.5},{channel:"a"}]);let F=U;var Se=process.env.NODE_ENV==="production",J="Invariant failed";function D(o,e){if(!o){if(Se)throw new Error(J);var t=J;throw new Error(t)}}class L{constructor(e,t){this.near=[new n.Vector3,new n.Vector3,new n.Vector3,new n.Vector3],this.far=[new n.Vector3,new n.Vector3,new n.Vector3,new n.Vector3],e!=null&&t!=null&&this.setFromCamera(e,t)}clone(){return new L().copy(this)}copy(e){for(let t=0;t<4;++t)this.near[t].copy(e.near[t]),this.far[t].copy(e.far[t]);return this}setFromCamera(e,t){const a=e.isOrthographicCamera===!0,i=e.projectionMatrixInverse;this.near[0].set(1,1,-1),this.near[1].set(1,-1,-1),this.near[2].set(-1,-1,-1),this.near[3].set(-1,1,-1);for(let r=0;r<4;++r)this.near[r].applyMatrix4(i);this.far[0].set(1,1,1),this.far[1].set(1,-1,1),this.far[2].set(-1,-1,1),this.far[3].set(-1,1,1);for(let r=0;r<4;++r){const s=this.far[r];s.applyMatrix4(i);const l=Math.abs(s.z);a?s.z*=Math.min(t/l,1):s.multiplyScalar(Math.min(t/l,1))}return this}split(e,t=[]){for(let a=0;a<e.length;++a){const i=t[a]??(t[a]=new L);if(a===0)for(let r=0;r<4;++r)i.near[r].copy(this.near[r]);else for(let r=0;r<4;++r)i.near[r].lerpVectors(this.near[r],this.far[r],e[a-1]);if(a===e.length-1)for(let r=0;r<4;++r)i.far[r].copy(this.far[r]);else for(let r=0;r<4;++r)i.far[r].lerpVectors(this.near[r],this.far[r],e[a])}return t.length=e.length,t}applyMatrix4(e){for(let t=0;t<4;++t)this.near[t].applyMatrix4(e),this.far[t].applyMatrix4(e);return this}}const ye={uniform:(o,e,t,a,i=[])=>{for(let r=0;r<o;++r)i[r]=(e+(t-e)*(r+1)/o)/t;return i.length=o,i},logarithmic:(o,e,t,a,i=[])=>{for(let r=0;r<o;++r)i[r]=e*(t/e)**((r+1)/o)/t;return i.length=o,i},practical:(o,e,t,a=.5,i=[])=>{for(let r=0;r<o;++r){const s=(e+(t-e)*(r+1)/o)/t,l=e*(t/e)**((r+1)/o)/t;i[r]=h.lerp(s,l,a)}return i.length=o,i}};function xe(o,e,t,a,i,r=[]){return ye[o](e,t,a,i,r)}const Q=new n.Vector3,ee=new n.Vector3,we=new n.Matrix4,te=new n.Matrix4,Ce=new L,Te=new n.Box3,De={maxFar:null,farScale:1,splitMode:"practical",splitLambda:.5,margin:0,fade:!0};class Ee{constructor(e){this.cascades=[],this.mapSize=new n.Vector2,this.cameraFrustum=new L,this.frusta=[],this.splits=[],this._far=0;const{cascadeCount:t,mapSize:a,maxFar:i,farScale:r,splitMode:s,splitLambda:l,margin:u,fade:d}={...De,...e};this.cascadeCount=t,this.mapSize.copy(a),this.maxFar=i,this.farScale=r,this.splitMode=s,this.splitLambda=l,this.margin=u,this.fade=d}get cascadeCount(){return this.cascades.length}set cascadeCount(e){var t;if(e!==this.cascadeCount){for(let a=0;a<e;++a)(t=this.cascades)[a]??(t[a]={interval:new n.Vector2,matrix:new n.Matrix4,inverseMatrix:new n.Matrix4,projectionMatrix:new n.Matrix4,inverseProjectionMatrix:new n.Matrix4,viewMatrix:new n.Matrix4,inverseViewMatrix:new n.Matrix4});this.cascades.length=e}}get far(){return this._far}updateIntervals(e){const t=this.cascadeCount,a=this.splits,i=this.far;xe(this.splitMode,t,e.near,i,this.splitLambda,a),this.cameraFrustum.setFromCamera(e,i),this.cameraFrustum.split(a,this.frusta);const r=this.cascades;for(let s=0;s<t;++s)r[s].interval.set(a[s-1]??0,a[s]??0)}getFrustumRadius(e,t){const a=t.near,i=t.far;let r=Math.max(i[0].distanceTo(i[2]),i[0].distanceTo(a[2]));if(this.fade){const s=e.near,l=this.far,u=i[0].z/(l-s);r+=.25*u**2*(l-s)}return r*.5}updateMatrices(e,t,a=1){const i=we.lookAt(Q.setScalar(0),ee.copy(t).multiplyScalar(-1),n.Object3D.DEFAULT_UP),r=te.multiplyMatrices(te.copy(i).invert(),e.matrixWorld),s=this.frusta,l=this.cascades;D(s.length===l.length);const u=this.margin,d=this.mapSize;for(let p=0;p<s.length;++p){const f=s[p],m=l[p],v=this.getFrustumRadius(e,s[p]),j=-v,Y=v,q=v,Z=-v;m.projectionMatrix.makeOrthographic(j,Y,q,Z,-this.margin,v*2+this.margin);const{near:pe,far:fe}=Ce.copy(f).applyMatrix4(r),N=Te.makeEmpty();for(let M=0;M<4;M++)N.expandByPoint(pe[M]),N.expandByPoint(fe[M]);const T=N.getCenter(Q);T.z=N.max.z+u;const K=(Y-j)/d.width,X=(q-Z)/d.height;T.x=Math.round(T.x/K)*K,T.y=Math.round(T.y/X)*X,T.applyMatrix4(i);const $=ee.copy(t).multiplyScalar(a).add(T);m.inverseViewMatrix.lookAt(T,$,n.Object3D.DEFAULT_UP).setPosition($)}}update(e,t,a){this._far=this.maxFar!=null?Math.min(this.maxFar,e.far*this.farScale):e.far*this.farScale,this.updateIntervals(e),this.updateMatrices(e,t,a);const i=this.cascades,r=this.cascadeCount;for(let s=0;s<r;++s){const{matrix:l,inverseMatrix:u,projectionMatrix:d,inverseProjectionMatrix:p,viewMatrix:f,inverseViewMatrix:m}=i[s];p.copy(d).invert(),f.copy(m).invert(),l.copy(d).multiply(f),u.copy(m).multiply(p)}}}const ne=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5],ie=ne.reduce((o,e,t)=>{const a=new n.Vector2;for(let i=0;i<16;++i)if(ne[i]===t){a.set((i%4+.5)/4,(Math.floor(i/4)+.5)/4);break}return[...o,a]},[]),Ae={resolutionScale:1,lightShafts:!0,shapeDetail:!0,turbulence:!0,haze:!0,clouds:{multiScatteringOctaves:8,accurateSunSkyIrradiance:!0,accuratePhaseFunction:!1,maxIterationCount:500,minStepSize:50,maxStepSize:1e3,maxRayDistance:2e5,perspectiveStepScale:1.01,minDensity:1e-5,minExtinction:1e-5,minTransmittance:.01,maxIterationCountToGround:3,maxIterationCountToSun:2,minSecondaryStepSize:100,secondaryStepScale:2,maxShadowLengthIterationCount:500,minShadowLengthStepSize:50,maxShadowLengthRayDistance:2e5},shadow:{cascadeCount:3,mapSize:new n.Vector2(512,512),maxIterationCount:50,minStepSize:100,maxStepSize:1e3,minDensity:1e-5,minExtinction:1e-5,minTransmittance:1e-4}},c=Ae,_e={low:{...c,lightShafts:!1,shapeDetail:!1,turbulence:!1,clouds:{...c.clouds,accurateSunSkyIrradiance:!1,maxIterationCount:200,minStepSize:100,maxRayDistance:1e5,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.1,maxIterationCountToGround:0,maxIterationCountToSun:1},shadow:{...c.shadow,maxIterationCount:25,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.01,cascadeCount:2,mapSize:new n.Vector2(256,256)}},medium:{...c,lightShafts:!1,turbulence:!1,clouds:{...c.clouds,minDensity:1e-4,minExtinction:1e-4,accurateSunSkyIrradiance:!1,maxIterationCountToSun:2,maxIterationCountToGround:1},shadow:{...c.shadow,minDensity:1e-4,minExtinction:1e-4,mapSize:new n.Vector2(256,256)}},high:c,ultra:{...c,clouds:{...c.clouds,minStepSize:10},shadow:{...c.shadow,mapSize:new n.Vector2(1024,1024)}}},Pe=`precision highp float;
1
+ "use strict";const C=require("postprocessing"),n=require("three"),H=require("@takram/three-atmosphere"),u=require("@takram/three-geospatial"),A=require("@takram/three-atmosphere/shaders/bruneton"),y=require("@takram/three-geospatial/shaders");class M{constructor(e=0,t=0,a=0,i=0){this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=i}set(e=0,t=0,a=0,i=0){return this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=i,this}clone(){return new M(this.expTerm,this.exponent,this.linearTerm,this.constantTerm)}copy(e){return this.expTerm=e.expTerm,this.exponent=e.exponent,this.linearTerm=e.linearTerm,this.constantTerm=e.constantTerm,this}}const me=["channel","altitude","height","densityScale","shapeAmount","shapeDetailAmount","weatherExponent","shapeAlteringBias","coverageFilterWidth","shadow","densityProfile"];function ve(o,e){if(e!=null)for(const t of me){const a=e[t];a!=null&&(o[t]instanceof M?o[t].copy(a):o[t]=a)}}const U=class U{constructor(e){this.channel="r",this.altitude=0,this.height=0,this.densityScale=.2,this.shapeAmount=1,this.shapeDetailAmount=1,this.weatherExponent=1,this.shapeAlteringBias=.35,this.coverageFilterWidth=.6,this.densityProfile=new M(0,0,.75,.25),this.shadow=!1,this.set(e)}set(e){return ve(this,e),this}clone(){return new U(this)}copy(e){return this.channel=e.channel,this.altitude=e.altitude,this.height=e.height,this.densityScale=e.densityScale,this.shapeAmount=e.shapeAmount,this.shapeDetailAmount=e.shapeDetailAmount,this.weatherExponent=e.weatherExponent,this.shapeAlteringBias=e.shapeAlteringBias,this.coverageFilterWidth=e.coverageFilterWidth,this.densityProfile.copy(e.densityProfile),this.shadow=e.shadow,this}};U.DEFAULT=new U;let x=U;const _=Array.from({length:8},()=>({value:0,flag:0})),P=Array.from({length:3},()=>({min:0,max:0}));function ge(o,e){return o.value!==e.value?o.value-e.value:o.flag-e.flag}const R=class R extends Array{constructor(e){super(new x(e==null?void 0:e[0]),new x(e==null?void 0:e[1]),new x(e==null?void 0:e[2]),new x(e==null?void 0:e[3]))}set(e){return this[0].set(e==null?void 0:e[0]),this[1].set(e==null?void 0:e[1]),this[2].set(e==null?void 0:e[2]),this[3].set(e==null?void 0:e[3]),this}reset(){return this[0].copy(x.DEFAULT),this[1].copy(x.DEFAULT),this[2].copy(x.DEFAULT),this[3].copy(x.DEFAULT),this}clone(){return new R(this)}copy(e){return this[0].copy(e[0]),this[1].copy(e[1]),this[2].copy(e[2]),this[3].copy(e[3]),this}get localWeatherChannels(){return this[0].channel+this[1].channel+this[2].channel+this[3].channel}packValues(e,t){return t.set(this[0][e],this[1][e],this[2][e],this[3][e])}packSums(e,t,a){return a.set(this[0][e]+this[0][t],this[1][e]+this[1][t],this[2][e]+this[2][t],this[3][e]+this[3][t])}packDensityProfiles(e,t){return t.set(this[0].densityProfile[e],this[1].densityProfile[e],this[2].densityProfile[e],this[3].densityProfile[e])}packIntervalHeights(e,t){for(let s=0;s<4;++s){const l=this[s];let h=_[s];h.value=l.altitude,h.flag=0,h=_[s+4],h.value=l.altitude+l.height,h.flag=1}_.sort(ge);let a=0,i=0;for(let s=0;s<_.length;++s){const{value:l,flag:h}=_[s];if(i===0&&s>0){const d=P[a++];d.min=_[s-1].value,d.max=l}i+=h===0?1:-1}for(;a<3;++a){const s=P[a];s.min=0,s.max=0}let r=P[0];e.x=r.min,t.x=r.max,r=P[1],e.y=r.min,t.y=r.max,r=P[2],e.z=r.min,t.z=r.max}};R.DEFAULT=new R([{channel:"r",altitude:750,height:650,densityScale:.2,shapeAmount:1,shapeDetailAmount:1,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.6,shadow:!0},{channel:"g",altitude:1e3,height:1200,densityScale:.2,shapeAmount:1,shapeDetailAmount:1,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.6,shadow:!0},{channel:"b",altitude:7500,height:500,densityScale:.003,shapeAmount:.4,shapeDetailAmount:0,weatherExponent:1,shapeAlteringBias:.35,coverageFilterWidth:.5},{channel:"a"}]);let F=R;var Se=process.env.NODE_ENV==="production",J="Invariant failed";function D(o,e){if(!o){if(Se)throw new Error(J);var t=J;throw new Error(t)}}class I{constructor(e,t){this.near=[new n.Vector3,new n.Vector3,new n.Vector3,new n.Vector3],this.far=[new n.Vector3,new n.Vector3,new n.Vector3,new n.Vector3],e!=null&&t!=null&&this.setFromCamera(e,t)}clone(){return new I().copy(this)}copy(e){for(let t=0;t<4;++t)this.near[t].copy(e.near[t]),this.far[t].copy(e.far[t]);return this}setFromCamera(e,t){const a=e.isOrthographicCamera===!0,i=e.projectionMatrixInverse;this.near[0].set(1,1,-1),this.near[1].set(1,-1,-1),this.near[2].set(-1,-1,-1),this.near[3].set(-1,1,-1);for(let r=0;r<4;++r)this.near[r].applyMatrix4(i);this.far[0].set(1,1,1),this.far[1].set(1,-1,1),this.far[2].set(-1,-1,1),this.far[3].set(-1,1,1);for(let r=0;r<4;++r){const s=this.far[r];s.applyMatrix4(i);const l=Math.abs(s.z);a?s.z*=Math.min(t/l,1):s.multiplyScalar(Math.min(t/l,1))}return this}split(e,t=[]){for(let a=0;a<e.length;++a){const i=t[a]??(t[a]=new I);if(a===0)for(let r=0;r<4;++r)i.near[r].copy(this.near[r]);else for(let r=0;r<4;++r)i.near[r].lerpVectors(this.near[r],this.far[r],e[a-1]);if(a===e.length-1)for(let r=0;r<4;++r)i.far[r].copy(this.far[r]);else for(let r=0;r<4;++r)i.far[r].lerpVectors(this.near[r],this.far[r],e[a])}return t.length=e.length,t}applyMatrix4(e){for(let t=0;t<4;++t)this.near[t].applyMatrix4(e),this.far[t].applyMatrix4(e);return this}}const ye={uniform:(o,e,t,a,i=[])=>{for(let r=0;r<o;++r)i[r]=(e+(t-e)*(r+1)/o)/t;return i.length=o,i},logarithmic:(o,e,t,a,i=[])=>{for(let r=0;r<o;++r)i[r]=e*(t/e)**((r+1)/o)/t;return i.length=o,i},practical:(o,e,t,a=.5,i=[])=>{for(let r=0;r<o;++r){const s=(e+(t-e)*(r+1)/o)/t,l=e*(t/e)**((r+1)/o)/t;i[r]=u.lerp(s,l,a)}return i.length=o,i}};function xe(o,e,t,a,i,r=[]){return ye[o](e,t,a,i,r)}const Q=new n.Vector3,ee=new n.Vector3,we=new n.Matrix4,te=new n.Matrix4,Ce=new I,Te=new n.Box3,De={maxFar:null,farScale:1,splitMode:"practical",splitLambda:.5,margin:0,fade:!0};class Ee{constructor(e){this.cascades=[],this.mapSize=new n.Vector2,this.cameraFrustum=new I,this.frusta=[],this.splits=[],this._far=0;const{cascadeCount:t,mapSize:a,maxFar:i,farScale:r,splitMode:s,splitLambda:l,margin:h,fade:d}={...De,...e};this.cascadeCount=t,this.mapSize.copy(a),this.maxFar=i,this.farScale=r,this.splitMode=s,this.splitLambda=l,this.margin=h,this.fade=d}get cascadeCount(){return this.cascades.length}set cascadeCount(e){var t;if(e!==this.cascadeCount){for(let a=0;a<e;++a)(t=this.cascades)[a]??(t[a]={interval:new n.Vector2,matrix:new n.Matrix4,inverseMatrix:new n.Matrix4,projectionMatrix:new n.Matrix4,inverseProjectionMatrix:new n.Matrix4,viewMatrix:new n.Matrix4,inverseViewMatrix:new n.Matrix4});this.cascades.length=e}}get far(){return this._far}updateIntervals(e){const t=this.cascadeCount,a=this.splits,i=this.far;xe(this.splitMode,t,e.near,i,this.splitLambda,a),this.cameraFrustum.setFromCamera(e,i),this.cameraFrustum.split(a,this.frusta);const r=this.cascades;for(let s=0;s<t;++s)r[s].interval.set(a[s-1]??0,a[s]??0)}getFrustumRadius(e,t){const a=t.near,i=t.far;let r=Math.max(i[0].distanceTo(i[2]),i[0].distanceTo(a[2]));if(this.fade){const s=e.near,l=this.far,h=i[0].z/(l-s);r+=.25*h**2*(l-s)}return r*.5}updateMatrices(e,t,a=1){const i=we.lookAt(Q.setScalar(0),ee.copy(t).multiplyScalar(-1),n.Object3D.DEFAULT_UP),r=te.multiplyMatrices(te.copy(i).invert(),e.matrixWorld),s=this.frusta,l=this.cascades;D(s.length===l.length);const h=this.margin,d=this.mapSize;for(let p=0;p<s.length;++p){const f=s[p],m=l[p],v=this.getFrustumRadius(e,s[p]),j=-v,Y=v,q=v,Z=-v;m.projectionMatrix.makeOrthographic(j,Y,q,Z,-this.margin,v*2+this.margin);const{near:pe,far:fe}=Ce.copy(f).applyMatrix4(r),N=Te.makeEmpty();for(let b=0;b<4;b++)N.expandByPoint(pe[b]),N.expandByPoint(fe[b]);const T=N.getCenter(Q);T.z=N.max.z+h;const K=(Y-j)/d.width,X=(q-Z)/d.height;T.x=Math.round(T.x/K)*K,T.y=Math.round(T.y/X)*X,T.applyMatrix4(i);const $=ee.copy(t).multiplyScalar(a).add(T);m.inverseViewMatrix.lookAt(T,$,n.Object3D.DEFAULT_UP).setPosition($)}}update(e,t,a){this._far=this.maxFar!=null?Math.min(this.maxFar,e.far*this.farScale):e.far*this.farScale,this.updateIntervals(e),this.updateMatrices(e,t,a);const i=this.cascades,r=this.cascadeCount;for(let s=0;s<r;++s){const{matrix:l,inverseMatrix:h,projectionMatrix:d,inverseProjectionMatrix:p,viewMatrix:f,inverseViewMatrix:m}=i[s];p.copy(d).invert(),f.copy(m).invert(),l.copy(d).multiply(f),h.copy(m).multiply(p)}}}const ne=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5],ie=ne.reduce((o,e,t)=>{const a=new n.Vector2;for(let i=0;i<16;++i)if(ne[i]===t){a.set((i%4+.5)/4,(Math.floor(i/4)+.5)/4);break}return[...o,a]},[]),Ae={resolutionScale:1,lightShafts:!0,shapeDetail:!0,turbulence:!0,haze:!0,clouds:{multiScatteringOctaves:8,accurateSunSkyLight:!0,accuratePhaseFunction:!1,maxIterationCount:500,minStepSize:50,maxStepSize:1e3,maxRayDistance:2e5,perspectiveStepScale:1.01,minDensity:1e-5,minExtinction:1e-5,minTransmittance:.01,maxIterationCountToGround:3,maxIterationCountToSun:2,minSecondaryStepSize:100,secondaryStepScale:2,maxShadowLengthIterationCount:500,minShadowLengthStepSize:50,maxShadowLengthRayDistance:2e5},shadow:{cascadeCount:3,mapSize:new n.Vector2(512,512),maxIterationCount:50,minStepSize:100,maxStepSize:1e3,minDensity:1e-5,minExtinction:1e-5,minTransmittance:1e-4}},c=Ae,_e={low:{...c,lightShafts:!1,shapeDetail:!1,turbulence:!1,clouds:{...c.clouds,accurateSunSkyLight:!1,maxIterationCount:200,minStepSize:100,maxRayDistance:1e5,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.1,maxIterationCountToGround:0,maxIterationCountToSun:1},shadow:{...c.shadow,maxIterationCount:25,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.01,cascadeCount:2,mapSize:new n.Vector2(256,256)}},medium:{...c,lightShafts:!1,turbulence:!1,clouds:{...c.clouds,minDensity:1e-4,minExtinction:1e-4,accurateSunSkyLight:!1,maxIterationCountToSun:2,maxIterationCountToGround:1},shadow:{...c.shadow,minDensity:1e-4,minExtinction:1e-4,mapSize:new n.Vector2(256,256)}},high:c,ultra:{...c,clouds:{...c.clouds,minStepSize:10},shadow:{...c.shadow,mapSize:new n.Vector2(1024,1024)}}},Oe=`precision highp float;
2
2
  precision highp sampler3D;
3
3
  precision highp sampler2DArray;
4
4
 
@@ -13,14 +13,28 @@ precision highp sampler2DArray;
13
13
  #include "core/cascadedShadowMaps"
14
14
  #include "core/interleavedGradientNoise"
15
15
  #include "core/vogelDisk"
16
- #include "atmosphere/parameters"
17
- #include "atmosphere/functions"
16
+
17
+ #include "atmosphere/bruneton/definitions"
18
+
19
+ uniform AtmosphereParameters ATMOSPHERE;
20
+ uniform vec3 SUN_SPECTRAL_RADIANCE_TO_LUMINANCE;
21
+ uniform vec3 SKY_SPECTRAL_RADIANCE_TO_LUMINANCE;
22
+
23
+ uniform sampler2D transmittance_texture;
24
+ uniform sampler3D scattering_texture;
25
+ uniform sampler2D irradiance_texture;
26
+ uniform sampler3D single_mie_scattering_texture;
27
+ uniform sampler3D higher_order_scattering_texture;
28
+
29
+ #include "atmosphere/bruneton/common"
30
+ #include "atmosphere/bruneton/runtime"
31
+
18
32
  #include "types"
19
33
  #include "parameters"
20
34
  #include "clouds"
21
35
 
22
36
  #if !defined(RECIPROCAL_PI4)
23
- #define RECIPROCAL_PI4 (0.07957747154594767)
37
+ #define RECIPROCAL_PI4 0.07957747154594767
24
38
  #endif // !defined(RECIPROCAL_PI4)
25
39
 
26
40
  uniform sampler2D depthBuffer;
@@ -36,8 +50,8 @@ uniform float mipLevelScale;
36
50
  // Scattering
37
51
  const vec2 scatterAnisotropy = vec2(SCATTER_ANISOTROPY_1, SCATTER_ANISOTROPY_2);
38
52
  const float scatterAnisotropyMix = SCATTER_ANISOTROPY_MIX;
39
- uniform float skyIrradianceScale;
40
- uniform float groundIrradianceScale;
53
+ uniform float skyLightScale;
54
+ uniform float groundBounceScale;
41
55
  uniform float powderScale;
42
56
  uniform float powderExponent;
43
57
 
@@ -266,7 +280,7 @@ vec4 getCascadedShadowMaps(vec2 uv) {
266
280
  }
267
281
 
268
282
  #if !defined(DEBUG_SHOW_SHADOW_MAP_TYPE)
269
- #define DEBUG_SHOW_SHADOW_MAP_TYPE (0)
283
+ #define DEBUG_SHOW_SHADOW_MAP_TYPE 0
270
284
  #endif // !defined(DEBUG_SHOW_SHADOW_MAP_TYPE
271
285
 
272
286
  const float frontDepthScale = 1e-5;
@@ -415,35 +429,31 @@ vec3 getGroundSunSkyIrradiance(
415
429
  const float height,
416
430
  out vec3 skyIrradiance
417
431
  ) {
418
- #ifdef ACCURATE_SUN_SKY_IRRADIANCE
432
+ #ifdef ACCURATE_SUN_SKY_LIGHT
419
433
  return GetSunAndSkyIrradiance(
420
434
  (position - surfaceNormal * height) * METER_TO_LENGTH_UNIT,
421
435
  surfaceNormal,
422
436
  sunDirection,
423
437
  skyIrradiance
424
438
  );
425
- #else // ACCURATE_SUN_SKY_IRRADIANCE
439
+ #else // ACCURATE_SUN_SKY_LIGHT
426
440
  skyIrradiance = vGroundIrradiance.sky;
427
441
  return vGroundIrradiance.sun;
428
- #endif // ACCURATE_SUN_SKY_IRRADIANCE
442
+ #endif // ACCURATE_SUN_SKY_LIGHT
429
443
  }
430
444
 
431
445
  vec3 getCloudsSunSkyIrradiance(const vec3 position, const float height, out vec3 skyIrradiance) {
432
- #ifdef ACCURATE_SUN_SKY_IRRADIANCE
433
- return GetSunAndSkyIrradianceForParticle(
434
- position * METER_TO_LENGTH_UNIT,
435
- sunDirection,
436
- skyIrradiance
437
- );
438
- #else // ACCURATE_SUN_SKY_IRRADIANCE
446
+ #ifdef ACCURATE_SUN_SKY_LIGHT
447
+ return GetSunAndSkyScalarIrradiance(position * METER_TO_LENGTH_UNIT, sunDirection, skyIrradiance);
448
+ #else // ACCURATE_SUN_SKY_LIGHT
439
449
  float alpha = remapClamped(height, minHeight, maxHeight);
440
450
  skyIrradiance = mix(vCloudsIrradiance.minSky, vCloudsIrradiance.maxSky, alpha);
441
451
  return mix(vCloudsIrradiance.minSun, vCloudsIrradiance.maxSun, alpha);
442
- #endif // ACCURATE_SUN_SKY_IRRADIANCE
452
+ #endif // ACCURATE_SUN_SKY_LIGHT
443
453
  }
444
454
 
445
- #ifdef GROUND_IRRADIANCE
446
- vec3 approximateIrradianceFromGround(
455
+ #ifdef GROUND_BOUNCE
456
+ vec3 approximateRadianceFromGround(
447
457
  const vec3 position,
448
458
  const vec3 surfaceNormal,
449
459
  const float height,
@@ -464,7 +474,7 @@ vec3 approximateIrradianceFromGround(
464
474
  vec3 bouncedRadiance = groundAlbedo * RECIPROCAL_PI * groundIrradiance;
465
475
  return bouncedRadiance * exp(-opticalDepthToGround);
466
476
  }
467
- #endif // GROUND_IRRADIANCE
477
+ #endif // GROUND_BOUNCE
468
478
 
469
479
  vec4 marchClouds(
470
480
  const vec3 rayOrigin,
@@ -554,23 +564,23 @@ vec4 marchClouds(
554
564
 
555
565
  vec3 radiance = sunIrradiance * approximateMultipleScattering(opticalDepth, cosTheta);
556
566
 
557
- #ifdef GROUND_IRRADIANCE
567
+ #ifdef GROUND_BOUNCE
558
568
  // Fudge factor for the irradiance from ground.
559
569
  if (height < shadowTopHeight && mipLevel < 0.5) {
560
- vec3 groundIrradiance = approximateIrradianceFromGround(
570
+ vec3 groundRadiance = approximateRadianceFromGround(
561
571
  position,
562
572
  surfaceNormal,
563
573
  height,
564
574
  mipLevel,
565
575
  jitter
566
576
  );
567
- radiance += groundIrradiance * RECIPROCAL_PI4 * groundIrradianceScale;
577
+ radiance += groundRadiance * RECIPROCAL_PI4 * groundBounceScale;
568
578
  }
569
- #endif // GROUND_IRRADIANCE
579
+ #endif // GROUND_BOUNCE
570
580
 
571
581
  // Crude approximation of sky gradient. Better than none in the shadows.
572
582
  float skyGradient = dot(weather.heightFraction * 0.5 + 0.5, media.weight);
573
- radiance += skyIrradiance * RECIPROCAL_PI4 * skyGradient * skyIrradianceScale;
583
+ radiance += skyIrradiance * RECIPROCAL_PI4 * skyGradient * skyLightScale;
574
584
 
575
585
  // Finally multiply by scattering.
576
586
  radiance *= media.scattering;
@@ -638,14 +648,6 @@ float marchShadowLength(
638
648
  vec3 position = rayDistance * rayDirection + rayOrigin;
639
649
  float opticalDepth = sampleShadowOpticalDepth(position, 0.0, 0.0, jitter);
640
650
  shadowLength += (1.0 - exp(-opticalDepth)) * stepSize * attenuation;
641
-
642
- // Hack to prevent over-integration of shadow length. The shadow should be
643
- // attenuated by the inscatter as the ray travels further.
644
- attenuation *= attenuationFactor;
645
- if (attenuation < 1e-5) {
646
- break;
647
- }
648
-
649
651
  stepSize *= perspectiveStepScale;
650
652
  rayDistance += stepSize;
651
653
  }
@@ -696,7 +698,7 @@ vec4 approximateHaze(
696
698
  vec3 skyIrradiance = vGroundIrradiance.sky;
697
699
  vec3 sunIrradiance = vGroundIrradiance.sun;
698
700
  vec3 inscatter = sunIrradiance * phaseFunction(cosTheta) * shadowTransmittance;
699
- inscatter += skyIrradiance * RECIPROCAL_PI4 * skyIrradianceScale * transmittance;
701
+ inscatter += skyIrradiance * RECIPROCAL_PI4 * skyLightScale * transmittance;
700
702
  inscatter *= hazeScatteringCoefficient / (hazeAbsorptionCoefficient + hazeScatteringCoefficient);
701
703
  return vec4(inscatter, transmittance);
702
704
  }
@@ -1196,11 +1198,24 @@ MediaSample sampleMedia(
1196
1198
  ivec3 sampleCount;
1197
1199
  return sampleMedia(weather, position, uv, mipLevel, jitter, sampleCount);
1198
1200
  }
1199
- `,Oe=`precision highp float;
1201
+ `,Pe=`precision highp float;
1200
1202
  precision highp sampler3D;
1201
1203
 
1202
- #include "atmosphere/parameters"
1203
- #include "atmosphere/functions"
1204
+ #include "atmosphere/bruneton/definitions"
1205
+
1206
+ uniform AtmosphereParameters ATMOSPHERE;
1207
+ uniform vec3 SUN_SPECTRAL_RADIANCE_TO_LUMINANCE;
1208
+ uniform vec3 SKY_SPECTRAL_RADIANCE_TO_LUMINANCE;
1209
+
1210
+ uniform sampler2D transmittance_texture;
1211
+ uniform sampler3D scattering_texture;
1212
+ uniform sampler2D irradiance_texture;
1213
+ uniform sampler3D single_mie_scattering_texture;
1214
+ uniform sampler3D higher_order_scattering_texture;
1215
+
1216
+ #include "atmosphere/bruneton/common"
1217
+ #include "atmosphere/bruneton/runtime"
1218
+
1204
1219
  #include "types"
1205
1220
 
1206
1221
  uniform mat4 inverseProjectionMatrix;
@@ -1230,7 +1245,7 @@ out GroundIrradiance vGroundIrradiance;
1230
1245
  out CloudsIrradiance vCloudsIrradiance;
1231
1246
 
1232
1247
  void sampleSunSkyIrradiance(const vec3 positionECEF) {
1233
- vGroundIrradiance.sun = GetSunAndSkyIrradianceForParticle(
1248
+ vGroundIrradiance.sun = GetSunAndSkyScalarIrradiance(
1234
1249
  positionECEF * METER_TO_LENGTH_UNIT,
1235
1250
  sunDirection,
1236
1251
  vGroundIrradiance.sky
@@ -1238,12 +1253,12 @@ void sampleSunSkyIrradiance(const vec3 positionECEF) {
1238
1253
 
1239
1254
  vec3 surfaceNormal = normalize(positionECEF);
1240
1255
  vec2 radii = (bottomRadius + vec2(minHeight, maxHeight)) * METER_TO_LENGTH_UNIT;
1241
- vCloudsIrradiance.minSun = GetSunAndSkyIrradianceForParticle(
1256
+ vCloudsIrradiance.minSun = GetSunAndSkyScalarIrradiance(
1242
1257
  surfaceNormal * radii.x,
1243
1258
  sunDirection,
1244
1259
  vCloudsIrradiance.minSky
1245
1260
  );
1246
- vCloudsIrradiance.maxSun = GetSunAndSkyIrradianceForParticle(
1261
+ vCloudsIrradiance.maxSun = GetSunAndSkyScalarIrradiance(
1247
1262
  surfaceNormal * radii.y,
1248
1263
  sunDirection,
1249
1264
  vCloudsIrradiance.maxSky
@@ -1329,7 +1344,7 @@ uniform float maxHeight;
1329
1344
  uniform float shadowTopHeight;
1330
1345
  uniform float shadowBottomHeight;
1331
1346
  uniform vec4 shadowLayerMask;
1332
- uniform DensityProfile densityProfile;
1347
+ uniform CloudDensityProfile densityProfile;
1333
1348
  `,V=`struct GroundIrradiance {
1334
1349
  vec3 sun;
1335
1350
  vec3 sky;
@@ -1342,13 +1357,13 @@ struct CloudsIrradiance {
1342
1357
  vec3 maxSky;
1343
1358
  };
1344
1359
 
1345
- struct DensityProfile {
1360
+ struct CloudDensityProfile {
1346
1361
  vec4 expTerms;
1347
1362
  vec4 exponents;
1348
1363
  vec4 linearTerms;
1349
1364
  vec4 constantTerms;
1350
1365
  };
1351
- `;var Re=Object.defineProperty,S=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Re(e,t,i),i};const Ue=new n.Vector3,Le=new h.Geodetic;class g extends H.AtmosphereMaterialBase{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},i=H.AtmosphereParameters.DEFAULT){super({name:"CloudsMaterial",glslVersion:n.GLSL3,vertexShader:h.resolveIncludes(Oe,{atmosphere:{parameters:b.parameters,functions:b.functions},types:V}),fragmentShader:h.unrollLoops(h.resolveIncludes(Pe,{core:{depth:y.depth,math:y.math,turbo:y.turbo,generators:y.generators,raySphereIntersection:y.raySphereIntersection,cascadedShadowMaps:y.cascadedShadowMaps,interleavedGradientNoise:y.interleavedGradientNoise,vogelDisk:y.vogelDisk},atmosphere:{parameters:b.parameters,functions:b.functions},types:V,parameters:oe,clouds:re})),uniforms:{...e,...t,...a,depthBuffer:new n.Uniform(null),viewMatrix:new n.Uniform(new n.Matrix4),inverseProjectionMatrix:new n.Uniform(new n.Matrix4),inverseViewMatrix:new n.Uniform(new n.Matrix4),reprojectionMatrix:new n.Uniform(new n.Matrix4),resolution:new n.Uniform(new n.Vector2),cameraNear:new n.Uniform(0),cameraFar:new n.Uniform(0),cameraHeight:new n.Uniform(0),frame:new n.Uniform(0),temporalJitter:new n.Uniform(new n.Vector2),targetUvScale:new n.Uniform(new n.Vector2),mipLevelScale:new n.Uniform(1),stbnTexture:new n.Uniform(null),skyIrradianceScale:new n.Uniform(1),groundIrradianceScale:new n.Uniform(1),powderScale:new n.Uniform(.8),powderExponent:new n.Uniform(150),maxIterationCount:new n.Uniform(c.clouds.maxIterationCount),minStepSize:new n.Uniform(c.clouds.minStepSize),maxStepSize:new n.Uniform(c.clouds.maxStepSize),maxRayDistance:new n.Uniform(c.clouds.maxRayDistance),perspectiveStepScale:new n.Uniform(c.clouds.perspectiveStepScale),minDensity:new n.Uniform(c.clouds.minDensity),minExtinction:new n.Uniform(c.clouds.minExtinction),minTransmittance:new n.Uniform(c.clouds.minTransmittance),maxIterationCountToSun:new n.Uniform(c.clouds.maxIterationCountToSun),maxIterationCountToGround:new n.Uniform(c.clouds.maxIterationCountToGround),minSecondaryStepSize:new n.Uniform(c.clouds.minSecondaryStepSize),secondaryStepScale:new n.Uniform(c.clouds.secondaryStepScale),shadowBuffer:new n.Uniform(null),shadowTexelSize:new n.Uniform(new n.Vector2),shadowIntervals:new n.Uniform(Array.from({length:4},()=>new n.Vector2)),shadowMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),shadowFar:new n.Uniform(0),maxShadowFilterRadius:new n.Uniform(6),shadowLayerMask:new n.Uniform(new n.Vector4().setScalar(1)),maxShadowLengthIterationCount:new n.Uniform(c.clouds.maxShadowLengthIterationCount),minShadowLengthStepSize:new n.Uniform(c.clouds.minShadowLengthStepSize),maxShadowLengthRayDistance:new n.Uniform(c.clouds.maxShadowLengthRayDistance),hazeDensityScale:new n.Uniform(3e-5),hazeExponent:new n.Uniform(.001),hazeScatteringCoefficient:new n.Uniform(.9),hazeAbsorptionCoefficient:new n.Uniform(.5)}},i),this.temporalUpscale=!0,this.depthPacking=0,this.localWeatherChannels="rgba",this.shapeDetail=c.shapeDetail,this.turbulence=c.turbulence,this.shadowLength=c.lightShafts,this.haze=c.haze,this.multiScatteringOctaves=c.clouds.multiScatteringOctaves,this.accurateSunSkyIrradiance=c.clouds.accurateSunSkyIrradiance,this.accuratePhaseFunction=c.clouds.accuratePhaseFunction,this.shadowCascadeCount=c.shadow.cascadeCount,this.shadowSampleCount=8,this.scatterAnisotropy1=.7,this.scatterAnisotropy2=-.2,this.scatterAnisotropyMix=.5}onBeforeRender(e,t,a,i,r,s){const l=this.defines.USE_LOGDEPTHBUF!=null,u=e.capabilities.logarithmicDepthBuffer;u!==l&&(u?this.defines.USE_LOGDEPTHBUF="1":delete this.defines.USE_LOGDEPTHBUF);const d=this.defines.POWDER!=null,p=this.uniforms.powderScale.value>0;p!==d&&(p?this.defines.POWDER="1":delete this.defines.POWDER,this.needsUpdate=!0);const f=this.defines.GROUND_IRRADIANCE!=null;(this.uniforms.groundIrradianceScale.value>0&&this.uniforms.maxIterationCountToGround.value>0)!==f&&(p?this.defines.GROUND_IRRADIANCE="1":delete this.defines.GROUND_IRRADIANCE,this.needsUpdate=!0)}copyCameraSettings(e){e.isPerspectiveCamera===!0?this.defines.PERSPECTIVE_CAMERA!=="1"&&(this.defines.PERSPECTIVE_CAMERA="1",this.needsUpdate=!0):this.defines.PERSPECTIVE_CAMERA!=null&&(delete this.defines.PERSPECTIVE_CAMERA,this.needsUpdate=!0);const t=this.uniforms;t.viewMatrix.value.copy(e.matrixWorldInverse),t.inverseViewMatrix.value.copy(e.matrixWorld);const a=this.previousProjectionMatrix??e.projectionMatrix,i=this.previousViewMatrix??e.matrixWorldInverse,r=t.inverseProjectionMatrix.value,s=t.reprojectionMatrix.value;if(this.temporalUpscale){const d=t.frame.value%16,p=t.resolution.value,f=ie[d],m=(f.x-.5)/p.x*4,v=(f.y-.5)/p.y*4;t.temporalJitter.value.set(m,v),t.mipLevelScale.value=.25,r.copy(e.projectionMatrix),r.elements[8]+=m*2,r.elements[9]+=v*2,r.invert(),s.copy(a),s.elements[8]+=m*2,s.elements[9]+=v*2,s.multiply(i)}else t.temporalJitter.value.setScalar(0),t.mipLevelScale.value=1,r.copy(e.projectionMatrixInverse),s.copy(a).multiply(i);h.assertType(e),t.cameraNear.value=e.near,t.cameraFar.value=e.far;const l=e.getWorldPosition(t.cameraPosition.value),u=Ue.copy(l).applyMatrix4(t.inverseEllipsoidMatrix.value).sub(t.ellipsoidCenter.value);try{t.cameraHeight.value=Le.setFromECEF(u).height}catch{}}copyReprojectionMatrix(e){this.previousProjectionMatrix??(this.previousProjectionMatrix=new n.Matrix4),this.previousViewMatrix??(this.previousViewMatrix=new n.Matrix4),this.previousProjectionMatrix.copy(e.projectionMatrix),this.previousViewMatrix.copy(e.matrixWorldInverse)}setSize(e,t,a,i){this.uniforms.resolution.value.set(e,t),a!=null&&i!=null?this.uniforms.targetUvScale.value.set(e/a,t/i):this.uniforms.targetUvScale.value.setScalar(1),this.previousProjectionMatrix=void 0,this.previousViewMatrix=void 0}setShadowSize(e,t){this.uniforms.shadowTexelSize.value.set(1/e,1/t)}get depthBuffer(){return this.uniforms.depthBuffer.value}set depthBuffer(e){this.uniforms.depthBuffer.value=e}}S([h.defineInt("DEPTH_PACKING")],g.prototype,"depthPacking");S([h.defineExpression("LOCAL_WEATHER_CHANNELS",{validate:o=>/^[rgba]{4}$/.test(o)})],g.prototype,"localWeatherChannels");S([h.define("SHAPE_DETAIL")],g.prototype,"shapeDetail");S([h.define("TURBULENCE")],g.prototype,"turbulence");S([h.define("SHADOW_LENGTH")],g.prototype,"shadowLength");S([h.define("HAZE")],g.prototype,"haze");S([h.defineInt("MULTI_SCATTERING_OCTAVES",{min:1,max:12})],g.prototype,"multiScatteringOctaves");S([h.define("ACCURATE_SUN_SKY_IRRADIANCE")],g.prototype,"accurateSunSkyIrradiance");S([h.define("ACCURATE_PHASE_FUNCTION")],g.prototype,"accuratePhaseFunction");S([h.defineInt("SHADOW_CASCADE_COUNT",{min:1,max:4})],g.prototype,"shadowCascadeCount");S([h.defineInt("SHADOW_SAMPLE_COUNT",{min:1,max:16})],g.prototype,"shadowSampleCount");S([h.defineFloat("SCATTER_ANISOTROPY_1")],g.prototype,"scatterAnisotropy1");S([h.defineFloat("SCATTER_ANISOTROPY_2")],g.prototype,"scatterAnisotropy2");S([h.defineFloat("SCATTER_ANISOTROPY_MIX")],g.prototype,"scatterAnisotropyMix");const Ie=`// Taken from https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
1366
+ `;var Le=Object.defineProperty,S=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Le(e,t,i),i};const Ue=new n.Vector3,Re=new u.Geodetic;class g extends H.AtmosphereMaterialBase{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},i=H.AtmosphereParameters.DEFAULT){super({name:"CloudsMaterial",glslVersion:n.GLSL3,vertexShader:u.resolveIncludes(Pe,{atmosphere:{bruneton:{common:A.common,definitions:A.definitions,runtime:A.runtime}},types:V}),fragmentShader:u.unrollLoops(u.resolveIncludes(Oe,{core:{depth:y.depth,math:y.math,turbo:y.turbo,generators:y.generators,raySphereIntersection:y.raySphereIntersection,cascadedShadowMaps:y.cascadedShadowMaps,interleavedGradientNoise:y.interleavedGradientNoise,vogelDisk:y.vogelDisk},atmosphere:{bruneton:{common:A.common,definitions:A.definitions,runtime:A.runtime}},types:V,parameters:oe,clouds:re})),uniforms:{...e,...t,...a,depthBuffer:new n.Uniform(null),viewMatrix:new n.Uniform(new n.Matrix4),inverseProjectionMatrix:new n.Uniform(new n.Matrix4),inverseViewMatrix:new n.Uniform(new n.Matrix4),reprojectionMatrix:new n.Uniform(new n.Matrix4),resolution:new n.Uniform(new n.Vector2),cameraNear:new n.Uniform(0),cameraFar:new n.Uniform(0),cameraHeight:new n.Uniform(0),frame:new n.Uniform(0),temporalJitter:new n.Uniform(new n.Vector2),targetUvScale:new n.Uniform(new n.Vector2),mipLevelScale:new n.Uniform(1),stbnTexture:new n.Uniform(null),skyLightScale:new n.Uniform(1),groundBounceScale:new n.Uniform(1),powderScale:new n.Uniform(.8),powderExponent:new n.Uniform(150),maxIterationCount:new n.Uniform(c.clouds.maxIterationCount),minStepSize:new n.Uniform(c.clouds.minStepSize),maxStepSize:new n.Uniform(c.clouds.maxStepSize),maxRayDistance:new n.Uniform(c.clouds.maxRayDistance),perspectiveStepScale:new n.Uniform(c.clouds.perspectiveStepScale),minDensity:new n.Uniform(c.clouds.minDensity),minExtinction:new n.Uniform(c.clouds.minExtinction),minTransmittance:new n.Uniform(c.clouds.minTransmittance),maxIterationCountToSun:new n.Uniform(c.clouds.maxIterationCountToSun),maxIterationCountToGround:new n.Uniform(c.clouds.maxIterationCountToGround),minSecondaryStepSize:new n.Uniform(c.clouds.minSecondaryStepSize),secondaryStepScale:new n.Uniform(c.clouds.secondaryStepScale),shadowBuffer:new n.Uniform(null),shadowTexelSize:new n.Uniform(new n.Vector2),shadowIntervals:new n.Uniform(Array.from({length:4},()=>new n.Vector2)),shadowMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),shadowFar:new n.Uniform(0),maxShadowFilterRadius:new n.Uniform(6),shadowLayerMask:new n.Uniform(new n.Vector4().setScalar(1)),maxShadowLengthIterationCount:new n.Uniform(c.clouds.maxShadowLengthIterationCount),minShadowLengthStepSize:new n.Uniform(c.clouds.minShadowLengthStepSize),maxShadowLengthRayDistance:new n.Uniform(c.clouds.maxShadowLengthRayDistance),hazeDensityScale:new n.Uniform(3e-5),hazeExponent:new n.Uniform(.001),hazeScatteringCoefficient:new n.Uniform(.9),hazeAbsorptionCoefficient:new n.Uniform(.5)}},i),this.temporalUpscale=!0,this.depthPacking=0,this.localWeatherChannels="rgba",this.shapeDetail=c.shapeDetail,this.turbulence=c.turbulence,this.shadowLength=c.lightShafts,this.haze=c.haze,this.multiScatteringOctaves=c.clouds.multiScatteringOctaves,this.accurateSunSkyLight=c.clouds.accurateSunSkyLight,this.accuratePhaseFunction=c.clouds.accuratePhaseFunction,this.shadowCascadeCount=c.shadow.cascadeCount,this.shadowSampleCount=8,this.scatterAnisotropy1=.7,this.scatterAnisotropy2=-.2,this.scatterAnisotropyMix=.5}onBeforeRender(e,t,a,i,r,s){const l=this.defines.USE_LOGDEPTHBUF!=null,h=e.capabilities.logarithmicDepthBuffer;h!==l&&(h?this.defines.USE_LOGDEPTHBUF="1":delete this.defines.USE_LOGDEPTHBUF);const d=this.defines.POWDER!=null,p=this.uniforms.powderScale.value>0;p!==d&&(p?this.defines.POWDER="1":delete this.defines.POWDER,this.needsUpdate=!0);const f=this.defines.GROUND_BOUNCE!=null;(this.uniforms.groundBounceScale.value>0&&this.uniforms.maxIterationCountToGround.value>0)!==f&&(p?this.defines.GROUND_BOUNCE="1":delete this.defines.GROUND_BOUNCE,this.needsUpdate=!0)}copyCameraSettings(e){e.isPerspectiveCamera===!0?this.defines.PERSPECTIVE_CAMERA!=="1"&&(this.defines.PERSPECTIVE_CAMERA="1",this.needsUpdate=!0):this.defines.PERSPECTIVE_CAMERA!=null&&(delete this.defines.PERSPECTIVE_CAMERA,this.needsUpdate=!0);const t=this.uniforms;t.viewMatrix.value.copy(e.matrixWorldInverse),t.inverseViewMatrix.value.copy(e.matrixWorld);const a=this.previousProjectionMatrix??e.projectionMatrix,i=this.previousViewMatrix??e.matrixWorldInverse,r=t.inverseProjectionMatrix.value,s=t.reprojectionMatrix.value;if(this.temporalUpscale){const d=t.frame.value%16,p=t.resolution.value,f=ie[d],m=(f.x-.5)/p.x*4,v=(f.y-.5)/p.y*4;t.temporalJitter.value.set(m,v),t.mipLevelScale.value=.25,r.copy(e.projectionMatrix),r.elements[8]+=m*2,r.elements[9]+=v*2,r.invert(),s.copy(a),s.elements[8]+=m*2,s.elements[9]+=v*2,s.multiply(i)}else t.temporalJitter.value.setScalar(0),t.mipLevelScale.value=1,r.copy(e.projectionMatrixInverse),s.copy(a).multiply(i);u.assertType(e),t.cameraNear.value=e.near,t.cameraFar.value=e.far;const l=e.getWorldPosition(t.cameraPosition.value),h=Ue.copy(l).applyMatrix4(t.inverseEllipsoidMatrix.value).sub(t.ellipsoidCenter.value);try{t.cameraHeight.value=Re.setFromECEF(h).height}catch{}}copyReprojectionMatrix(e){this.previousProjectionMatrix??(this.previousProjectionMatrix=new n.Matrix4),this.previousViewMatrix??(this.previousViewMatrix=new n.Matrix4),this.previousProjectionMatrix.copy(e.projectionMatrix),this.previousViewMatrix.copy(e.matrixWorldInverse)}setSize(e,t,a,i){this.uniforms.resolution.value.set(e,t),a!=null&&i!=null?this.uniforms.targetUvScale.value.set(e/a,t/i):this.uniforms.targetUvScale.value.setScalar(1),this.previousProjectionMatrix=void 0,this.previousViewMatrix=void 0}setShadowSize(e,t){this.uniforms.shadowTexelSize.value.set(1/e,1/t)}get depthBuffer(){return this.uniforms.depthBuffer.value}set depthBuffer(e){this.uniforms.depthBuffer.value=e}get accurateSunSkyIrradiance(){return this.accurateSunSkyLight}set accurateSunSkyIrradiance(e){this.accurateSunSkyLight=e}}S([u.defineInt("DEPTH_PACKING")],g.prototype,"depthPacking");S([u.defineExpression("LOCAL_WEATHER_CHANNELS",{validate:o=>/^[rgba]{4}$/.test(o)})],g.prototype,"localWeatherChannels");S([u.define("SHAPE_DETAIL")],g.prototype,"shapeDetail");S([u.define("TURBULENCE")],g.prototype,"turbulence");S([u.define("SHADOW_LENGTH")],g.prototype,"shadowLength");S([u.define("HAZE")],g.prototype,"haze");S([u.defineInt("MULTI_SCATTERING_OCTAVES",{min:1,max:12})],g.prototype,"multiScatteringOctaves");S([u.define("ACCURATE_SUN_SKY_LIGHT")],g.prototype,"accurateSunSkyLight");S([u.define("ACCURATE_PHASE_FUNCTION")],g.prototype,"accuratePhaseFunction");S([u.defineInt("SHADOW_CASCADE_COUNT",{min:1,max:4})],g.prototype,"shadowCascadeCount");S([u.defineInt("SHADOW_SAMPLE_COUNT",{min:1,max:16})],g.prototype,"shadowSampleCount");S([u.defineFloat("SCATTER_ANISOTROPY_1")],g.prototype,"scatterAnisotropy1");S([u.defineFloat("SCATTER_ANISOTROPY_2")],g.prototype,"scatterAnisotropy2");S([u.defineFloat("SCATTER_ANISOTROPY_MIX")],g.prototype,"scatterAnisotropyMix");const Ie=`// Taken from https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
1352
1367
  // TODO: Use 5-taps version: https://www.shadertoy.com/view/MtVGWz
1353
1368
  // Or even 4 taps (requires preprocessing in the input buffer):
1354
1369
  // https://www.shadertoy.com/view/4tyGDD
@@ -1461,7 +1476,7 @@ vec4 textureCatmullRom(sampler2DArray tex, vec3 uv) {
1461
1476
  result += texture(tex, vec3(texPos3.x, texPos3.y, uv.z)) * w3.x * w3.y;
1462
1477
  return result;
1463
1478
  }
1464
- `,Ne=`precision highp float;
1479
+ `,Me=`precision highp float;
1465
1480
  precision highp sampler2DArray;
1466
1481
 
1467
1482
  #include "core/turbo"
@@ -1663,7 +1678,7 @@ void main() {
1663
1678
  outputColor = vec4(turbo(outputShadowLength * 0.05), 1.0);
1664
1679
  #endif // defined(SHADOW_LENGTH) && defined(DEBUG_SHOW_SHADOW_LENGTH)
1665
1680
  }
1666
- `,Me=`precision highp float;
1681
+ `,Ne=`precision highp float;
1667
1682
 
1668
1683
  layout(location = 0) in vec3 position;
1669
1684
 
@@ -1674,7 +1689,7 @@ void main() {
1674
1689
  gl_Position = vec4(position.xy, 1.0, 1.0);
1675
1690
  }
1676
1691
  `,se=`#ifdef VARIANCE_9_SAMPLES
1677
- #define VARIANCE_OFFSET_COUNT (8)
1692
+ #define VARIANCE_OFFSET_COUNT 8
1678
1693
  const ivec2 varianceOffsets[8] = ivec2[8](
1679
1694
  ivec2(-1, -1),
1680
1695
  ivec2(-1, 1),
@@ -1686,7 +1701,7 @@ const ivec2 varianceOffsets[8] = ivec2[8](
1686
1701
  ivec2(-1, 0)
1687
1702
  );
1688
1703
  #else // VARIANCE_9_SAMPLES
1689
- #define VARIANCE_OFFSET_COUNT (4)
1704
+ #define VARIANCE_OFFSET_COUNT 4
1690
1705
  const ivec2 varianceOffsets[4] = ivec2[4](ivec2(1, 0), ivec2(0, -1), ivec2(0, 1), ivec2(-1, 0));
1691
1706
  #endif // VARIANCE_9_SAMPLES
1692
1707
 
@@ -1787,7 +1802,7 @@ vec4 varianceClipping(
1787
1802
  ) {
1788
1803
  return varianceClipping(inputBuffer, coord, current, history, 1.0);
1789
1804
  }
1790
- `;var be=Object.defineProperty,ce=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&be(e,t,i),i};class k extends n.RawShaderMaterial{constructor({colorBuffer:e=null,depthVelocityBuffer:t=null,shadowLengthBuffer:a=null,colorHistoryBuffer:i=null,shadowLengthHistoryBuffer:r=null}={}){super({name:"CloudsResolveMaterial",glslVersion:n.GLSL3,vertexShader:Me,fragmentShader:h.unrollLoops(h.resolveIncludes(Ne,{core:{turbo:y.turbo},catmullRomSampling:Ie,varianceClipping:se})),uniforms:{colorBuffer:new n.Uniform(e),depthVelocityBuffer:new n.Uniform(t),shadowLengthBuffer:new n.Uniform(a),colorHistoryBuffer:new n.Uniform(i),shadowLengthHistoryBuffer:new n.Uniform(r),texelSize:new n.Uniform(new n.Vector2),frame:new n.Uniform(0),jitterOffset:new n.Uniform(new n.Vector2),varianceGamma:new n.Uniform(2),temporalAlpha:new n.Uniform(.1)}}),this.temporalUpscale=!0,this.shadowLength=!0}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}onBeforeRender(e,t,a,i,r,s){const u=this.uniforms.frame.value%16,d=ie[u],p=(d.x-.5)*4,f=(d.y-.5)*4;this.uniforms.jitterOffset.value.set(p,f)}}ce([h.define("TEMPORAL_UPSCALE")],k.prototype,"temporalUpscale");ce([h.define("SHADOW_LENGTH")],k.prototype,"shadowLength");class le extends C.Pass{constructor(e,t){super(e),this._mainCamera=new n.Camera;const{shadow:a}=t;this.shadow=a}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e}}function W(o,{depthVelocity:e,shadowLength:t}){const a=new n.WebGLRenderTarget(1,1,{depthBuffer:!1,stencilBuffer:!1,type:n.HalfFloatType});a.texture.minFilter=n.LinearFilter,a.texture.magFilter=n.LinearFilter,a.texture.name=o;let i;e&&(i=a.texture.clone(),i.isRenderTargetTexture=!0,a.depthVelocity=i,a.textures.push(i));let r;return t&&(r=a.texture.clone(),r.isRenderTargetTexture=!0,r.format=n.RedFormat,a.shadowLength=r,a.textures.push(r)),Object.assign(a,{depthVelocity:i??null,shadowLength:r??null})}class He extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...i},r){super("CloudsPass",i),this.atmosphere=r,this.width=0,this.height=0,this.currentMaterial=new g({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},r),this.currentPass=new C.ShaderPass(this.currentMaterial),this.resolveMaterial=new k,this.resolvePass=new C.ShaderPass(this.resolveMaterial),this.initRenderTargets({depthVelocity:!0,shadowLength:c.lightShafts})}copyCameraSettings(e){this.currentMaterial.copyCameraSettings(e)}initialize(e,t,a){this.currentPass.initialize(e,t,a),this.resolvePass.initialize(e,t,a)}initRenderTargets(e){var s,l,u;(s=this.currentRenderTarget)==null||s.dispose(),(l=this.resolveRenderTarget)==null||l.dispose(),(u=this.historyRenderTarget)==null||u.dispose();const t=W("Clouds",e),a=W("Clouds.A",{...e,depthVelocity:!1}),i=W("Clouds.B",{...e,depthVelocity:!1});this.currentRenderTarget=t,this.resolveRenderTarget=a,this.historyRenderTarget=i;const r=this.resolveMaterial.uniforms;r.colorBuffer.value=t.texture,r.depthVelocityBuffer.value=t.depthVelocity,r.shadowLengthBuffer.value=t.shadowLength,r.colorHistoryBuffer.value=i.texture,r.shadowLengthHistoryBuffer.value=i.shadowLength}copyShadow(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.shadowIntervals.value[a].copy(i.interval),t.shadowMatrices.value[a].copy(i.matrix)}t.shadowFar.value=e.far}copyReprojection(){this.currentMaterial.copyReprojectionMatrix(this.mainCamera)}swapBuffers(){const e=this.historyRenderTarget,t=this.resolveRenderTarget;this.resolveRenderTarget=e,this.historyRenderTarget=t;const a=this.resolveMaterial.uniforms;a.colorHistoryBuffer.value=t.texture,a.shadowLengthHistoryBuffer.value=t.shadowLength}update(e,t,a){this.currentMaterial.uniforms.frame.value=t,this.resolveMaterial.uniforms.frame.value=t,this.copyCameraSettings(this.mainCamera),this.copyShadow(),this.currentPass.render(e,null,this.currentRenderTarget),this.resolvePass.render(e,null,this.resolveRenderTarget),this.copyReprojection(),this.swapBuffers()}setSize(e,t){if(this.width=e,this.height=t,this.temporalUpscale){const a=Math.ceil(e/4),i=Math.ceil(t/4);this.currentRenderTarget.setSize(a,i),this.currentMaterial.setSize(a*4,i*4,e,t)}else this.currentRenderTarget.setSize(e,t),this.currentMaterial.setSize(e,t);this.resolveRenderTarget.setSize(e,t),this.resolveMaterial.setSize(e,t),this.historyRenderTarget.setSize(e,t)}setShadowSize(e,t,a){this.currentMaterial.shadowCascadeCount=a,this.currentMaterial.setShadowSize(e,t)}setDepthTexture(e,t){this.currentMaterial.depthBuffer=e,this.currentMaterial.depthPacking=t??0}get outputBuffer(){return this.historyRenderTarget.texture}get shadowBuffer(){return this.currentMaterial.uniforms.shadowBuffer.value}set shadowBuffer(e){this.currentMaterial.uniforms.shadowBuffer.value=e}get shadowLengthBuffer(){return this.historyRenderTarget.shadowLength}get temporalUpscale(){return this.currentMaterial.temporalUpscale}set temporalUpscale(e){e!==this.temporalUpscale&&(this.currentMaterial.temporalUpscale=e,this.resolveMaterial.temporalUpscale=e,this.setSize(this.width,this.height))}get lightShafts(){return this.currentMaterial.shadowLength}set lightShafts(e){e!==this.lightShafts&&(this.currentMaterial.shadowLength=e,this.resolveMaterial.shadowLength=e,this.initRenderTargets({depthVelocity:!0,shadowLength:e}),this.setSize(this.width,this.height))}}function Fe(o,e){const t=o.properties.get(e.texture).__webglTexture,a=o.getContext();D(a instanceof WebGL2RenderingContext),o.setRenderTarget(e);const i=[];if(t!=null)for(let r=0;r<e.depth;++r)a.framebufferTextureLayer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+r,t,0,r),i.push(a.COLOR_ATTACHMENT0+r);a.drawBuffers(i)}class ae extends C.ShaderPass{render(e,t,a,i,r){const s=this.fullscreenMaterial.uniforms;t!==null&&(s==null?void 0:s[this.input])!=null&&(s[this.input].value=t.texture),Fe(e,a),e.render(this.scene,this.camera)}}const ze=`precision highp float;
1805
+ `;var be=Object.defineProperty,ce=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&be(e,t,i),i};class k extends n.RawShaderMaterial{constructor({colorBuffer:e=null,depthVelocityBuffer:t=null,shadowLengthBuffer:a=null,colorHistoryBuffer:i=null,shadowLengthHistoryBuffer:r=null}={}){super({name:"CloudsResolveMaterial",glslVersion:n.GLSL3,vertexShader:Ne,fragmentShader:u.unrollLoops(u.resolveIncludes(Me,{core:{turbo:y.turbo},catmullRomSampling:Ie,varianceClipping:se})),uniforms:{colorBuffer:new n.Uniform(e),depthVelocityBuffer:new n.Uniform(t),shadowLengthBuffer:new n.Uniform(a),colorHistoryBuffer:new n.Uniform(i),shadowLengthHistoryBuffer:new n.Uniform(r),texelSize:new n.Uniform(new n.Vector2),frame:new n.Uniform(0),jitterOffset:new n.Uniform(new n.Vector2),varianceGamma:new n.Uniform(2),temporalAlpha:new n.Uniform(.1)}}),this.temporalUpscale=!0,this.shadowLength=!0}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}onBeforeRender(e,t,a,i,r,s){const h=this.uniforms.frame.value%16,d=ie[h],p=(d.x-.5)*4,f=(d.y-.5)*4;this.uniforms.jitterOffset.value.set(p,f)}}ce([u.define("TEMPORAL_UPSCALE")],k.prototype,"temporalUpscale");ce([u.define("SHADOW_LENGTH")],k.prototype,"shadowLength");class le extends C.Pass{constructor(e,t){super(e),this._mainCamera=new n.Camera;const{shadow:a}=t;this.shadow=a}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e}}function W(o,{depthVelocity:e,shadowLength:t}){const a=new n.WebGLRenderTarget(1,1,{depthBuffer:!1,type:n.HalfFloatType});a.texture.minFilter=n.LinearFilter,a.texture.magFilter=n.LinearFilter,a.texture.name=o;let i;e&&(i=a.texture.clone(),i.isRenderTargetTexture=!0,a.depthVelocity=i,a.textures.push(i));let r;return t&&(r=a.texture.clone(),r.isRenderTargetTexture=!0,r.format=n.RedFormat,a.shadowLength=r,a.textures.push(r)),Object.assign(a,{depthVelocity:i??null,shadowLength:r??null})}class He extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...i},r){super("CloudsPass",i),this.atmosphere=r,this.width=0,this.height=0,this.currentMaterial=new g({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},r),this.currentPass=new C.ShaderPass(this.currentMaterial),this.resolveMaterial=new k,this.resolvePass=new C.ShaderPass(this.resolveMaterial),this.initRenderTargets({depthVelocity:!0,shadowLength:c.lightShafts})}copyCameraSettings(e){this.currentMaterial.copyCameraSettings(e)}initialize(e,t,a){this.currentPass.initialize(e,t,a),this.resolvePass.initialize(e,t,a)}initRenderTargets(e){var s,l,h;(s=this.currentRenderTarget)==null||s.dispose(),(l=this.resolveRenderTarget)==null||l.dispose(),(h=this.historyRenderTarget)==null||h.dispose();const t=W("Clouds",e),a=W("Clouds.A",{...e,depthVelocity:!1}),i=W("Clouds.B",{...e,depthVelocity:!1});this.currentRenderTarget=t,this.resolveRenderTarget=a,this.historyRenderTarget=i;const r=this.resolveMaterial.uniforms;r.colorBuffer.value=t.texture,r.depthVelocityBuffer.value=t.depthVelocity,r.shadowLengthBuffer.value=t.shadowLength,r.colorHistoryBuffer.value=i.texture,r.shadowLengthHistoryBuffer.value=i.shadowLength}copyShadow(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.shadowIntervals.value[a].copy(i.interval),t.shadowMatrices.value[a].copy(i.matrix)}t.shadowFar.value=e.far}copyReprojection(){this.currentMaterial.copyReprojectionMatrix(this.mainCamera)}swapBuffers(){const e=this.historyRenderTarget,t=this.resolveRenderTarget;this.resolveRenderTarget=e,this.historyRenderTarget=t;const a=this.resolveMaterial.uniforms;a.colorHistoryBuffer.value=t.texture,a.shadowLengthHistoryBuffer.value=t.shadowLength}update(e,t,a){this.currentMaterial.uniforms.frame.value=t,this.resolveMaterial.uniforms.frame.value=t,this.copyCameraSettings(this.mainCamera),this.copyShadow(),this.currentPass.render(e,null,this.currentRenderTarget),this.resolvePass.render(e,null,this.resolveRenderTarget),this.copyReprojection(),this.swapBuffers()}setSize(e,t){if(this.width=e,this.height=t,this.temporalUpscale){const a=Math.ceil(e/4),i=Math.ceil(t/4);this.currentRenderTarget.setSize(a,i),this.currentMaterial.setSize(a*4,i*4,e,t)}else this.currentRenderTarget.setSize(e,t),this.currentMaterial.setSize(e,t);this.resolveRenderTarget.setSize(e,t),this.resolveMaterial.setSize(e,t),this.historyRenderTarget.setSize(e,t)}setShadowSize(e,t,a){this.currentMaterial.shadowCascadeCount=a,this.currentMaterial.setShadowSize(e,t)}setDepthTexture(e,t){this.currentMaterial.depthBuffer=e,this.currentMaterial.depthPacking=t??0}get outputBuffer(){return this.historyRenderTarget.texture}get shadowBuffer(){return this.currentMaterial.uniforms.shadowBuffer.value}set shadowBuffer(e){this.currentMaterial.uniforms.shadowBuffer.value=e}get shadowLengthBuffer(){return this.historyRenderTarget.shadowLength}get temporalUpscale(){return this.currentMaterial.temporalUpscale}set temporalUpscale(e){e!==this.temporalUpscale&&(this.currentMaterial.temporalUpscale=e,this.resolveMaterial.temporalUpscale=e,this.setSize(this.width,this.height))}get lightShafts(){return this.currentMaterial.shadowLength}set lightShafts(e){e!==this.lightShafts&&(this.currentMaterial.shadowLength=e,this.resolveMaterial.shadowLength=e,this.initRenderTargets({depthVelocity:!0,shadowLength:e}),this.setSize(this.width,this.height))}}function Fe(o,e){const a=o.properties.get(e.texture).__webglTexture,i=o.getContext();D(i instanceof WebGL2RenderingContext),o.setRenderTarget(e);const r=[];if(a!=null)for(let s=0;s<e.depth;++s)i.framebufferTextureLayer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+s,a,0,s),r.push(i.COLOR_ATTACHMENT0+s);i.drawBuffers(r)}class ae extends C.ShaderPass{render(e,t,a,i,r){const s=this.fullscreenMaterial.uniforms;t!==null&&(s==null?void 0:s[this.input])!=null&&(s[this.input].value=t.texture),Fe(e,a),e.render(this.scene,this.camera)}}const ze=`precision highp float;
1791
1806
  precision highp sampler3D;
1792
1807
 
1793
1808
  #include <common>
@@ -2000,7 +2015,7 @@ void main() {
2000
2015
 
2001
2016
  gl_Position = vec4(position.xy, 1.0, 1.0);
2002
2017
  }
2003
- `,Ge=`// Implements Structured Volume Sampling in fragment shader:
2018
+ `,Be=`// Implements Structured Volume Sampling in fragment shader:
2004
2019
  // https://github.com/huwb/volsample
2005
2020
  // Implementation reference:
2006
2021
  // https://www.shadertoy.com/view/ttVfDc
@@ -2101,11 +2116,11 @@ void intersectStructuredPlanes(
2101
2116
  stepOffset += stepSize;
2102
2117
  }
2103
2118
  }
2104
- `;var Be=Object.defineProperty,_=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Be(e,t,i),i};class E extends n.RawShaderMaterial{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a}){super({name:"ShadowMaterial",glslVersion:n.GLSL3,vertexShader:We,fragmentShader:h.unrollLoops(h.resolveIncludes(ze,{core:{math:y.math,raySphereIntersection:y.raySphereIntersection},types:V,parameters:oe,structuredSampling:Ge,clouds:re})),uniforms:{...e,...t,...a,inverseShadowMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),reprojectionMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),resolution:new n.Uniform(new n.Vector2),frame:new n.Uniform(0),stbnTexture:new n.Uniform(null),maxIterationCount:new n.Uniform(c.shadow.maxIterationCount),minStepSize:new n.Uniform(c.shadow.minStepSize),maxStepSize:new n.Uniform(c.shadow.maxStepSize),minDensity:new n.Uniform(c.shadow.minDensity),minExtinction:new n.Uniform(c.shadow.minExtinction),minTransmittance:new n.Uniform(c.shadow.minTransmittance),opticalDepthTailScale:new n.Uniform(2)},defines:{SHADOW:"1",TEMPORAL_PASS:"1",TEMPORAL_JITTER:"1"}}),this.localWeatherChannels="rgba",this.cascadeCount=c.shadow.cascadeCount,this.temporalPass=!0,this.temporalJitter=!0,this.shapeDetail=c.shapeDetail,this.turbulence=c.turbulence,this.cascadeCount=c.shadow.cascadeCount}setSize(e,t){this.uniforms.resolution.value.set(e,t)}}_([h.defineExpression("LOCAL_WEATHER_CHANNELS",{validate:o=>/^[rgba]{4}$/.test(o)})],E.prototype,"localWeatherChannels");_([h.defineInt("CASCADE_COUNT",{min:1,max:4})],E.prototype,"cascadeCount");_([h.define("TEMPORAL_PASS")],E.prototype,"temporalPass");_([h.define("TEMPORAL_JITTER")],E.prototype,"temporalJitter");_([h.define("SHAPE_DETAIL")],E.prototype,"shapeDetail");_([h.define("TURBULENCE")],E.prototype,"turbulence");const Ve=`precision highp float;
2119
+ `;var Ge=Object.defineProperty,O=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Ge(e,t,i),i};class E extends n.RawShaderMaterial{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a}){super({name:"ShadowMaterial",glslVersion:n.GLSL3,vertexShader:We,fragmentShader:u.unrollLoops(u.resolveIncludes(ze,{core:{math:y.math,raySphereIntersection:y.raySphereIntersection},types:V,parameters:oe,structuredSampling:Be,clouds:re})),uniforms:{...e,...t,...a,inverseShadowMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),reprojectionMatrices:new n.Uniform(Array.from({length:4},()=>new n.Matrix4)),resolution:new n.Uniform(new n.Vector2),frame:new n.Uniform(0),stbnTexture:new n.Uniform(null),maxIterationCount:new n.Uniform(c.shadow.maxIterationCount),minStepSize:new n.Uniform(c.shadow.minStepSize),maxStepSize:new n.Uniform(c.shadow.maxStepSize),minDensity:new n.Uniform(c.shadow.minDensity),minExtinction:new n.Uniform(c.shadow.minExtinction),minTransmittance:new n.Uniform(c.shadow.minTransmittance),opticalDepthTailScale:new n.Uniform(2)},defines:{SHADOW:"1",TEMPORAL_PASS:"1",TEMPORAL_JITTER:"1"}}),this.localWeatherChannels="rgba",this.cascadeCount=c.shadow.cascadeCount,this.temporalPass=!0,this.temporalJitter=!0,this.shapeDetail=c.shapeDetail,this.turbulence=c.turbulence,this.cascadeCount=c.shadow.cascadeCount}setSize(e,t){this.uniforms.resolution.value.set(e,t)}}O([u.defineExpression("LOCAL_WEATHER_CHANNELS",{validate:o=>/^[rgba]{4}$/.test(o)})],E.prototype,"localWeatherChannels");O([u.defineInt("CASCADE_COUNT",{min:1,max:4})],E.prototype,"cascadeCount");O([u.define("TEMPORAL_PASS")],E.prototype,"temporalPass");O([u.define("TEMPORAL_JITTER")],E.prototype,"temporalJitter");O([u.define("SHAPE_DETAIL")],E.prototype,"shapeDetail");O([u.define("TURBULENCE")],E.prototype,"turbulence");const Ve=`precision highp float;
2105
2120
  precision highp sampler2DArray;
2106
2121
 
2107
- #define VARIANCE_9_SAMPLES (1)
2108
- #define VARIANCE_SAMPLER_ARRAY (1)
2122
+ #define VARIANCE_9_SAMPLES 1
2123
+ #define VARIANCE_SAMPLER_ARRAY 1
2109
2124
 
2110
2125
  #include "varianceClipping"
2111
2126
 
@@ -2187,7 +2202,7 @@ void main() {
2187
2202
  vUv = position.xy * 0.5 + 0.5;
2188
2203
  gl_Position = vec4(position.xy, 1.0, 1.0);
2189
2204
  }
2190
- `;var je=Object.defineProperty,Ye=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&je(e,t,i),i};class he extends n.RawShaderMaterial{constructor({inputBuffer:e=null,historyBuffer:t=null}={}){super({name:"ShadowResolveMaterial",glslVersion:n.GLSL3,vertexShader:ke,fragmentShader:h.unrollLoops(h.resolveIncludes(Ve,{varianceClipping:se})),uniforms:{inputBuffer:new n.Uniform(e),historyBuffer:new n.Uniform(t),texelSize:new n.Uniform(new n.Vector2),varianceGamma:new n.Uniform(1),temporalAlpha:new n.Uniform(.01)},defines:{}}),this.cascadeCount=c.shadow.cascadeCount}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}}Ye([h.defineInt("CASCADE_COUNT",{min:1,max:4})],he.prototype,"cascadeCount");function G(o){const e=new n.WebGLArrayRenderTarget(1,1,1,{depthBuffer:!1,stencilBuffer:!1});return e.texture.type=n.HalfFloatType,e.texture.minFilter=n.LinearFilter,e.texture.magFilter=n.LinearFilter,e.texture.name=o,e}class qe extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...i}){super("ShadowPass",i),this.width=0,this.height=0,this.currentMaterial=new E({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a}),this.currentPass=new ae(this.currentMaterial),this.resolveMaterial=new he,this.resolvePass=new ae(this.resolveMaterial),this.initRenderTargets()}initialize(e,t,a){this.currentPass.initialize(e,t,a),this.resolvePass.initialize(e,t,a)}initRenderTargets(){var r,s,l;(r=this.currentRenderTarget)==null||r.dispose(),(s=this.resolveRenderTarget)==null||s.dispose(),(l=this.historyRenderTarget)==null||l.dispose();const e=G("Shadow"),t=this.temporalPass?G("Shadow.A"):null,a=this.temporalPass?G("Shadow.B"):null;this.currentRenderTarget=e,this.resolveRenderTarget=t,this.historyRenderTarget=a;const i=this.resolveMaterial.uniforms;i.inputBuffer.value=e.texture,i.historyBuffer.value=(a==null?void 0:a.texture)??null}copyShadow(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.inverseShadowMatrices.value[a].copy(i.inverseMatrix)}}copyReprojection(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.reprojectionMatrices.value[a].copy(i.matrix)}}swapBuffers(){D(this.historyRenderTarget!=null),D(this.resolveRenderTarget!=null);const e=this.historyRenderTarget,t=this.resolveRenderTarget;this.resolveRenderTarget=e,this.historyRenderTarget=t,this.resolveMaterial.uniforms.historyBuffer.value=t.texture}update(e,t,a){this.currentMaterial.uniforms.frame.value=t,this.copyShadow(),this.currentPass.render(e,null,this.currentRenderTarget),this.temporalPass&&(D(this.resolveRenderTarget!=null),this.resolvePass.render(e,null,this.resolveRenderTarget),this.copyReprojection(),this.swapBuffers())}setSize(e,t,a=this.shadow.cascadeCount){var i,r;this.width=e,this.height=t,this.currentMaterial.cascadeCount=a,this.resolveMaterial.cascadeCount=a,this.currentMaterial.setSize(e,t),this.resolveMaterial.setSize(e,t),this.currentRenderTarget.setSize(e,t,this.temporalPass?a*2:a),(i=this.resolveRenderTarget)==null||i.setSize(e,t,a),(r=this.historyRenderTarget)==null||r.setSize(e,t,a)}get outputBuffer(){return this.temporalPass?(D(this.historyRenderTarget!=null),this.historyRenderTarget.texture):this.currentRenderTarget.texture}get temporalPass(){return this.currentMaterial.temporalPass}set temporalPass(e){e!==this.temporalPass&&(this.currentMaterial.temporalPass=e,this.initRenderTargets(),this.setSize(this.width,this.height))}}function Ze(o){return{scatteringCoefficient:new n.Uniform(1),absorptionCoefficient:new n.Uniform(0),coverage:new n.Uniform(.3),localWeatherTexture:new n.Uniform(o.localWeatherTexture),localWeatherRepeat:new n.Uniform(o.localWeatherRepeat),localWeatherOffset:new n.Uniform(o.localWeatherOffset),shapeTexture:new n.Uniform(o.shapeTexture),shapeRepeat:new n.Uniform(o.shapeRepeat),shapeOffset:new n.Uniform(o.shapeOffset),shapeDetailTexture:new n.Uniform(o.shapeDetailTexture),shapeDetailRepeat:new n.Uniform(o.shapeDetailRepeat),shapeDetailOffset:new n.Uniform(o.shapeDetailOffset),turbulenceTexture:new n.Uniform(o.turbulenceTexture),turbulenceRepeat:new n.Uniform(o.turbulenceRepeat),turbulenceDisplacement:new n.Uniform(350)}}function Ke(){return{minLayerHeights:new n.Uniform(new n.Vector4),maxLayerHeights:new n.Uniform(new n.Vector4),minIntervalHeights:new n.Uniform(new n.Vector3),maxIntervalHeights:new n.Uniform(new n.Vector3),densityScales:new n.Uniform(new n.Vector4),shapeAmounts:new n.Uniform(new n.Vector4),shapeDetailAmounts:new n.Uniform(new n.Vector4),weatherExponents:new n.Uniform(new n.Vector4),shapeAlteringBiases:new n.Uniform(new n.Vector4),coverageFilterWidths:new n.Uniform(new n.Vector4),minHeight:new n.Uniform(0),maxHeight:new n.Uniform(0),shadowTopHeight:new n.Uniform(0),shadowBottomHeight:new n.Uniform(0),shadowLayerMask:new n.Uniform(new n.Vector4),densityProfile:new n.Uniform({expTerms:new n.Vector4,exponents:new n.Vector4,linearTerms:new n.Vector4,constantTerms:new n.Vector4})}}const B=[0,0,0,0];function Xe(o,e){e.packValues("altitude",o.minLayerHeights.value),e.packSums("altitude","height",o.maxLayerHeights.value),e.packIntervalHeights(o.minIntervalHeights.value,o.maxIntervalHeights.value),e.packValues("densityScale",o.densityScales.value),e.packValues("shapeAmount",o.shapeAmounts.value),e.packValues("shapeDetailAmount",o.shapeDetailAmounts.value),e.packValues("weatherExponent",o.weatherExponents.value),e.packValues("shapeAlteringBias",o.shapeAlteringBiases.value),e.packValues("coverageFilterWidth",o.coverageFilterWidths.value);const t=o.densityProfile.value;e.packDensityProfiles("expTerm",t.expTerms),e.packDensityProfiles("exponent",t.exponents),e.packDensityProfiles("linearTerm",t.linearTerms),e.packDensityProfiles("constantTerm",t.constantTerms);let a=1/0,i=0,r=1/0,s=0;B.fill(0);for(let l=0;l<e.length;++l){const{altitude:u,height:d,shadow:p}=e[l],f=u+d;d>0&&(u<a&&(a=u),p&&u<r&&(r=u),f>i&&(i=f),p&&f>s&&(s=f)),B[l]=p?1:0}a!==1/0?(o.minHeight.value=a,o.maxHeight.value=i):(D(i===0),o.minHeight.value=0),r!==1/0?(o.shadowBottomHeight.value=r,o.shadowTopHeight.value=s):(D(s===0),o.shadowBottomHeight.value=0),o.shadowLayerMask.value.fromArray(B)}function $e(o,e){return{bottomRadius:new n.Uniform(o.bottomRadius),topRadius:new n.Uniform(o.topRadius),ellipsoidCenter:new n.Uniform(e.ellipsoidCenter),ellipsoidMatrix:new n.Uniform(e.ellipsoidMatrix),inverseEllipsoidMatrix:new n.Uniform(e.inverseEllipsoidMatrix),altitudeCorrection:new n.Uniform(e.altitudeCorrection),sunDirection:new n.Uniform(e.sunDirection)}}const Je=`uniform sampler2D cloudsBuffer;
2205
+ `;var je=Object.defineProperty,Ye=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&je(e,t,i),i};class ue extends n.RawShaderMaterial{constructor({inputBuffer:e=null,historyBuffer:t=null}={}){super({name:"ShadowResolveMaterial",glslVersion:n.GLSL3,vertexShader:ke,fragmentShader:u.unrollLoops(u.resolveIncludes(Ve,{varianceClipping:se})),uniforms:{inputBuffer:new n.Uniform(e),historyBuffer:new n.Uniform(t),texelSize:new n.Uniform(new n.Vector2),varianceGamma:new n.Uniform(1),temporalAlpha:new n.Uniform(.01)},defines:{}}),this.cascadeCount=c.shadow.cascadeCount}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}}Ye([u.defineInt("CASCADE_COUNT",{min:1,max:4})],ue.prototype,"cascadeCount");function B(o){const e=new n.WebGLArrayRenderTarget(1,1,1,{depthBuffer:!1});return e.texture.type=n.HalfFloatType,e.texture.minFilter=n.LinearFilter,e.texture.magFilter=n.LinearFilter,e.texture.name=o,e}class qe extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...i}){super("ShadowPass",i),this.width=0,this.height=0,this.currentMaterial=new E({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a}),this.currentPass=new ae(this.currentMaterial),this.resolveMaterial=new ue,this.resolvePass=new ae(this.resolveMaterial),this.initRenderTargets()}initialize(e,t,a){this.currentPass.initialize(e,t,a),this.resolvePass.initialize(e,t,a)}initRenderTargets(){var r,s,l;(r=this.currentRenderTarget)==null||r.dispose(),(s=this.resolveRenderTarget)==null||s.dispose(),(l=this.historyRenderTarget)==null||l.dispose();const e=B("Shadow"),t=this.temporalPass?B("Shadow.A"):null,a=this.temporalPass?B("Shadow.B"):null;this.currentRenderTarget=e,this.resolveRenderTarget=t,this.historyRenderTarget=a;const i=this.resolveMaterial.uniforms;i.inputBuffer.value=e.texture,i.historyBuffer.value=(a==null?void 0:a.texture)??null}copyShadow(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.inverseShadowMatrices.value[a].copy(i.inverseMatrix)}}copyReprojection(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const i=e.cascades[a];t.reprojectionMatrices.value[a].copy(i.matrix)}}swapBuffers(){D(this.historyRenderTarget!=null),D(this.resolveRenderTarget!=null);const e=this.historyRenderTarget,t=this.resolveRenderTarget;this.resolveRenderTarget=e,this.historyRenderTarget=t,this.resolveMaterial.uniforms.historyBuffer.value=t.texture}update(e,t,a){this.currentMaterial.uniforms.frame.value=t,this.copyShadow(),this.currentPass.render(e,null,this.currentRenderTarget),this.temporalPass&&(D(this.resolveRenderTarget!=null),this.resolvePass.render(e,null,this.resolveRenderTarget),this.copyReprojection(),this.swapBuffers())}setSize(e,t,a=this.shadow.cascadeCount){var i,r;this.width=e,this.height=t,this.currentMaterial.cascadeCount=a,this.resolveMaterial.cascadeCount=a,this.currentMaterial.setSize(e,t),this.resolveMaterial.setSize(e,t),this.currentRenderTarget.setSize(e,t,this.temporalPass?a*2:a),(i=this.resolveRenderTarget)==null||i.setSize(e,t,a),(r=this.historyRenderTarget)==null||r.setSize(e,t,a)}get outputBuffer(){return this.temporalPass?(D(this.historyRenderTarget!=null),this.historyRenderTarget.texture):this.currentRenderTarget.texture}get temporalPass(){return this.currentMaterial.temporalPass}set temporalPass(e){e!==this.temporalPass&&(this.currentMaterial.temporalPass=e,this.initRenderTargets(),this.setSize(this.width,this.height))}}function Ze(o){return{scatteringCoefficient:new n.Uniform(1),absorptionCoefficient:new n.Uniform(0),coverage:new n.Uniform(.3),localWeatherTexture:new n.Uniform(o.localWeatherTexture),localWeatherRepeat:new n.Uniform(o.localWeatherRepeat),localWeatherOffset:new n.Uniform(o.localWeatherOffset),shapeTexture:new n.Uniform(o.shapeTexture),shapeRepeat:new n.Uniform(o.shapeRepeat),shapeOffset:new n.Uniform(o.shapeOffset),shapeDetailTexture:new n.Uniform(o.shapeDetailTexture),shapeDetailRepeat:new n.Uniform(o.shapeDetailRepeat),shapeDetailOffset:new n.Uniform(o.shapeDetailOffset),turbulenceTexture:new n.Uniform(o.turbulenceTexture),turbulenceRepeat:new n.Uniform(o.turbulenceRepeat),turbulenceDisplacement:new n.Uniform(350)}}function Ke(){return{minLayerHeights:new n.Uniform(new n.Vector4),maxLayerHeights:new n.Uniform(new n.Vector4),minIntervalHeights:new n.Uniform(new n.Vector3),maxIntervalHeights:new n.Uniform(new n.Vector3),densityScales:new n.Uniform(new n.Vector4),shapeAmounts:new n.Uniform(new n.Vector4),shapeDetailAmounts:new n.Uniform(new n.Vector4),weatherExponents:new n.Uniform(new n.Vector4),shapeAlteringBiases:new n.Uniform(new n.Vector4),coverageFilterWidths:new n.Uniform(new n.Vector4),minHeight:new n.Uniform(0),maxHeight:new n.Uniform(0),shadowTopHeight:new n.Uniform(0),shadowBottomHeight:new n.Uniform(0),shadowLayerMask:new n.Uniform(new n.Vector4),densityProfile:new n.Uniform({expTerms:new n.Vector4,exponents:new n.Vector4,linearTerms:new n.Vector4,constantTerms:new n.Vector4})}}const G=[0,0,0,0];function Xe(o,e){e.packValues("altitude",o.minLayerHeights.value),e.packSums("altitude","height",o.maxLayerHeights.value),e.packIntervalHeights(o.minIntervalHeights.value,o.maxIntervalHeights.value),e.packValues("densityScale",o.densityScales.value),e.packValues("shapeAmount",o.shapeAmounts.value),e.packValues("shapeDetailAmount",o.shapeDetailAmounts.value),e.packValues("weatherExponent",o.weatherExponents.value),e.packValues("shapeAlteringBias",o.shapeAlteringBiases.value),e.packValues("coverageFilterWidth",o.coverageFilterWidths.value);const t=o.densityProfile.value;e.packDensityProfiles("expTerm",t.expTerms),e.packDensityProfiles("exponent",t.exponents),e.packDensityProfiles("linearTerm",t.linearTerms),e.packDensityProfiles("constantTerm",t.constantTerms);let a=1/0,i=0,r=1/0,s=0;G.fill(0);for(let l=0;l<e.length;++l){const{altitude:h,height:d,shadow:p}=e[l],f=h+d;d>0&&(h<a&&(a=h),p&&h<r&&(r=h),f>i&&(i=f),p&&f>s&&(s=f)),G[l]=p?1:0}a!==1/0?(o.minHeight.value=a,o.maxHeight.value=i):(D(i===0),o.minHeight.value=0),r!==1/0?(o.shadowBottomHeight.value=r,o.shadowTopHeight.value=s):(D(s===0),o.shadowBottomHeight.value=0),o.shadowLayerMask.value.fromArray(G)}function $e(o,e){return{bottomRadius:new n.Uniform(o.bottomRadius),topRadius:new n.Uniform(o.topRadius),ellipsoidCenter:new n.Uniform(e.ellipsoidCenter),ellipsoidMatrix:new n.Uniform(e.ellipsoidMatrix),inverseEllipsoidMatrix:new n.Uniform(e.inverseEllipsoidMatrix),altitudeCorrection:new n.Uniform(e.altitudeCorrection),sunDirection:new n.Uniform(e.sunDirection)}}const Je=`uniform sampler2D cloudsBuffer;
2191
2206
 
2192
2207
  void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
2193
2208
  #ifdef SKIP_RENDERING
@@ -2198,5 +2213,5 @@ void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
2198
2213
  outputColor.a = inputColor.a * (1.0 - clouds.a) + clouds.a;
2199
2214
  #endif // SKIP_RENDERING
2200
2215
  }
2201
- `;var Qe=Object.defineProperty,et=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Qe(e,t,i),i};const O=new n.Vector3,tt=new n.Vector2,nt=["maxIterationCount","minStepSize","maxStepSize","maxRayDistance","perspectiveStepScale","minDensity","minExtinction","minTransmittance","maxIterationCountToSun","maxIterationCountToGround","minSecondaryStepSize","secondaryStepScale","maxShadowFilterRadius","maxShadowLengthIterationCount","minShadowLengthStepSize","maxShadowLengthRayDistance","hazeDensityScale","hazeExponent","hazeScatteringCoefficient","hazeAbsorptionCoefficient"],at=["multiScatteringOctaves","accurateSunSkyIrradiance","accuratePhaseFunction"],it=["maxIterationCount","minStepSize","maxStepSize","minDensity","minExtinction","minTransmittance","opticalDepthTailScale"],rt=["temporalJitter"],ot=["temporalPass"],st=["cascadeCount","mapSize","maxFar","farScale","splitMode","splitLambda"],w={type:"change"},ue={resolutionScale:c.resolutionScale,width:C.Resolution.AUTO_SIZE,height:C.Resolution.AUTO_SIZE};class de extends C.Effect{constructor(e=new n.Camera,t,a=H.AtmosphereParameters.DEFAULT){var p,f,m,v;super("CloudsEffect",Je,{attributes:C.EffectAttribute.DEPTH,uniforms:new Map([["cloudsBuffer",new n.Uniform(null)]])}),this.camera=e,this.atmosphere=a,this.cloudLayers=F.DEFAULT.clone(),this.correctAltitude=!0,this.localWeatherRepeat=new n.Vector2().setScalar(100),this.localWeatherOffset=new n.Vector2,this.shapeRepeat=new n.Vector3().setScalar(3e-4),this.shapeOffset=new n.Vector3,this.shapeDetailRepeat=new n.Vector3().setScalar(.006),this.shapeDetailOffset=new n.Vector3,this.turbulenceRepeat=new n.Vector2().setScalar(20),this.ellipsoidCenter=new n.Vector3,this.ellipsoidMatrix=new n.Matrix4,this.inverseEllipsoidMatrix=new n.Matrix4,this.altitudeCorrection=new n.Vector3,this.sunDirection=new n.Vector3,this.localWeatherVelocity=new n.Vector2,this.shapeVelocity=new n.Vector3,this.shapeDetailVelocity=new n.Vector3,this._atmosphereOverlay=null,this._atmosphereShadow=null,this._atmosphereShadowLength=null,this.events=new n.EventDispatcher,this.frame=0,this.shadowCascadeCount=0,this.shadowMapSize=new n.Vector2,this.onResolutionChange=()=>{this.setSize(this.resolution.baseWidth,this.resolution.baseHeight)},this.skipRendering=!0;const{resolutionScale:i,width:r,height:s,resolutionX:l=r,resolutionY:u=s}={...ue,...t};this.shadowMaps=new Ee({cascadeCount:c.shadow.cascadeCount,mapSize:c.shadow.mapSize,splitLambda:.6}),this.parameterUniforms=Ze({localWeatherTexture:((p=this.proceduralLocalWeather)==null?void 0:p.texture)??null,localWeatherRepeat:this.localWeatherRepeat,localWeatherOffset:this.localWeatherOffset,shapeTexture:((f=this.proceduralShape)==null?void 0:f.texture)??null,shapeRepeat:this.shapeRepeat,shapeOffset:this.shapeOffset,shapeDetailTexture:((m=this.proceduralShapeDetail)==null?void 0:m.texture)??null,shapeDetailRepeat:this.shapeDetailRepeat,shapeDetailOffset:this.shapeDetailOffset,turbulenceTexture:((v=this.proceduralTurbulence)==null?void 0:v.texture)??null,turbulenceRepeat:this.turbulenceRepeat}),this.layerUniforms=Ke(),this.atmosphereUniforms=$e(a,{ellipsoidCenter:this.ellipsoidCenter,ellipsoidMatrix:this.ellipsoidMatrix,inverseEllipsoidMatrix:this.inverseEllipsoidMatrix,altitudeCorrection:this.altitudeCorrection,sunDirection:this.sunDirection});const d={shadow:this.shadowMaps,parameterUniforms:this.parameterUniforms,layerUniforms:this.layerUniforms,atmosphereUniforms:this.atmosphereUniforms};this.shadowPass=new qe(d),this.shadowPass.mainCamera=e,this.cloudsPass=new He(d,a),this.cloudsPass.mainCamera=e,this.clouds=h.definePropertyShorthand(h.defineUniformShorthand({},this.cloudsPass.currentMaterial,nt),this.cloudsPass.currentMaterial,at),this.shadow=h.definePropertyShorthand(h.defineUniformShorthand({},this.shadowPass.currentMaterial,it),this.shadowPass.currentMaterial,rt,this.shadowPass,ot,this.shadowMaps,st),this.resolution=new C.Resolution(this,l,u,i),this.resolution.addEventListener("change",this.onResolutionChange)}get mainCamera(){return this.camera}set mainCamera(e){this.camera=e,this.shadowPass.mainCamera=e,this.cloudsPass.mainCamera=e}initialize(e,t,a){this.shadowPass.initialize(e,t,a),this.cloudsPass.initialize(e,t,a)}updateSharedUniforms(e){Xe(this.layerUniforms,this.cloudLayers);const{parameterUniforms:t}=this;t.localWeatherOffset.value.add(tt.copy(this.localWeatherVelocity).multiplyScalar(e)),t.shapeOffset.value.add(O.copy(this.shapeVelocity).multiplyScalar(e)),t.shapeDetailOffset.value.add(O.copy(this.shapeDetailVelocity).multiplyScalar(e));const a=this.inverseEllipsoidMatrix.copy(this.ellipsoidMatrix).invert(),i=this.camera.getWorldPosition(O).applyMatrix4(a).sub(this.ellipsoidCenter),r=this.altitudeCorrection;this.correctAltitude?H.getAltitudeCorrectionOffset(i,this.atmosphere.bottomRadius,this.ellipsoid,r,!1):r.setScalar(0);const s=this.ellipsoid.getSurfaceNormal(i,O),l=this.sunDirection.dot(s),u=h.lerp(1e6,1e3,l);this.shadowMaps.update(this.camera,O.copy(this.sunDirection).applyMatrix4(this.ellipsoidMatrix),u)}updateWeatherTextureChannels(){const e=this.cloudLayers.localWeatherChannels;this.cloudsPass.currentMaterial.localWeatherChannels=e,this.shadowPass.currentMaterial.localWeatherChannels=e}updateAtmosphereComposition(){const{shadowMaps:e,shadowPass:t,cloudsPass:a}=this,i=t.currentMaterial.uniforms,r=a.currentMaterial.uniforms,s=this._atmosphereOverlay,l=Object.assign(this._atmosphereOverlay??{},{map:a.outputBuffer});s!==l&&(this._atmosphereOverlay=l,w.target=this,w.property="atmosphereOverlay",this.events.dispatchEvent(w));const u=this._atmosphereShadow,d=Object.assign(this._atmosphereShadow??{},{map:t.outputBuffer,mapSize:e.mapSize,cascadeCount:e.cascadeCount,intervals:r.shadowIntervals.value,matrices:r.shadowMatrices.value,inverseMatrices:i.inverseShadowMatrices.value,far:e.far,topHeight:r.shadowTopHeight.value});u!==d&&(this._atmosphereShadow=d,w.target=this,w.property="atmosphereShadow",this.events.dispatchEvent(w));const p=this._atmosphereShadowLength,f=a.shadowLengthBuffer!=null?Object.assign(this._atmosphereShadowLength??{},{map:a.shadowLengthBuffer}):null;p!==f&&(this._atmosphereShadowLength=f,w.target=this,w.property="atmosphereShadowLength",this.events.dispatchEvent(w))}update(e,t,a=0){var l,u,d,p;const{shadowMaps:i,shadowPass:r,cloudsPass:s}=this;if(i.cascadeCount!==this.shadowCascadeCount||!i.mapSize.equals(this.shadowMapSize)){const{width:f,height:m}=i.mapSize,v=i.cascadeCount;this.shadowMapSize.set(f,m),this.shadowCascadeCount=v,r.setSize(f,m,v),s.setShadowSize(f,m,v)}(l=this.proceduralLocalWeather)==null||l.render(e,a),(u=this.proceduralShape)==null||u.render(e,a),(d=this.proceduralShapeDetail)==null||d.render(e,a),(p=this.proceduralTurbulence)==null||p.render(e,a),++this.frame,this.updateSharedUniforms(a),this.updateWeatherTextureChannels(),r.update(e,this.frame,a),s.shadowBuffer=r.outputBuffer,s.update(e,this.frame,a),this.updateAtmosphereComposition(),this.uniforms.get("cloudsBuffer").value=this.cloudsPass.outputBuffer}setSize(e,t){const{resolution:a}=this;a.setBaseSize(e,t);const{width:i,height:r}=a;this.cloudsPass.setSize(i,r)}setDepthTexture(e,t){this.shadowPass.setDepthTexture(e,t),this.cloudsPass.setDepthTexture(e,t)}set qualityPreset(e){const{clouds:t,shadow:a,...i}=_e[e];Object.assign(this,i),Object.assign(this.clouds,t),Object.assign(this.shadow,a)}get localWeatherTexture(){return this.proceduralLocalWeather??this.parameterUniforms.localWeatherTexture.value}set localWeatherTexture(e){e instanceof n.Texture||e==null?(this.proceduralLocalWeather=void 0,this.parameterUniforms.localWeatherTexture.value=e):(this.proceduralLocalWeather=e,this.parameterUniforms.localWeatherTexture.value=e.texture)}get shapeTexture(){return this.proceduralShape??this.parameterUniforms.shapeTexture.value}set shapeTexture(e){e instanceof n.Data3DTexture||e==null?(this.proceduralShape=void 0,this.parameterUniforms.shapeTexture.value=e):(this.proceduralShape=e,this.parameterUniforms.shapeTexture.value=e.texture)}get shapeDetailTexture(){return this.proceduralShapeDetail??this.parameterUniforms.shapeDetailTexture.value}set shapeDetailTexture(e){e instanceof n.Data3DTexture||e==null?(this.proceduralShapeDetail=void 0,this.parameterUniforms.shapeDetailTexture.value=e):(this.proceduralShapeDetail=e,this.parameterUniforms.shapeDetailTexture.value=e.texture)}get turbulenceTexture(){return this.proceduralTurbulence??this.parameterUniforms.turbulenceTexture.value}set turbulenceTexture(e){e instanceof n.Texture||e==null?(this.proceduralTurbulence=void 0,this.parameterUniforms.turbulenceTexture.value=e):(this.proceduralTurbulence=e,this.parameterUniforms.turbulenceTexture.value=e.texture)}get stbnTexture(){return this.cloudsPass.currentMaterial.uniforms.stbnTexture.value}set stbnTexture(e){this.cloudsPass.currentMaterial.uniforms.stbnTexture.value=e,this.shadowPass.currentMaterial.uniforms.stbnTexture.value=e}get resolutionScale(){return this.resolution.scale}set resolutionScale(e){this.resolution.scale=e}get temporalUpscale(){return this.cloudsPass.temporalUpscale}set temporalUpscale(e){this.cloudsPass.temporalUpscale=e}get lightShafts(){return this.cloudsPass.lightShafts}set lightShafts(e){this.cloudsPass.lightShafts=e}get shapeDetail(){return this.cloudsPass.currentMaterial.shapeDetail}set shapeDetail(e){this.cloudsPass.currentMaterial.shapeDetail=e,this.shadowPass.currentMaterial.shapeDetail=e}get turbulence(){return this.cloudsPass.currentMaterial.turbulence}set turbulence(e){this.cloudsPass.currentMaterial.turbulence=e,this.shadowPass.currentMaterial.turbulence=e}get haze(){return this.cloudsPass.currentMaterial.haze}set haze(e){this.cloudsPass.currentMaterial.haze=e}get scatteringCoefficient(){return this.parameterUniforms.scatteringCoefficient.value}set scatteringCoefficient(e){this.parameterUniforms.scatteringCoefficient.value=e}get absorptionCoefficient(){return this.parameterUniforms.absorptionCoefficient.value}set absorptionCoefficient(e){this.parameterUniforms.absorptionCoefficient.value=e}get coverage(){return this.parameterUniforms.coverage.value}set coverage(e){this.parameterUniforms.coverage.value=e}get turbulenceDisplacement(){return this.parameterUniforms.turbulenceDisplacement.value}set turbulenceDisplacement(e){this.parameterUniforms.turbulenceDisplacement.value=e}get scatterAnisotropy1(){return this.cloudsPass.currentMaterial.scatterAnisotropy1}set scatterAnisotropy1(e){this.cloudsPass.currentMaterial.scatterAnisotropy1=e}get scatterAnisotropy2(){return this.cloudsPass.currentMaterial.scatterAnisotropy2}set scatterAnisotropy2(e){this.cloudsPass.currentMaterial.scatterAnisotropy2=e}get scatterAnisotropyMix(){return this.cloudsPass.currentMaterial.scatterAnisotropyMix}set scatterAnisotropyMix(e){this.cloudsPass.currentMaterial.scatterAnisotropyMix=e}get skyIrradianceScale(){return this.cloudsPass.currentMaterial.uniforms.skyIrradianceScale.value}set skyIrradianceScale(e){this.cloudsPass.currentMaterial.uniforms.skyIrradianceScale.value=e}get groundIrradianceScale(){return this.cloudsPass.currentMaterial.uniforms.groundIrradianceScale.value}set groundIrradianceScale(e){this.cloudsPass.currentMaterial.uniforms.groundIrradianceScale.value=e}get powderScale(){return this.cloudsPass.currentMaterial.uniforms.powderScale.value}set powderScale(e){this.cloudsPass.currentMaterial.uniforms.powderScale.value=e}get powderExponent(){return this.cloudsPass.currentMaterial.uniforms.powderExponent.value}set powderExponent(e){this.cloudsPass.currentMaterial.uniforms.powderExponent.value=e}get atmosphereOverlay(){return this._atmosphereOverlay}get atmosphereShadow(){return this._atmosphereShadow}get atmosphereShadowLength(){return this._atmosphereShadowLength}get irradianceTexture(){return this.cloudsPass.currentMaterial.irradianceTexture}set irradianceTexture(e){this.cloudsPass.currentMaterial.irradianceTexture=e}get scatteringTexture(){return this.cloudsPass.currentMaterial.scatteringTexture}set scatteringTexture(e){this.cloudsPass.currentMaterial.scatteringTexture=e}get transmittanceTexture(){return this.cloudsPass.currentMaterial.transmittanceTexture}set transmittanceTexture(e){this.cloudsPass.currentMaterial.transmittanceTexture=e}get ellipsoid(){return this.cloudsPass.currentMaterial.ellipsoid}set ellipsoid(e){this.cloudsPass.currentMaterial.ellipsoid=e}get photometric(){return this.cloudsPass.currentMaterial.photometric}set photometric(e){this.cloudsPass.currentMaterial.photometric=e}get sunAngularRadius(){return this.cloudsPass.currentMaterial.sunAngularRadius}set sunAngularRadius(e){this.cloudsPass.currentMaterial.sunAngularRadius=e}}et([h.define("SKIP_RENDERING")],de.prototype,"skipRendering");const ct=128,lt=32,z="45a1c6c1bb9fd38b3680fd120795ff4c32df68ff",ht=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/local_weather.png`,ut=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/shape.bin`,dt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/shape_detail.bin`,pt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/turbulence.png`;exports.CLOUD_SHAPE_DETAIL_TEXTURE_SIZE=lt;exports.CLOUD_SHAPE_TEXTURE_SIZE=ct;exports.CloudLayer=x;exports.CloudLayers=F;exports.CloudsEffect=de;exports.DEFAULT_LOCAL_WEATHER_URL=ht;exports.DEFAULT_SHAPE_DETAIL_URL=dt;exports.DEFAULT_SHAPE_URL=ut;exports.DEFAULT_TURBULENCE_URL=pt;exports.DensityProfile=I;exports.cloudsPassOptionsDefaults=ue;
2216
+ `;var Qe=Object.defineProperty,et=(o,e,t,a)=>{for(var i=void 0,r=o.length-1,s;r>=0;r--)(s=o[r])&&(i=s(e,t,i)||i);return i&&Qe(e,t,i),i};const L=new n.Vector3,tt=new n.Vector2,nt=["maxIterationCount","minStepSize","maxStepSize","maxRayDistance","perspectiveStepScale","minDensity","minExtinction","minTransmittance","maxIterationCountToSun","maxIterationCountToGround","minSecondaryStepSize","secondaryStepScale","maxShadowFilterRadius","maxShadowLengthIterationCount","minShadowLengthStepSize","maxShadowLengthRayDistance","hazeDensityScale","hazeExponent","hazeScatteringCoefficient","hazeAbsorptionCoefficient"],at=["multiScatteringOctaves","accurateSunSkyLight","accuratePhaseFunction"],it=["maxIterationCount","minStepSize","maxStepSize","minDensity","minExtinction","minTransmittance","opticalDepthTailScale"],rt=["temporalJitter"],ot=["temporalPass"],st=["cascadeCount","mapSize","maxFar","farScale","splitMode","splitLambda"],w={type:"change"},he={resolutionScale:c.resolutionScale,width:C.Resolution.AUTO_SIZE,height:C.Resolution.AUTO_SIZE};class de extends C.Effect{constructor(e=new n.Camera,t,a=H.AtmosphereParameters.DEFAULT){var p,f,m,v;super("CloudsEffect",Je,{attributes:C.EffectAttribute.DEPTH,uniforms:new Map([["cloudsBuffer",new n.Uniform(null)]])}),this.camera=e,this.atmosphere=a,this.cloudLayers=F.DEFAULT.clone(),this.correctAltitude=!0,this.localWeatherRepeat=new n.Vector2().setScalar(100),this.localWeatherOffset=new n.Vector2,this.shapeRepeat=new n.Vector3().setScalar(3e-4),this.shapeOffset=new n.Vector3,this.shapeDetailRepeat=new n.Vector3().setScalar(.006),this.shapeDetailOffset=new n.Vector3,this.turbulenceRepeat=new n.Vector2().setScalar(20),this.ellipsoidCenter=new n.Vector3,this.ellipsoidMatrix=new n.Matrix4,this.inverseEllipsoidMatrix=new n.Matrix4,this.altitudeCorrection=new n.Vector3,this.sunDirection=new n.Vector3,this.localWeatherVelocity=new n.Vector2,this.shapeVelocity=new n.Vector3,this.shapeDetailVelocity=new n.Vector3,this._atmosphereOverlay=null,this._atmosphereShadow=null,this._atmosphereShadowLength=null,this.events=new n.EventDispatcher,this.frame=0,this.shadowCascadeCount=0,this.shadowMapSize=new n.Vector2,this.onResolutionChange=()=>{this.setSize(this.resolution.baseWidth,this.resolution.baseHeight)},this.skipRendering=!0;const{resolutionScale:i,width:r,height:s,resolutionX:l=r,resolutionY:h=s}={...he,...t};this.shadowMaps=new Ee({cascadeCount:c.shadow.cascadeCount,mapSize:c.shadow.mapSize,splitLambda:.6}),this.parameterUniforms=Ze({localWeatherTexture:((p=this.proceduralLocalWeather)==null?void 0:p.texture)??null,localWeatherRepeat:this.localWeatherRepeat,localWeatherOffset:this.localWeatherOffset,shapeTexture:((f=this.proceduralShape)==null?void 0:f.texture)??null,shapeRepeat:this.shapeRepeat,shapeOffset:this.shapeOffset,shapeDetailTexture:((m=this.proceduralShapeDetail)==null?void 0:m.texture)??null,shapeDetailRepeat:this.shapeDetailRepeat,shapeDetailOffset:this.shapeDetailOffset,turbulenceTexture:((v=this.proceduralTurbulence)==null?void 0:v.texture)??null,turbulenceRepeat:this.turbulenceRepeat}),this.layerUniforms=Ke(),this.atmosphereUniforms=$e(a,{ellipsoidCenter:this.ellipsoidCenter,ellipsoidMatrix:this.ellipsoidMatrix,inverseEllipsoidMatrix:this.inverseEllipsoidMatrix,altitudeCorrection:this.altitudeCorrection,sunDirection:this.sunDirection});const d={shadow:this.shadowMaps,parameterUniforms:this.parameterUniforms,layerUniforms:this.layerUniforms,atmosphereUniforms:this.atmosphereUniforms};this.shadowPass=new qe(d),this.shadowPass.mainCamera=e,this.cloudsPass=new He(d,a),this.cloudsPass.mainCamera=e,this.clouds=u.definePropertyShorthand(u.defineUniformShorthand({},this.cloudsPass.currentMaterial,nt),this.cloudsPass.currentMaterial,at),this.shadow=u.definePropertyShorthand(u.defineUniformShorthand({},this.shadowPass.currentMaterial,it),this.shadowPass.currentMaterial,rt,this.shadowPass,ot,this.shadowMaps,st),this.resolution=new C.Resolution(this,l,h,i),this.resolution.addEventListener("change",this.onResolutionChange)}get mainCamera(){return this.camera}set mainCamera(e){this.camera=e,this.shadowPass.mainCamera=e,this.cloudsPass.mainCamera=e}initialize(e,t,a){this.shadowPass.initialize(e,t,a),this.cloudsPass.initialize(e,t,a)}updateSharedUniforms(e){Xe(this.layerUniforms,this.cloudLayers);const{parameterUniforms:t}=this;t.localWeatherOffset.value.add(tt.copy(this.localWeatherVelocity).multiplyScalar(e)),t.shapeOffset.value.add(L.copy(this.shapeVelocity).multiplyScalar(e)),t.shapeDetailOffset.value.add(L.copy(this.shapeDetailVelocity).multiplyScalar(e));const a=this.inverseEllipsoidMatrix.copy(this.ellipsoidMatrix).invert(),i=this.camera.getWorldPosition(L).applyMatrix4(a).sub(this.ellipsoidCenter),r=this.altitudeCorrection;this.correctAltitude?H.getAltitudeCorrectionOffset(i,this.atmosphere.bottomRadius,this.ellipsoid,r,!1):r.setScalar(0);const s=this.ellipsoid.getSurfaceNormal(i,L),l=this.sunDirection.dot(s),h=u.lerp(1e6,1e3,l);this.shadowMaps.update(this.camera,L.copy(this.sunDirection).applyMatrix4(this.ellipsoidMatrix),h)}updateWeatherTextureChannels(){const e=this.cloudLayers.localWeatherChannels;this.cloudsPass.currentMaterial.localWeatherChannels=e,this.shadowPass.currentMaterial.localWeatherChannels=e}updateAtmosphereComposition(){const{shadowMaps:e,shadowPass:t,cloudsPass:a}=this,i=t.currentMaterial.uniforms,r=a.currentMaterial.uniforms,s=this._atmosphereOverlay,l=Object.assign(this._atmosphereOverlay??{},{map:a.outputBuffer});s!==l&&(this._atmosphereOverlay=l,w.target=this,w.property="atmosphereOverlay",this.events.dispatchEvent(w));const h=this._atmosphereShadow,d=Object.assign(this._atmosphereShadow??{},{map:t.outputBuffer,mapSize:e.mapSize,cascadeCount:e.cascadeCount,intervals:r.shadowIntervals.value,matrices:r.shadowMatrices.value,inverseMatrices:i.inverseShadowMatrices.value,far:e.far,topHeight:r.shadowTopHeight.value});h!==d&&(this._atmosphereShadow=d,w.target=this,w.property="atmosphereShadow",this.events.dispatchEvent(w));const p=this._atmosphereShadowLength,f=a.shadowLengthBuffer!=null?Object.assign(this._atmosphereShadowLength??{},{map:a.shadowLengthBuffer}):null;p!==f&&(this._atmosphereShadowLength=f,w.target=this,w.property="atmosphereShadowLength",this.events.dispatchEvent(w))}update(e,t,a=0){var l,h,d,p;const{shadowMaps:i,shadowPass:r,cloudsPass:s}=this;if(i.cascadeCount!==this.shadowCascadeCount||!i.mapSize.equals(this.shadowMapSize)){const{width:f,height:m}=i.mapSize,v=i.cascadeCount;this.shadowMapSize.set(f,m),this.shadowCascadeCount=v,r.setSize(f,m,v),s.setShadowSize(f,m,v)}(l=this.proceduralLocalWeather)==null||l.render(e,a),(h=this.proceduralShape)==null||h.render(e,a),(d=this.proceduralShapeDetail)==null||d.render(e,a),(p=this.proceduralTurbulence)==null||p.render(e,a),++this.frame,this.updateSharedUniforms(a),this.updateWeatherTextureChannels(),r.update(e,this.frame,a),s.shadowBuffer=r.outputBuffer,s.update(e,this.frame,a),this.updateAtmosphereComposition(),this.uniforms.get("cloudsBuffer").value=this.cloudsPass.outputBuffer}setSize(e,t){const{resolution:a}=this;a.setBaseSize(e,t);const{width:i,height:r}=a;this.cloudsPass.setSize(i,r)}setDepthTexture(e,t){this.shadowPass.setDepthTexture(e,t),this.cloudsPass.setDepthTexture(e,t)}set qualityPreset(e){const{clouds:t,shadow:a,...i}=_e[e];Object.assign(this,i),Object.assign(this.clouds,t),Object.assign(this.shadow,a)}get localWeatherTexture(){return this.proceduralLocalWeather??this.parameterUniforms.localWeatherTexture.value}set localWeatherTexture(e){e instanceof n.Texture||e==null?(this.proceduralLocalWeather=void 0,this.parameterUniforms.localWeatherTexture.value=e):(this.proceduralLocalWeather=e,this.parameterUniforms.localWeatherTexture.value=e.texture)}get shapeTexture(){return this.proceduralShape??this.parameterUniforms.shapeTexture.value}set shapeTexture(e){e instanceof n.Data3DTexture||e==null?(this.proceduralShape=void 0,this.parameterUniforms.shapeTexture.value=e):(this.proceduralShape=e,this.parameterUniforms.shapeTexture.value=e.texture)}get shapeDetailTexture(){return this.proceduralShapeDetail??this.parameterUniforms.shapeDetailTexture.value}set shapeDetailTexture(e){e instanceof n.Data3DTexture||e==null?(this.proceduralShapeDetail=void 0,this.parameterUniforms.shapeDetailTexture.value=e):(this.proceduralShapeDetail=e,this.parameterUniforms.shapeDetailTexture.value=e.texture)}get turbulenceTexture(){return this.proceduralTurbulence??this.parameterUniforms.turbulenceTexture.value}set turbulenceTexture(e){e instanceof n.Texture||e==null?(this.proceduralTurbulence=void 0,this.parameterUniforms.turbulenceTexture.value=e):(this.proceduralTurbulence=e,this.parameterUniforms.turbulenceTexture.value=e.texture)}get stbnTexture(){return this.cloudsPass.currentMaterial.uniforms.stbnTexture.value}set stbnTexture(e){this.cloudsPass.currentMaterial.uniforms.stbnTexture.value=e,this.shadowPass.currentMaterial.uniforms.stbnTexture.value=e}get resolutionScale(){return this.resolution.scale}set resolutionScale(e){this.resolution.scale=e}get temporalUpscale(){return this.cloudsPass.temporalUpscale}set temporalUpscale(e){this.cloudsPass.temporalUpscale=e}get lightShafts(){return this.cloudsPass.lightShafts}set lightShafts(e){this.cloudsPass.lightShafts=e}get shapeDetail(){return this.cloudsPass.currentMaterial.shapeDetail}set shapeDetail(e){this.cloudsPass.currentMaterial.shapeDetail=e,this.shadowPass.currentMaterial.shapeDetail=e}get turbulence(){return this.cloudsPass.currentMaterial.turbulence}set turbulence(e){this.cloudsPass.currentMaterial.turbulence=e,this.shadowPass.currentMaterial.turbulence=e}get haze(){return this.cloudsPass.currentMaterial.haze}set haze(e){this.cloudsPass.currentMaterial.haze=e}get scatteringCoefficient(){return this.parameterUniforms.scatteringCoefficient.value}set scatteringCoefficient(e){this.parameterUniforms.scatteringCoefficient.value=e}get absorptionCoefficient(){return this.parameterUniforms.absorptionCoefficient.value}set absorptionCoefficient(e){this.parameterUniforms.absorptionCoefficient.value=e}get coverage(){return this.parameterUniforms.coverage.value}set coverage(e){this.parameterUniforms.coverage.value=e}get turbulenceDisplacement(){return this.parameterUniforms.turbulenceDisplacement.value}set turbulenceDisplacement(e){this.parameterUniforms.turbulenceDisplacement.value=e}get scatterAnisotropy1(){return this.cloudsPass.currentMaterial.scatterAnisotropy1}set scatterAnisotropy1(e){this.cloudsPass.currentMaterial.scatterAnisotropy1=e}get scatterAnisotropy2(){return this.cloudsPass.currentMaterial.scatterAnisotropy2}set scatterAnisotropy2(e){this.cloudsPass.currentMaterial.scatterAnisotropy2=e}get scatterAnisotropyMix(){return this.cloudsPass.currentMaterial.scatterAnisotropyMix}set scatterAnisotropyMix(e){this.cloudsPass.currentMaterial.scatterAnisotropyMix=e}get skyIrradianceScale(){return this.skyLightScale}set skyIrradianceScale(e){this.skyLightScale=e}get skyLightScale(){return this.cloudsPass.currentMaterial.uniforms.skyLightScale.value}set skyLightScale(e){this.cloudsPass.currentMaterial.uniforms.skyLightScale.value=e}get groundIrradianceScale(){return this.groundBounceScale}set groundIrradianceScale(e){this.groundBounceScale=e}get groundBounceScale(){return this.cloudsPass.currentMaterial.uniforms.groundBounceScale.value}set groundBounceScale(e){this.cloudsPass.currentMaterial.uniforms.groundBounceScale.value=e}get powderScale(){return this.cloudsPass.currentMaterial.uniforms.powderScale.value}set powderScale(e){this.cloudsPass.currentMaterial.uniforms.powderScale.value=e}get powderExponent(){return this.cloudsPass.currentMaterial.uniforms.powderExponent.value}set powderExponent(e){this.cloudsPass.currentMaterial.uniforms.powderExponent.value=e}get atmosphereOverlay(){return this._atmosphereOverlay}get atmosphereShadow(){return this._atmosphereShadow}get atmosphereShadowLength(){return this._atmosphereShadowLength}get irradianceTexture(){return this.cloudsPass.currentMaterial.irradianceTexture}set irradianceTexture(e){this.cloudsPass.currentMaterial.irradianceTexture=e}get scatteringTexture(){return this.cloudsPass.currentMaterial.scatteringTexture}set scatteringTexture(e){this.cloudsPass.currentMaterial.scatteringTexture=e}get transmittanceTexture(){return this.cloudsPass.currentMaterial.transmittanceTexture}set transmittanceTexture(e){this.cloudsPass.currentMaterial.transmittanceTexture=e}get singleMieScatteringTexture(){return this.cloudsPass.currentMaterial.singleMieScatteringTexture}set singleMieScatteringTexture(e){this.cloudsPass.currentMaterial.singleMieScatteringTexture=e}get higherOrderScatteringTexture(){return this.cloudsPass.currentMaterial.higherOrderScatteringTexture}set higherOrderScatteringTexture(e){this.cloudsPass.currentMaterial.higherOrderScatteringTexture=e}get ellipsoid(){return this.cloudsPass.currentMaterial.ellipsoid}set ellipsoid(e){this.cloudsPass.currentMaterial.ellipsoid=e}get sunAngularRadius(){return this.cloudsPass.currentMaterial.sunAngularRadius}set sunAngularRadius(e){this.cloudsPass.currentMaterial.sunAngularRadius=e}}et([u.define("SKIP_RENDERING")],de.prototype,"skipRendering");const ct=128,lt=32,z="45a1c6c1bb9fd38b3680fd120795ff4c32df68ff",ut=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/local_weather.png`,ht=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/shape.bin`,dt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/shape_detail.bin`,pt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${z}/packages/clouds/assets/turbulence.png`;exports.CLOUD_SHAPE_DETAIL_TEXTURE_SIZE=lt;exports.CLOUD_SHAPE_TEXTURE_SIZE=ct;exports.CloudLayer=x;exports.CloudLayers=F;exports.CloudsEffect=de;exports.DEFAULT_LOCAL_WEATHER_URL=ut;exports.DEFAULT_SHAPE_DETAIL_URL=dt;exports.DEFAULT_SHAPE_URL=ht;exports.DEFAULT_TURBULENCE_URL=pt;exports.DensityProfile=M;exports.cloudsPassOptionsDefaults=he;
2202
2217
  //# sourceMappingURL=shared.cjs.map