@takram/three-clouds 0.2.1 → 0.3.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/CHANGELOG.md +24 -0
- package/README.md +12 -3
- package/build/r3f.cjs +1 -1
- package/build/r3f.cjs.map +1 -1
- package/build/r3f.js +169 -170
- package/build/r3f.js.map +1 -1
- package/build/shared.cjs +50 -37
- package/build/shared.cjs.map +1 -1
- package/build/shared.js +130 -116
- package/build/shared.js.map +1 -1
- package/package.json +3 -3
- package/src/CloudsEffect.ts +3 -1
- package/src/CloudsMaterial.ts +17 -11
- package/src/r3f/CloudLayer.tsx +64 -62
- package/src/r3f/Clouds.tsx +105 -109
- package/src/shaders/clouds.frag +37 -25
- package/src/shaders/clouds.glsl +1 -1
- package/src/shaders/clouds.vert +3 -3
- package/src/shaders/parameters.glsl +2 -1
- package/types/CloudsEffect.d.ts +1 -1
- package/types/CloudsMaterial.d.ts +3 -2
- package/types/r3f/CloudLayer.d.ts +3 -1
- package/types/r3f/Clouds.d.ts +2 -1
package/build/shared.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";const C=require("postprocessing"),n=require("three"),H=require("@takram/three-atmosphere"),
|
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;
|
2
2
|
precision highp sampler3D;
|
3
3
|
precision highp sampler2DArray;
|
4
4
|
|
@@ -418,6 +418,7 @@ vec3 getGroundSunSkyIrradiance(
|
|
418
418
|
#ifdef ACCURATE_SUN_SKY_IRRADIANCE
|
419
419
|
return GetSunAndSkyIrradiance(
|
420
420
|
(position - surfaceNormal * height) * METER_TO_LENGTH_UNIT,
|
421
|
+
surfaceNormal,
|
421
422
|
sunDirection,
|
422
423
|
skyIrradiance
|
423
424
|
);
|
@@ -429,7 +430,11 @@ vec3 getGroundSunSkyIrradiance(
|
|
429
430
|
|
430
431
|
vec3 getCloudsSunSkyIrradiance(const vec3 position, const float height, out vec3 skyIrradiance) {
|
431
432
|
#ifdef ACCURATE_SUN_SKY_IRRADIANCE
|
432
|
-
return
|
433
|
+
return GetSunAndSkyIrradianceForParticle(
|
434
|
+
position * METER_TO_LENGTH_UNIT,
|
435
|
+
sunDirection,
|
436
|
+
skyIrradiance
|
437
|
+
);
|
433
438
|
#else // ACCURATE_SUN_SKY_IRRADIANCE
|
434
439
|
float alpha = remapClamped(height, minHeight, maxHeight);
|
435
440
|
skyIrradiance = mix(vCloudsIrradiance.minSky, vCloudsIrradiance.maxSky, alpha);
|
@@ -455,10 +460,9 @@ vec3 approximateIrradianceFromGround(
|
|
455
460
|
vec3 skyIrradiance;
|
456
461
|
vec3 sunIrradiance = getGroundSunSkyIrradiance(position, surfaceNormal, height, skyIrradiance);
|
457
462
|
const float groundAlbedo = 0.3;
|
458
|
-
vec3 groundIrradiance = skyIrradiance + (1.0 - coverage) * sunIrradiance
|
459
|
-
vec3
|
460
|
-
|
461
|
-
return albedo * bouncedIrradiance * RECIPROCAL_PI4 * groundIrradianceScale;
|
463
|
+
vec3 groundIrradiance = skyIrradiance + (1.0 - coverage) * sunIrradiance;
|
464
|
+
vec3 bouncedRadiance = groundAlbedo * RECIPROCAL_PI * groundIrradiance;
|
465
|
+
return bouncedRadiance * exp(-opticalDepthToGround);
|
462
466
|
}
|
463
467
|
#endif // GROUND_IRRADIANCE
|
464
468
|
|
@@ -548,28 +552,28 @@ vec4 marchClouds(
|
|
548
552
|
);
|
549
553
|
}
|
550
554
|
|
551
|
-
|
552
|
-
vec3 radiance = albedo * sunIrradiance * scattering;
|
555
|
+
vec3 radiance = sunIrradiance * approximateMultipleScattering(opticalDepth, cosTheta);
|
553
556
|
|
554
557
|
#ifdef GROUND_IRRADIANCE
|
555
558
|
// Fudge factor for the irradiance from ground.
|
556
559
|
if (height < shadowTopHeight && mipLevel < 0.5) {
|
557
|
-
|
560
|
+
vec3 groundIrradiance = approximateIrradianceFromGround(
|
558
561
|
position,
|
559
562
|
surfaceNormal,
|
560
563
|
height,
|
561
564
|
mipLevel,
|
562
565
|
jitter
|
563
566
|
);
|
567
|
+
radiance += groundIrradiance * RECIPROCAL_PI4 * groundIrradianceScale;
|
564
568
|
}
|
565
569
|
#endif // GROUND_IRRADIANCE
|
566
570
|
|
567
571
|
// Crude approximation of sky gradient. Better than none in the shadows.
|
568
|
-
float skyGradient = dot(0.5 +
|
569
|
-
radiance +=
|
572
|
+
float skyGradient = dot(weather.heightFraction * 0.5 + 0.5, media.weight);
|
573
|
+
radiance += skyIrradiance * RECIPROCAL_PI4 * skyGradient * skyIrradianceScale;
|
570
574
|
|
571
|
-
// Finally multiply by
|
572
|
-
radiance *= media.
|
575
|
+
// Finally multiply by scattering.
|
576
|
+
radiance *= media.scattering;
|
573
577
|
|
574
578
|
#ifdef POWDER
|
575
579
|
radiance *= 1.0 - powderScale * exp(-media.extinction * powderExponent);
|
@@ -622,7 +626,7 @@ float marchShadowLength(
|
|
622
626
|
float maxRayDistance = rayNearFar.y - rayNearFar.x;
|
623
627
|
float stepSize = minShadowLengthStepSize;
|
624
628
|
float rayDistance = stepSize * jitter;
|
625
|
-
const float attenuationFactor = 1.0 -
|
629
|
+
const float attenuationFactor = 1.0 - 5e-4;
|
626
630
|
float attenuation = 1.0;
|
627
631
|
|
628
632
|
// TODO: This march is closed, and sample resolution can be much lower.
|
@@ -668,25 +672,33 @@ vec4 approximateHaze(
|
|
668
672
|
return vec4(0.0); // Prevent artifact in views from space
|
669
673
|
}
|
670
674
|
|
675
|
+
// Blend two normals by the difference in angle so that normal near the
|
676
|
+
// ground becomes that of the origin, and in the sky that of the horizon.
|
677
|
+
vec3 normalAtOrigin = normalize(rayOrigin);
|
678
|
+
vec3 normalAtHorizon = (rayOrigin - dot(rayOrigin, rayDirection) * rayDirection) / bottomRadius;
|
679
|
+
float alpha = remapClamped(dot(normalAtOrigin, normalAtHorizon), 0.9, 1.0);
|
680
|
+
vec3 normal = mix(normalAtOrigin, normalAtHorizon, alpha);
|
681
|
+
|
671
682
|
// Analytical optical depth where density exponentially decreases with height.
|
672
683
|
// Based on: https://iquilezles.org/articles/fog/
|
673
|
-
float angle = max(dot(
|
684
|
+
float angle = max(dot(normal, rayDirection), 1e-5);
|
674
685
|
float exponent = angle * hazeExponent;
|
686
|
+
float linearTerm = density / hazeExponent / angle;
|
687
|
+
|
675
688
|
// Derive the optical depths separately for with and without shadow length.
|
676
689
|
float expTerm = 1.0 - exp(-maxRayDistance * exponent);
|
677
690
|
float shadowExpTerm = 1.0 - exp(-min(maxRayDistance, shadowLength) * exponent);
|
678
|
-
float linearTerm = density / hazeExponent / angle;
|
679
691
|
float opticalDepth = expTerm * linearTerm;
|
680
|
-
float
|
692
|
+
float shadowOpticalDepth = max((expTerm - shadowExpTerm) * linearTerm, 0.0);
|
693
|
+
float transmittance = saturate(1.0 - exp(-opticalDepth));
|
694
|
+
float shadowTransmittance = saturate(1.0 - exp(-shadowOpticalDepth));
|
681
695
|
|
682
696
|
vec3 skyIrradiance = vGroundIrradiance.sky;
|
683
697
|
vec3 sunIrradiance = vGroundIrradiance.sun;
|
684
|
-
vec3
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
// Inscatter is attenuated by shadow length, but transmittance is not.
|
689
|
-
return vec4(inscatter, saturate(1.0 - exp(-opticalDepth)));
|
698
|
+
vec3 inscatter = sunIrradiance * phaseFunction(cosTheta) * shadowTransmittance;
|
699
|
+
inscatter += skyIrradiance * RECIPROCAL_PI4 * skyIrradianceScale * transmittance;
|
700
|
+
inscatter *= hazeScatteringCoefficient / (hazeAbsorptionCoefficient + hazeScatteringCoefficient);
|
701
|
+
return vec4(inscatter, transmittance);
|
690
702
|
}
|
691
703
|
|
692
704
|
#endif // HAZE
|
@@ -705,8 +717,7 @@ void applyAerialPerspective(
|
|
705
717
|
sunDirection,
|
706
718
|
transmittance
|
707
719
|
);
|
708
|
-
|
709
|
-
color.rgb = mix(vec3(0.0), color.rgb * transmittance / clampedAlpha + inscatter, color.a);
|
720
|
+
color.rgb = color.rgb * transmittance + inscatter * color.a;
|
710
721
|
}
|
711
722
|
|
712
723
|
bool rayIntersectsGround(const vec3 cameraPosition, const vec3 rayDirection) {
|
@@ -985,7 +996,8 @@ void main() {
|
|
985
996
|
cosTheta,
|
986
997
|
shadowLength
|
987
998
|
);
|
988
|
-
color = color
|
999
|
+
color.rgb = mix(color.rgb, haze.rgb, haze.a);
|
1000
|
+
color.a = color.a * (1.0 - haze.a) + haze.a;
|
989
1001
|
#endif // HAZE
|
990
1002
|
|
991
1003
|
outputColor = color;
|
@@ -1163,7 +1175,7 @@ MediaSample sampleMedia(
|
|
1163
1175
|
}
|
1164
1176
|
#endif // SHAPE_DETAIL
|
1165
1177
|
|
1166
|
-
//
|
1178
|
+
// Apply the density profiles.
|
1167
1179
|
density = saturate(density * densityScales * getLayerDensity(weather.heightFraction));
|
1168
1180
|
|
1169
1181
|
MediaSample media;
|
@@ -1218,7 +1230,7 @@ out GroundIrradiance vGroundIrradiance;
|
|
1218
1230
|
out CloudsIrradiance vCloudsIrradiance;
|
1219
1231
|
|
1220
1232
|
void sampleSunSkyIrradiance(const vec3 positionECEF) {
|
1221
|
-
vGroundIrradiance.sun =
|
1233
|
+
vGroundIrradiance.sun = GetSunAndSkyIrradianceForParticle(
|
1222
1234
|
positionECEF * METER_TO_LENGTH_UNIT,
|
1223
1235
|
sunDirection,
|
1224
1236
|
vGroundIrradiance.sky
|
@@ -1226,12 +1238,12 @@ void sampleSunSkyIrradiance(const vec3 positionECEF) {
|
|
1226
1238
|
|
1227
1239
|
vec3 surfaceNormal = normalize(positionECEF);
|
1228
1240
|
vec2 radii = (bottomRadius + vec2(minHeight, maxHeight)) * METER_TO_LENGTH_UNIT;
|
1229
|
-
vCloudsIrradiance.minSun =
|
1241
|
+
vCloudsIrradiance.minSun = GetSunAndSkyIrradianceForParticle(
|
1230
1242
|
surfaceNormal * radii.x,
|
1231
1243
|
sunDirection,
|
1232
1244
|
vCloudsIrradiance.minSky
|
1233
1245
|
);
|
1234
|
-
vCloudsIrradiance.maxSun =
|
1246
|
+
vCloudsIrradiance.maxSun = GetSunAndSkyIrradianceForParticle(
|
1235
1247
|
surfaceNormal * radii.y,
|
1236
1248
|
sunDirection,
|
1237
1249
|
vCloudsIrradiance.maxSky
|
@@ -1266,7 +1278,6 @@ uniform vec3 sunDirection;
|
|
1266
1278
|
// Participating medium
|
1267
1279
|
uniform float scatteringCoefficient;
|
1268
1280
|
uniform float absorptionCoefficient;
|
1269
|
-
uniform vec3 albedo;
|
1270
1281
|
|
1271
1282
|
// Primary raymarch
|
1272
1283
|
uniform float minDensity;
|
@@ -1298,6 +1309,8 @@ uniform float turbulenceDisplacement;
|
|
1298
1309
|
#ifdef HAZE
|
1299
1310
|
uniform float hazeDensityScale;
|
1300
1311
|
uniform float hazeExponent;
|
1312
|
+
uniform float hazeScatteringCoefficient;
|
1313
|
+
uniform float hazeAbsorptionCoefficient;
|
1301
1314
|
#endif // HAZE
|
1302
1315
|
|
1303
1316
|
// Cloud layers
|
@@ -1317,7 +1330,7 @@ uniform float shadowTopHeight;
|
|
1317
1330
|
uniform float shadowBottomHeight;
|
1318
1331
|
uniform vec4 shadowLayerMask;
|
1319
1332
|
uniform DensityProfile densityProfile;
|
1320
|
-
`,
|
1333
|
+
`,V=`struct GroundIrradiance {
|
1321
1334
|
vec3 sun;
|
1322
1335
|
vec3 sky;
|
1323
1336
|
};
|
@@ -1335,7 +1348,7 @@ struct DensityProfile {
|
|
1335
1348
|
vec4 linearTerms;
|
1336
1349
|
vec4 constantTerms;
|
1337
1350
|
};
|
1338
|
-
`;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
|
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
|
1339
1352
|
// TODO: Use 5-taps version: https://www.shadertoy.com/view/MtVGWz
|
1340
1353
|
// Or even 4 taps (requires preprocessing in the input buffer):
|
1341
1354
|
// https://www.shadertoy.com/view/4tyGDD
|
@@ -1774,7 +1787,7 @@ vec4 varianceClipping(
|
|
1774
1787
|
) {
|
1775
1788
|
return varianceClipping(inputBuffer, coord, current, history, 1.0);
|
1776
1789
|
}
|
1777
|
-
`;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:
|
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;
|
1778
1791
|
precision highp sampler3D;
|
1779
1792
|
|
1780
1793
|
#include <common>
|
@@ -2088,7 +2101,7 @@ void intersectStructuredPlanes(
|
|
2088
2101
|
stepOffset += stepSize;
|
2089
2102
|
}
|
2090
2103
|
}
|
2091
|
-
`;var
|
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;
|
2092
2105
|
precision highp sampler2DArray;
|
2093
2106
|
|
2094
2107
|
#define VARIANCE_9_SAMPLES (1)
|
@@ -2174,7 +2187,7 @@ void main() {
|
|
2174
2187
|
vUv = position.xy * 0.5 + 0.5;
|
2175
2188
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
2176
2189
|
}
|
2177
|
-
`;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
|
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;
|
2178
2191
|
|
2179
2192
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
2180
2193
|
#ifdef SKIP_RENDERING
|
@@ -2185,5 +2198,5 @@ void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
|
2185
2198
|
outputColor.a = inputColor.a * (1.0 - clouds.a) + clouds.a;
|
2186
2199
|
#endif // SKIP_RENDERING
|
2187
2200
|
}
|
2188
|
-
`;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"],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"},he={resolutionScale:l.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:c=r,resolutionY:h=s}={...he,...t};this.shadowMaps=new Ee({cascadeCount:l.shadow.cascadeCount,mapSize:l.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,c,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(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),c=this.sunDirection.dot(s),h=u.lerp(1e6,1e3,c);this.shadowMaps.update(this.camera,O.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,c=Object.assign(this._atmosphereOverlay??{},{map:a.outputBuffer});s!==c&&(this._atmosphereOverlay=c,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 c,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)}(c=this.proceduralLocalWeather)==null||c.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.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([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=I;exports.cloudsPassOptionsDefaults=he;
|
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;
|
2189
2202
|
//# sourceMappingURL=shared.cjs.map
|