@takram/three-clouds 0.4.1 → 0.5.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 +12 -0
- package/build/index.cjs.map +1 -1
- package/build/index.js.map +1 -1
- package/build/r3f.cjs +1 -1
- package/build/r3f.cjs.map +1 -1
- package/build/r3f.js +55 -55
- package/build/r3f.js.map +1 -1
- package/build/shared.cjs +87 -121
- package/build/shared.cjs.map +1 -1
- package/build/shared.js +376 -413
- package/build/shared.js.map +1 -1
- package/package.json +3 -3
- package/src/CloudsEffect.ts +15 -17
- package/src/CloudsMaterial.ts +11 -2
- package/src/r3f/Clouds.tsx +1 -2
- package/src/shaders/clouds.frag +48 -47
- package/src/shaders/clouds.vert +10 -11
- package/src/shaders/cloudsResolve.frag +14 -39
- package/src/shaders/parameters.glsl +3 -2
- package/src/shaders/shadow.frag +2 -6
- package/src/shaders/shadow.vert +0 -6
- package/src/uniforms.ts +4 -6
- package/types/CloudsEffect.d.ts +2 -3
- package/types/CloudsMaterial.d.ts +1 -0
- package/types/uniforms.d.ts +2 -3
package/build/shared.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const C=require("postprocessing"),n=require("three"),
|
|
1
|
+
"use strict";const C=require("postprocessing"),n=require("three"),z=require("@takram/three-atmosphere"),u=require("@takram/three-geospatial"),P=require("@takram/three-atmosphere/shaders/bruneton"),y=require("@takram/three-geospatial/shaders");class b{constructor(e=0,t=0,a=0,r=0){this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=r}set(e=0,t=0,a=0,r=0){return this.expTerm=e,this.exponent=t,this.linearTerm=a,this.constantTerm=r,this}clone(){return new b(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 b?o[t].copy(a):o[t]=a)}}const M=class M{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 b(0,0,.75,.25),this.shadow=!1,this.set(e)}set(e){return ve(this,e),this}clone(){return new M(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}};M.DEFAULT=new M;let x=M;const O=Array.from({length:8},()=>({value:0,flag:0})),R=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 I=class I 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 I(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 c=this[s];let h=O[s];h.value=c.altitude,h.flag=0,h=O[s+4],h.value=c.altitude+c.height,h.flag=1}O.sort(ge);let a=0,r=0;for(let s=0;s<O.length;++s){const{value:c,flag:h}=O[s];if(r===0&&s>0){const d=R[a++];d.min=O[s-1].value,d.max=c}r+=h===0?1:-1}for(;a<3;++a){const s=R[a];s.min=0,s.max=0}let i=R[0];e.x=i.min,t.x=i.max,i=R[1],e.y=i.min,t.y=i.max,i=R[2],e.z=i.min,t.z=i.max}};I.DEFAULT=new I([{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 W=I;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 N{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 N().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,r=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 i=0;i<4;++i)this.near[i].applyMatrix4(r);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 i=0;i<4;++i){const s=this.far[i];s.applyMatrix4(r);const c=Math.abs(s.z);a?s.z*=Math.min(t/c,1):s.multiplyScalar(Math.min(t/c,1))}return this}split(e,t=[]){for(let a=0;a<e.length;++a){const r=t[a]??(t[a]=new N);if(a===0)for(let i=0;i<4;++i)r.near[i].copy(this.near[i]);else for(let i=0;i<4;++i)r.near[i].lerpVectors(this.near[i],this.far[i],e[a-1]);if(a===e.length-1)for(let i=0;i<4;++i)r.far[i].copy(this.far[i]);else for(let i=0;i<4;++i)r.far[i].lerpVectors(this.near[i],this.far[i],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,r=[])=>{for(let i=0;i<o;++i)r[i]=(e+(t-e)*(i+1)/o)/t;return r.length=o,r},logarithmic:(o,e,t,a,r=[])=>{for(let i=0;i<o;++i)r[i]=e*(t/e)**((i+1)/o)/t;return r.length=o,r},practical:(o,e,t,a=.5,r=[])=>{for(let i=0;i<o;++i){const s=(e+(t-e)*(i+1)/o)/t,c=e*(t/e)**((i+1)/o)/t;r[i]=u.lerp(s,c,a)}return r.length=o,r}};function xe(o,e,t,a,r,i=[]){return ye[o](e,t,a,r,i)}const Q=new n.Vector3,ee=new n.Vector3,we=new n.Matrix4,te=new n.Matrix4,Ce=new N,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 N,this.frusta=[],this.splits=[],this._far=0;const{cascadeCount:t,mapSize:a,maxFar:r,farScale:i,splitMode:s,splitLambda:c,margin:h,fade:d}={...De,...e};this.cascadeCount=t,this.mapSize.copy(a),this.maxFar=r,this.farScale=i,this.splitMode=s,this.splitLambda=c,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,r=this.far;xe(this.splitMode,t,e.near,r,this.splitLambda,a),this.cameraFrustum.setFromCamera(e,r),this.cameraFrustum.split(a,this.frusta);const i=this.cascades;for(let s=0;s<t;++s)i[s].interval.set(a[s-1]??0,a[s]??0)}getFrustumRadius(e,t){const a=t.near,r=t.far;let i=Math.max(r[0].distanceTo(r[2]),r[0].distanceTo(a[2]));if(this.fade){const s=e.near,c=this.far,h=r[0].z/(c-s);i+=.25*h**2*(c-s)}return i*.5}updateMatrices(e,t,a=1){const r=we.lookAt(Q.setScalar(0),ee.copy(t).multiplyScalar(-1),n.Object3D.DEFAULT_UP),i=te.multiplyMatrices(te.copy(r).invert(),e.matrixWorld),s=this.frusta,c=this.cascades;D(s.length===c.length);const h=this.margin,d=this.mapSize;for(let p=0;p<s.length;++p){const f=s[p],m=c[p],v=this.getFrustumRadius(e,s[p]),A=-v,_=v,Z=v,q=-v;m.projectionMatrix.makeOrthographic(A,_,Z,q,-this.margin,v*2+this.margin);const{near:pe,far:fe}=Ce.copy(f).applyMatrix4(i),H=Te.makeEmpty();for(let F=0;F<4;F++)H.expandByPoint(pe[F]),H.expandByPoint(fe[F]);const T=H.getCenter(Q);T.z=H.max.z+h;const K=(_-A)/d.width,X=(Z-q)/d.height;T.x=Math.round(T.x/K)*K,T.y=Math.round(T.y/X)*X,T.applyMatrix4(r);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 r=this.cascades,i=this.cascadeCount;for(let s=0;s<i;++s){const{matrix:c,inverseMatrix:h,projectionMatrix:d,inverseProjectionMatrix:p,viewMatrix:f,inverseViewMatrix:m}=r[s];p.copy(d).invert(),f.copy(m).invert(),c.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],re=ne.reduce((o,e,t)=>{const a=new n.Vector2;for(let r=0;r<16;++r)if(ne[r]===t){a.set((r%4+.5)/4,(Math.floor(r/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}},l=Ae,_e={low:{...l,lightShafts:!1,shapeDetail:!1,turbulence:!1,clouds:{...l.clouds,accurateSunSkyLight:!1,maxIterationCount:200,minStepSize:100,maxRayDistance:1e5,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.1,maxIterationCountToGround:0,maxIterationCountToSun:1},shadow:{...l.shadow,maxIterationCount:25,minDensity:1e-4,minExtinction:1e-4,minTransmittance:.01,cascadeCount:2,mapSize:new n.Vector2(256,256)}},medium:{...l,lightShafts:!1,turbulence:!1,clouds:{...l.clouds,minDensity:1e-4,minExtinction:1e-4,accurateSunSkyLight:!1,maxIterationCountToSun:2,maxIterationCountToGround:1},shadow:{...l.shadow,minDensity:1e-4,minExtinction:1e-4,mapSize:new n.Vector2(256,256)}},high:l,ultra:{...l,clouds:{...l.clouds,minStepSize:10},shadow:{...l.shadow,mapSize:new n.Vector2(1024,1024)}}},Pe=`precision highp float;
|
|
2
2
|
precision highp sampler3D;
|
|
3
3
|
precision highp sampler2DArray;
|
|
4
4
|
|
|
@@ -40,6 +40,7 @@ uniform sampler3D higher_order_scattering_texture;
|
|
|
40
40
|
uniform sampler2D depthBuffer;
|
|
41
41
|
uniform mat4 viewMatrix;
|
|
42
42
|
uniform mat4 reprojectionMatrix;
|
|
43
|
+
uniform mat4 viewReprojectionMatrix;
|
|
43
44
|
uniform float cameraNear;
|
|
44
45
|
uniform float cameraFar;
|
|
45
46
|
uniform float cameraHeight;
|
|
@@ -87,7 +88,7 @@ in vec2 vUv;
|
|
|
87
88
|
in vec3 vCameraPosition;
|
|
88
89
|
in vec3 vCameraDirection; // Direction to the center of screen
|
|
89
90
|
in vec3 vRayDirection; // Direction to the texel
|
|
90
|
-
in vec3
|
|
91
|
+
in vec3 vViewPosition;
|
|
91
92
|
in GroundIrradiance vGroundIrradiance;
|
|
92
93
|
in CloudsIrradiance vCloudsIrradiance;
|
|
93
94
|
|
|
@@ -113,8 +114,8 @@ float getViewZ(const float depth) {
|
|
|
113
114
|
#endif // PERSPECTIVE_CAMERA
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
vec3
|
|
117
|
-
return
|
|
117
|
+
vec3 ecefToWorld(const vec3 positionECEF) {
|
|
118
|
+
return (ecefToWorldMatrix * vec4(positionECEF - altitudeCorrection, 1.0)).xyz;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
vec2 getShadowUv(const vec3 worldPosition, const int cascadeIndex) {
|
|
@@ -144,7 +145,7 @@ const vec3 cascadeColors[4] = vec3[4](
|
|
|
144
145
|
);
|
|
145
146
|
|
|
146
147
|
vec3 getCascadeColor(const vec3 rayPosition) {
|
|
147
|
-
vec3 worldPosition =
|
|
148
|
+
vec3 worldPosition = ecefToWorld(rayPosition);
|
|
148
149
|
int cascadeIndex = getCascadeIndex(
|
|
149
150
|
viewMatrix,
|
|
150
151
|
worldPosition,
|
|
@@ -160,7 +161,7 @@ vec3 getCascadeColor(const vec3 rayPosition) {
|
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
vec3 getFadedCascadeColor(const vec3 rayPosition, const float jitter) {
|
|
163
|
-
vec3 worldPosition =
|
|
164
|
+
vec3 worldPosition = ecefToWorld(rayPosition);
|
|
164
165
|
int cascadeIndex = getFadedCascadeIndex(
|
|
165
166
|
viewMatrix,
|
|
166
167
|
worldPosition,
|
|
@@ -235,7 +236,7 @@ float sampleShadowOpticalDepth(
|
|
|
235
236
|
if (distanceToTop <= 0.0) {
|
|
236
237
|
return 0.0;
|
|
237
238
|
}
|
|
238
|
-
vec3 worldPosition =
|
|
239
|
+
vec3 worldPosition = ecefToWorld(rayPosition);
|
|
239
240
|
int cascadeIndex = getFadedCascadeIndex(
|
|
240
241
|
viewMatrix,
|
|
241
242
|
worldPosition,
|
|
@@ -816,14 +817,15 @@ vec2 getHazeRayNearFar(const IntersectionResult intersections) {
|
|
|
816
817
|
}
|
|
817
818
|
#endif // HAZE
|
|
818
819
|
|
|
819
|
-
float getRayDistanceToScene(const vec3 rayDirection) {
|
|
820
|
+
float getRayDistanceToScene(const vec3 rayDirection, out float viewZ) {
|
|
820
821
|
float depth = readDepth(vUv * targetUvScale + temporalJitter);
|
|
821
822
|
if (depth < 1.0 - 1e-7) {
|
|
822
823
|
depth = reverseLogDepth(depth, cameraNear, cameraFar);
|
|
823
|
-
|
|
824
|
+
viewZ = getViewZ(depth);
|
|
824
825
|
return -viewZ / dot(rayDirection, vCameraDirection);
|
|
825
826
|
}
|
|
826
|
-
|
|
827
|
+
viewZ = 0.0;
|
|
828
|
+
return 0.0;
|
|
827
829
|
}
|
|
828
830
|
|
|
829
831
|
void main() {
|
|
@@ -836,7 +838,7 @@ void main() {
|
|
|
836
838
|
return;
|
|
837
839
|
#endif // DEBUG_SHOW_SHADOW_MAP
|
|
838
840
|
|
|
839
|
-
vec3 cameraPosition = vCameraPosition
|
|
841
|
+
vec3 cameraPosition = vCameraPosition + altitudeCorrection;
|
|
840
842
|
vec3 rayDirection = normalize(vRayDirection);
|
|
841
843
|
float cosTheta = dot(sunDirection, rayDirection);
|
|
842
844
|
|
|
@@ -849,8 +851,9 @@ void main() {
|
|
|
849
851
|
vec2 hazeRayNearFar = getHazeRayNearFar(intersections);
|
|
850
852
|
#endif // HAZE
|
|
851
853
|
|
|
852
|
-
float
|
|
853
|
-
|
|
854
|
+
float sceneViewZ;
|
|
855
|
+
float rayDistanceToScene = getRayDistanceToScene(rayDirection, sceneViewZ);
|
|
856
|
+
if (rayDistanceToScene > 0.0) {
|
|
854
857
|
rayNearFar.y = min(rayNearFar.y, rayDistanceToScene);
|
|
855
858
|
#ifdef SHADOW_LENGTH
|
|
856
859
|
shadowRayNearFar.y = min(shadowRayNearFar.y, rayDistanceToScene);
|
|
@@ -869,6 +872,7 @@ void main() {
|
|
|
869
872
|
float frontDepth = rayNearFar.y;
|
|
870
873
|
vec3 depthVelocity = vec3(0.0);
|
|
871
874
|
float shadowLength = 0.0;
|
|
875
|
+
bool hitClouds = false;
|
|
872
876
|
|
|
873
877
|
if (!intersectsGround && !intersectsScene) {
|
|
874
878
|
vec3 rayOrigin = rayNearFar.x * rayDirection + cameraPosition;
|
|
@@ -909,7 +913,8 @@ void main() {
|
|
|
909
913
|
#endif // DEBUG_SHOW_SAMPLE_COUNT
|
|
910
914
|
|
|
911
915
|
// Front depth will be -1.0 when no samples are accumulated.
|
|
912
|
-
|
|
916
|
+
hitClouds = marchedFrontDepth >= 0.0;
|
|
917
|
+
if (hitClouds) {
|
|
913
918
|
frontDepth = rayNearFar.x + marchedFrontDepth;
|
|
914
919
|
|
|
915
920
|
#ifdef SHADOW_LENGTH
|
|
@@ -919,6 +924,16 @@ void main() {
|
|
|
919
924
|
min(frontDepth, shadowRayNearFar.y),
|
|
920
925
|
color.a // Interpolate by the alpha for smoother edges.
|
|
921
926
|
);
|
|
927
|
+
|
|
928
|
+
// Shadow length must be computed before applying aerial perspective.
|
|
929
|
+
if (all(greaterThanEqual(shadowRayNearFar, vec2(0.0)))) {
|
|
930
|
+
shadowLength = marchShadowLength(
|
|
931
|
+
shadowRayNearFar.x * rayDirection + cameraPosition,
|
|
932
|
+
rayDirection,
|
|
933
|
+
shadowRayNearFar,
|
|
934
|
+
stbn
|
|
935
|
+
);
|
|
936
|
+
}
|
|
922
937
|
#endif // SHADOW_LENGTH
|
|
923
938
|
|
|
924
939
|
#ifdef HAZE
|
|
@@ -929,8 +944,22 @@ void main() {
|
|
|
929
944
|
color.a // Interpolate by the alpha for smoother edges.
|
|
930
945
|
);
|
|
931
946
|
#endif // HAZE
|
|
947
|
+
|
|
948
|
+
// Apply aerial perspective.
|
|
949
|
+
vec3 frontPosition = cameraPosition + frontDepth * rayDirection;
|
|
950
|
+
applyAerialPerspective(cameraPosition, frontPosition, shadowLength, color);
|
|
951
|
+
|
|
952
|
+
// Velocity for temporal resolution.
|
|
953
|
+
vec3 frontPositionWorld = ecefToWorld(frontPosition);
|
|
954
|
+
vec4 prevClip = reprojectionMatrix * vec4(frontPositionWorld, 1.0);
|
|
955
|
+
prevClip /= prevClip.w;
|
|
956
|
+
vec2 prevUv = prevClip.xy * 0.5 + 0.5;
|
|
957
|
+
vec2 velocity = vUv - prevUv;
|
|
958
|
+
depthVelocity = vec3(frontDepth, velocity);
|
|
932
959
|
}
|
|
960
|
+
}
|
|
933
961
|
|
|
962
|
+
if (!hitClouds) {
|
|
934
963
|
#ifdef SHADOW_LENGTH
|
|
935
964
|
if (all(greaterThanEqual(shadowRayNearFar, vec2(0.0)))) {
|
|
936
965
|
shadowLength = marchShadowLength(
|
|
@@ -942,43 +971,15 @@ void main() {
|
|
|
942
971
|
}
|
|
943
972
|
#endif // SHADOW_LENGTH
|
|
944
973
|
|
|
945
|
-
//
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
vec3 frontPositionWorld = ECEFToWorld(frontPosition);
|
|
951
|
-
vec4 prevClip = reprojectionMatrix * vec4(frontPositionWorld, 1.0);
|
|
974
|
+
// Velocity for temporal resolution. Here reproject in the view space for
|
|
975
|
+
// greatly reducing the precision errors.
|
|
976
|
+
frontDepth = sceneViewZ < 0.0 ? -sceneViewZ : cameraFar;
|
|
977
|
+
vec3 frontView = vViewPosition * frontDepth;
|
|
978
|
+
vec4 prevClip = viewReprojectionMatrix * vec4(frontView, 1.0);
|
|
952
979
|
prevClip /= prevClip.w;
|
|
953
980
|
vec2 prevUv = prevClip.xy * 0.5 + 0.5;
|
|
954
|
-
vec2 velocity =
|
|
981
|
+
vec2 velocity = vUv - prevUv;
|
|
955
982
|
depthVelocity = vec3(frontDepth, velocity);
|
|
956
|
-
|
|
957
|
-
} else {
|
|
958
|
-
#ifdef SHADOW_LENGTH
|
|
959
|
-
if (all(greaterThanEqual(shadowRayNearFar, vec2(0.0)))) {
|
|
960
|
-
shadowLength = marchShadowLength(
|
|
961
|
-
shadowRayNearFar.x * rayDirection + cameraPosition,
|
|
962
|
-
rayDirection,
|
|
963
|
-
shadowRayNearFar,
|
|
964
|
-
stbn
|
|
965
|
-
);
|
|
966
|
-
}
|
|
967
|
-
#endif // SHADOW_LENGTH
|
|
968
|
-
|
|
969
|
-
// TODO: We can calculate velocity to reduce occlusion errors at the edges,
|
|
970
|
-
// but suffers from floating-point precision errors on near objects.
|
|
971
|
-
|
|
972
|
-
// if (intersectsScene) {
|
|
973
|
-
// vec3 frontPosition = cameraPosition + rayNearFar.y * rayDirection;
|
|
974
|
-
// vec3 frontPositionWorld = ECEFToWorld(frontPosition);
|
|
975
|
-
// vec4 prevClip = reprojectionMatrix * vec4(frontPositionWorld, 1.0);
|
|
976
|
-
// prevClip /= prevClip.w;
|
|
977
|
-
// vec2 prevUv = prevClip.xy * 0.5 + 0.5;
|
|
978
|
-
// vec2 velocity = (vUv - prevUv) * resolution;
|
|
979
|
-
// depthVelocity = vec3(rayNearFar.y, velocity);
|
|
980
|
-
// }
|
|
981
|
-
|
|
982
983
|
}
|
|
983
984
|
|
|
984
985
|
#ifdef DEBUG_SHOW_FRONT_DEPTH
|
|
@@ -1008,7 +1009,7 @@ void main() {
|
|
|
1008
1009
|
outputShadowLength = shadowLength * METER_TO_LENGTH_UNIT;
|
|
1009
1010
|
#endif // SHADOW_LENGTH
|
|
1010
1011
|
}
|
|
1011
|
-
`,
|
|
1012
|
+
`,ie=`float getSTBN() {
|
|
1012
1013
|
ivec3 size = textureSize(stbnTexture, 0);
|
|
1013
1014
|
vec3 scale = 1.0 / vec3(size);
|
|
1014
1015
|
return texture(stbnTexture, vec3(gl_FragCoord.xy, float(frame % size.z)) * scale).r;
|
|
@@ -1198,7 +1199,7 @@ MediaSample sampleMedia(
|
|
|
1198
1199
|
ivec3 sampleCount;
|
|
1199
1200
|
return sampleMedia(weather, position, uv, mipLevel, jitter, sampleCount);
|
|
1200
1201
|
}
|
|
1201
|
-
`,
|
|
1202
|
+
`,Oe=`precision highp float;
|
|
1202
1203
|
precision highp sampler3D;
|
|
1203
1204
|
|
|
1204
1205
|
#include "atmosphere/bruneton/definitions"
|
|
@@ -1221,8 +1222,7 @@ uniform sampler3D higher_order_scattering_texture;
|
|
|
1221
1222
|
uniform mat4 inverseProjectionMatrix;
|
|
1222
1223
|
uniform mat4 inverseViewMatrix;
|
|
1223
1224
|
uniform vec3 cameraPosition;
|
|
1224
|
-
uniform
|
|
1225
|
-
uniform mat4 inverseEllipsoidMatrix;
|
|
1225
|
+
uniform mat4 worldToECEFMatrix;
|
|
1226
1226
|
uniform vec3 altitudeCorrection;
|
|
1227
1227
|
|
|
1228
1228
|
// Atmosphere
|
|
@@ -1239,7 +1239,7 @@ out vec2 vUv;
|
|
|
1239
1239
|
out vec3 vCameraPosition;
|
|
1240
1240
|
out vec3 vCameraDirection; // Direction to the center of screen
|
|
1241
1241
|
out vec3 vRayDirection; // Direction to the texel
|
|
1242
|
-
out vec3
|
|
1242
|
+
out vec3 vViewPosition;
|
|
1243
1243
|
|
|
1244
1244
|
out GroundIrradiance vGroundIrradiance;
|
|
1245
1245
|
out CloudsIrradiance vCloudsIrradiance;
|
|
@@ -1268,15 +1268,15 @@ void sampleSunSkyIrradiance(const vec3 positionECEF) {
|
|
|
1268
1268
|
void main() {
|
|
1269
1269
|
vUv = position.xy * 0.5 + 0.5;
|
|
1270
1270
|
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
vCameraPosition =
|
|
1275
|
-
vCameraDirection =
|
|
1276
|
-
vRayDirection =
|
|
1277
|
-
|
|
1271
|
+
vec3 viewPosition = (inverseProjectionMatrix * vec4(position, 1.0)).xyz;
|
|
1272
|
+
vec3 worldDirection = (inverseViewMatrix * vec4(viewPosition.xyz, 0.0)).xyz;
|
|
1273
|
+
vec3 cameraDirection = normalize((inverseViewMatrix * vec4(0.0, 0.0, -1.0, 0.0)).xyz);
|
|
1274
|
+
vCameraPosition = (worldToECEFMatrix * vec4(cameraPosition, 1.0)).xyz;
|
|
1275
|
+
vCameraDirection = (worldToECEFMatrix * vec4(cameraDirection, 0.0)).xyz;
|
|
1276
|
+
vRayDirection = (worldToECEFMatrix * vec4(worldDirection, 0.0)).xyz;
|
|
1277
|
+
vViewPosition = viewPosition;
|
|
1278
1278
|
|
|
1279
|
-
sampleSunSkyIrradiance(vCameraPosition
|
|
1279
|
+
sampleSunSkyIrradiance(vCameraPosition + altitudeCorrection);
|
|
1280
1280
|
|
|
1281
1281
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
1282
1282
|
}
|
|
@@ -1286,8 +1286,9 @@ uniform sampler3D stbnTexture;
|
|
|
1286
1286
|
|
|
1287
1287
|
// Atmosphere
|
|
1288
1288
|
uniform float bottomRadius;
|
|
1289
|
-
uniform mat4
|
|
1290
|
-
uniform mat4
|
|
1289
|
+
uniform mat4 worldToECEFMatrix;
|
|
1290
|
+
uniform mat4 ecefToWorldMatrix;
|
|
1291
|
+
uniform vec3 altitudeCorrection;
|
|
1291
1292
|
uniform vec3 sunDirection;
|
|
1292
1293
|
|
|
1293
1294
|
// Participating medium
|
|
@@ -1345,7 +1346,7 @@ uniform float shadowTopHeight;
|
|
|
1345
1346
|
uniform float shadowBottomHeight;
|
|
1346
1347
|
uniform vec4 shadowLayerMask;
|
|
1347
1348
|
uniform CloudDensityProfile densityProfile;
|
|
1348
|
-
`,
|
|
1349
|
+
`,j=`struct GroundIrradiance {
|
|
1349
1350
|
vec3 sun;
|
|
1350
1351
|
vec3 sky;
|
|
1351
1352
|
};
|
|
@@ -1363,7 +1364,7 @@ struct CloudDensityProfile {
|
|
|
1363
1364
|
vec4 linearTerms;
|
|
1364
1365
|
vec4 constantTerms;
|
|
1365
1366
|
};
|
|
1366
|
-
`;var Le=Object.defineProperty,S=(o,e,t,a)=>{for(var
|
|
1367
|
+
`;var Le=Object.defineProperty,S=(o,e,t,a)=>{for(var r=void 0,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=s(e,t,r)||r);return r&&Le(e,t,r),r};const Re=new n.Vector3,Ue=new u.Geodetic;class g extends z.AtmosphereMaterialBase{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},r=z.AtmosphereParameters.DEFAULT){super({name:"CloudsMaterial",glslVersion:n.GLSL3,vertexShader:u.resolveIncludes(Oe,{atmosphere:{bruneton:{common:P.common,definitions:P.definitions,runtime:P.runtime}},types:j}),fragmentShader:u.unrollLoops(u.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:{bruneton:{common:P.common,definitions:P.definitions,runtime:P.runtime}},types:j,parameters:oe,clouds:ie})),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),viewReprojectionMatrix: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(l.clouds.maxIterationCount),minStepSize:new n.Uniform(l.clouds.minStepSize),maxStepSize:new n.Uniform(l.clouds.maxStepSize),maxRayDistance:new n.Uniform(l.clouds.maxRayDistance),perspectiveStepScale:new n.Uniform(l.clouds.perspectiveStepScale),minDensity:new n.Uniform(l.clouds.minDensity),minExtinction:new n.Uniform(l.clouds.minExtinction),minTransmittance:new n.Uniform(l.clouds.minTransmittance),maxIterationCountToSun:new n.Uniform(l.clouds.maxIterationCountToSun),maxIterationCountToGround:new n.Uniform(l.clouds.maxIterationCountToGround),minSecondaryStepSize:new n.Uniform(l.clouds.minSecondaryStepSize),secondaryStepScale:new n.Uniform(l.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(l.clouds.maxShadowLengthIterationCount),minShadowLengthStepSize:new n.Uniform(l.clouds.minShadowLengthStepSize),maxShadowLengthRayDistance:new n.Uniform(l.clouds.maxShadowLengthRayDistance),hazeDensityScale:new n.Uniform(3e-5),hazeExponent:new n.Uniform(.001),hazeScatteringCoefficient:new n.Uniform(.9),hazeAbsorptionCoefficient:new n.Uniform(.5)}},r),this.temporalUpscale=!0,this.depthPacking=0,this.localWeatherChannels="rgba",this.shapeDetail=l.shapeDetail,this.turbulence=l.turbulence,this.shadowLength=l.lightShafts,this.haze=l.haze,this.multiScatteringOctaves=l.clouds.multiScatteringOctaves,this.accurateSunSkyLight=l.clouds.accurateSunSkyLight,this.accuratePhaseFunction=l.clouds.accuratePhaseFunction,this.shadowCascadeCount=l.shadow.cascadeCount,this.shadowSampleCount=8,this.scatterAnisotropy1=.7,this.scatterAnisotropy2=-.2,this.scatterAnisotropyMix=.5}onBeforeRender(e,t,a,r,i,s){const c=this.defines.USE_LOGDEPTHBUF!=null,h=e.capabilities.logarithmicDepthBuffer;h!==c&&(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,r=this.previousViewMatrix??e.matrixWorldInverse,i=t.inverseProjectionMatrix.value,s=t.inverseViewMatrix.value,c=t.reprojectionMatrix.value,h=t.viewReprojectionMatrix.value;if(this.temporalUpscale){const f=t.frame.value%16,m=t.resolution.value,v=re[f],A=(v.x-.5)/m.x*4,_=(v.y-.5)/m.y*4;t.temporalJitter.value.set(A,_),t.mipLevelScale.value=.25,i.copy(e.projectionMatrix),i.elements[8]+=A*2,i.elements[9]+=_*2,i.invert(),c.copy(a),c.elements[8]+=A*2,c.elements[9]+=_*2,c.multiply(r),h.copy(c).multiply(s)}else t.temporalJitter.value.setScalar(0),t.mipLevelScale.value=1,i.copy(e.projectionMatrixInverse),c.copy(a).multiply(r),h.copy(c).multiply(s);u.assertType(e),t.cameraNear.value=e.near,t.cameraFar.value=e.far;const d=e.getWorldPosition(t.cameraPosition.value),p=Re.copy(d).applyMatrix4(t.worldToECEFMatrix.value);try{t.cameraHeight.value=Ue.setFromECEF(p).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,r){this.uniforms.resolution.value.set(e,t),a!=null&&r!=null?this.uniforms.targetUvScale.value.set(e/a,t/r):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 Me=`// Taken from https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
|
|
1367
1368
|
// TODO: Use 5-taps version: https://www.shadertoy.com/view/MtVGWz
|
|
1368
1369
|
// Or even 4 taps (requires preprocessing in the input buffer):
|
|
1369
1370
|
// https://www.shadertoy.com/view/4tyGDD
|
|
@@ -1476,7 +1477,7 @@ vec4 textureCatmullRom(sampler2DArray tex, vec3 uv) {
|
|
|
1476
1477
|
result += texture(tex, vec3(texPos3.x, texPos3.y, uv.z)) * w3.x * w3.y;
|
|
1477
1478
|
return result;
|
|
1478
1479
|
}
|
|
1479
|
-
`,
|
|
1480
|
+
`,Ie=`precision highp float;
|
|
1480
1481
|
precision highp sampler2DArray;
|
|
1481
1482
|
|
|
1482
1483
|
#include "core/turbo"
|
|
@@ -1524,24 +1525,6 @@ const ivec4[4] bayerIndices = ivec4[4](
|
|
|
1524
1525
|
ivec4(10, 6, 9, 5)
|
|
1525
1526
|
);
|
|
1526
1527
|
|
|
1527
|
-
vec2 getUnjitteredUv(ivec2 coord) {
|
|
1528
|
-
return (vec2(coord) + 0.5 - jitterOffset) * texelSize;
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
vec4 getClosestFragment(const vec2 uv) {
|
|
1532
|
-
vec4 result = vec4(1e7, 0.0, 0.0, 0.0);
|
|
1533
|
-
vec4 neighbor;
|
|
1534
|
-
#pragma unroll_loop_start
|
|
1535
|
-
for (int i = 0; i < 9; ++i) {
|
|
1536
|
-
neighbor = textureOffset(depthVelocityBuffer, uv, neighborOffsets[i]);
|
|
1537
|
-
if (neighbor.r < result.r) {
|
|
1538
|
-
result = neighbor;
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
#pragma unroll_loop_end
|
|
1542
|
-
return result;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
1528
|
vec4 getClosestFragment(const ivec2 coord) {
|
|
1546
1529
|
vec4 result = vec4(1e7, 0.0, 0.0, 0.0);
|
|
1547
1530
|
vec4 neighbor;
|
|
@@ -1563,25 +1546,22 @@ void temporalUpscale(
|
|
|
1563
1546
|
out vec4 outputColor,
|
|
1564
1547
|
out float outputShadowLength
|
|
1565
1548
|
) {
|
|
1566
|
-
|
|
1549
|
+
vec4 currentColor = texelFetch(colorBuffer, lowResCoord, 0);
|
|
1550
|
+
#ifdef SHADOW_LENGTH
|
|
1551
|
+
vec4 currentShadowLength = vec4(texelFetch(shadowLengthBuffer, lowResCoord, 0).rgb, 1.0);
|
|
1552
|
+
#endif // SHADOW_LENGTH
|
|
1553
|
+
|
|
1567
1554
|
if (currentFrame) {
|
|
1568
1555
|
// Use the texel just rendered without any accumulation.
|
|
1569
|
-
outputColor =
|
|
1556
|
+
outputColor = currentColor;
|
|
1570
1557
|
#ifdef SHADOW_LENGTH
|
|
1571
|
-
outputShadowLength =
|
|
1558
|
+
outputShadowLength = currentShadowLength.r;
|
|
1572
1559
|
#endif // SHADOW_LENGTH
|
|
1573
1560
|
return;
|
|
1574
1561
|
}
|
|
1575
|
-
#endif // !defined(DEBUG_SHOW_VELOCITY)
|
|
1576
|
-
|
|
1577
|
-
vec2 unjitteredUv = getUnjitteredUv(coord);
|
|
1578
|
-
vec4 currentColor = texture(colorBuffer, unjitteredUv);
|
|
1579
|
-
#ifdef SHADOW_LENGTH
|
|
1580
|
-
vec4 currentShadowLength = vec4(texture(shadowLengthBuffer, unjitteredUv).rgb, 1.0);
|
|
1581
|
-
#endif // SHADOW_LENGTH
|
|
1582
1562
|
|
|
1583
|
-
vec4 depthVelocity = getClosestFragment(
|
|
1584
|
-
vec2 velocity = depthVelocity.gb
|
|
1563
|
+
vec4 depthVelocity = getClosestFragment(lowResCoord);
|
|
1564
|
+
vec2 velocity = depthVelocity.gb;
|
|
1585
1565
|
vec2 prevUv = vUv - velocity;
|
|
1586
1566
|
if (prevUv.x < 0.0 || prevUv.x > 1.0 || prevUv.y < 0.0 || prevUv.y > 1.0) {
|
|
1587
1567
|
outputColor = currentColor;
|
|
@@ -1599,10 +1579,6 @@ void temporalUpscale(
|
|
|
1599
1579
|
vec4 clippedColor = varianceClipping(colorBuffer, vUv, currentColor, historyColor, varianceGamma);
|
|
1600
1580
|
outputColor = clippedColor;
|
|
1601
1581
|
|
|
1602
|
-
#ifdef DEBUG_SHOW_VELOCITY
|
|
1603
|
-
outputColor.rgb = outputColor.rgb + vec3(abs(velocity), 0.0);
|
|
1604
|
-
#endif // DEBUG_SHOW_VELOCITY
|
|
1605
|
-
|
|
1606
1582
|
#ifdef SHADOW_LENGTH
|
|
1607
1583
|
// Sampling the shadow length history using scene depth doesn't make much
|
|
1608
1584
|
// sense, but it's too hard to derive it properly. At least this approach
|
|
@@ -1627,7 +1603,7 @@ void temporalAntialiasing(const ivec2 coord, out vec4 outputColor, out float out
|
|
|
1627
1603
|
#endif // SHADOW_LENGTH
|
|
1628
1604
|
|
|
1629
1605
|
vec4 depthVelocity = getClosestFragment(coord);
|
|
1630
|
-
vec2 velocity = depthVelocity.gb
|
|
1606
|
+
vec2 velocity = depthVelocity.gb;
|
|
1631
1607
|
|
|
1632
1608
|
vec2 prevUv = vUv - velocity;
|
|
1633
1609
|
if (prevUv.x < 0.0 || prevUv.x > 1.0 || prevUv.y < 0.0 || prevUv.y > 1.0) {
|
|
@@ -1642,10 +1618,6 @@ void temporalAntialiasing(const ivec2 coord, out vec4 outputColor, out float out
|
|
|
1642
1618
|
vec4 clippedColor = varianceClipping(colorBuffer, coord, currentColor, historyColor);
|
|
1643
1619
|
outputColor = mix(clippedColor, currentColor, temporalAlpha);
|
|
1644
1620
|
|
|
1645
|
-
#ifdef DEBUG_SHOW_VELOCITY
|
|
1646
|
-
outputColor.rgb = outputColor.rgb + vec3(abs(velocity), 0.0);
|
|
1647
|
-
#endif // DEBUG_SHOW_VELOCITY
|
|
1648
|
-
|
|
1649
1621
|
#ifdef SHADOW_LENGTH
|
|
1650
1622
|
vec4 historyShadowLength = vec4(texture(shadowLengthHistoryBuffer, prevUv).rgb, 1.0);
|
|
1651
1623
|
vec4 clippedShadowLength = varianceClipping(
|
|
@@ -1677,6 +1649,10 @@ void main() {
|
|
|
1677
1649
|
#if defined(SHADOW_LENGTH) && defined(DEBUG_SHOW_SHADOW_LENGTH)
|
|
1678
1650
|
outputColor = vec4(turbo(outputShadowLength * 0.05), 1.0);
|
|
1679
1651
|
#endif // defined(SHADOW_LENGTH) && defined(DEBUG_SHOW_SHADOW_LENGTH)
|
|
1652
|
+
|
|
1653
|
+
#ifdef DEBUG_SHOW_VELOCITY
|
|
1654
|
+
outputColor.rgb = outputColor.rgb + vec3(abs(texture(depthVelocityBuffer, vUv).gb) * 10.0, 0.0);
|
|
1655
|
+
#endif // DEBUG_SHOW_VELOCITY
|
|
1680
1656
|
}
|
|
1681
1657
|
`,Ne=`precision highp float;
|
|
1682
1658
|
|
|
@@ -1802,7 +1778,7 @@ vec4 varianceClipping(
|
|
|
1802
1778
|
) {
|
|
1803
1779
|
return varianceClipping(inputBuffer, coord, current, history, 1.0);
|
|
1804
1780
|
}
|
|
1805
|
-
`;var be=Object.defineProperty,ce=(o,e,t,a)=>{for(var
|
|
1781
|
+
`;var be=Object.defineProperty,ce=(o,e,t,a)=>{for(var r=void 0,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=s(e,t,r)||r);return r&&be(e,t,r),r};class Y extends n.RawShaderMaterial{constructor({colorBuffer:e=null,depthVelocityBuffer:t=null,shadowLengthBuffer:a=null,colorHistoryBuffer:r=null,shadowLengthHistoryBuffer:i=null}={}){super({name:"CloudsResolveMaterial",glslVersion:n.GLSL3,vertexShader:Ne,fragmentShader:u.unrollLoops(u.resolveIncludes(Ie,{core:{turbo:y.turbo},catmullRomSampling:Me,varianceClipping:se})),uniforms:{colorBuffer:new n.Uniform(e),depthVelocityBuffer:new n.Uniform(t),shadowLengthBuffer:new n.Uniform(a),colorHistoryBuffer:new n.Uniform(r),shadowLengthHistoryBuffer:new n.Uniform(i),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,r,i,s){const h=this.uniforms.frame.value%16,d=re[h],p=(d.x-.5)*4,f=(d.y-.5)*4;this.uniforms.jitterOffset.value.set(p,f)}}ce([u.define("TEMPORAL_UPSCALE")],Y.prototype,"temporalUpscale");ce([u.define("SHADOW_LENGTH")],Y.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 G(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 r;e&&(r=a.texture.clone(),r.isRenderTargetTexture=!0,a.depthVelocity=r,a.textures.push(r));let i;return t&&(i=a.texture.clone(),i.isRenderTargetTexture=!0,i.format=n.RedFormat,a.shadowLength=i,a.textures.push(i)),Object.assign(a,{depthVelocity:r??null,shadowLength:i??null})}class He extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...r},i){super("CloudsPass",r),this.atmosphere=i,this.width=0,this.height=0,this.currentMaterial=new g({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a},i),this.currentPass=new C.ShaderPass(this.currentMaterial),this.resolveMaterial=new Y,this.resolvePass=new C.ShaderPass(this.resolveMaterial),this.initRenderTargets({depthVelocity:!0,shadowLength:l.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,c,h;(s=this.currentRenderTarget)==null||s.dispose(),(c=this.resolveRenderTarget)==null||c.dispose(),(h=this.historyRenderTarget)==null||h.dispose();const t=G("Clouds",e),a=G("Clouds.A",{...e,depthVelocity:!1}),r=G("Clouds.B",{...e,depthVelocity:!1});this.currentRenderTarget=t,this.resolveRenderTarget=a,this.historyRenderTarget=r;const i=this.resolveMaterial.uniforms;i.colorBuffer.value=t.texture,i.depthVelocityBuffer.value=t.depthVelocity,i.shadowLengthBuffer.value=t.shadowLength,i.colorHistoryBuffer.value=r.texture,i.shadowLengthHistoryBuffer.value=r.shadowLength}copyShadow(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const r=e.cascades[a];t.shadowIntervals.value[a].copy(r.interval),t.shadowMatrices.value[a].copy(r.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),r=Math.ceil(t/4);this.currentRenderTarget.setSize(a,r),this.currentMaterial.setSize(a*4,r*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,r=o.getContext();D(r instanceof WebGL2RenderingContext),o.setRenderTarget(e);const i=[];if(a!=null)for(let s=0;s<e.depth;++s)r.framebufferTextureLayer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+s,a,0,s),i.push(r.COLOR_ATTACHMENT0+s);r.drawBuffers(i)}class ae extends C.ShaderPass{render(e,t,a,r,i){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;
|
|
1806
1782
|
precision highp sampler3D;
|
|
1807
1783
|
|
|
1808
1784
|
#include <common>
|
|
@@ -1824,7 +1800,6 @@ uniform float maxStepSize;
|
|
|
1824
1800
|
uniform float opticalDepthTailScale;
|
|
1825
1801
|
|
|
1826
1802
|
in vec2 vUv;
|
|
1827
|
-
in vec3 vEllipsoidCenter;
|
|
1828
1803
|
|
|
1829
1804
|
layout(location = 0) out vec4 outputColor[CASCADE_COUNT];
|
|
1830
1805
|
|
|
@@ -1958,11 +1933,8 @@ void cascade(
|
|
|
1958
1933
|
vec2 clip = vUv * 2.0 - 1.0;
|
|
1959
1934
|
vec4 point = inverseShadowMatrices[cascadeIndex] * vec4(clip.xy, -1.0, 1.0);
|
|
1960
1935
|
point /= point.w;
|
|
1961
|
-
vec3 sunPosition =
|
|
1936
|
+
vec3 sunPosition = (worldToECEFMatrix * vec4(point.xyz, 1.0)).xyz + altitudeCorrection;
|
|
1962
1937
|
|
|
1963
|
-
// The sun direction is in ECEF. Since the view matrix is constructed with the
|
|
1964
|
-
// ellipsoid matrix already applied, there's no need to apply the inverse
|
|
1965
|
-
// matrix here.
|
|
1966
1938
|
vec3 rayDirection = normalize(-sunDirection);
|
|
1967
1939
|
float rayNear;
|
|
1968
1940
|
float rayFar;
|
|
@@ -1976,7 +1948,7 @@ void cascade(
|
|
|
1976
1948
|
// Velocity for temporal resolution.
|
|
1977
1949
|
#ifdef TEMPORAL_PASS
|
|
1978
1950
|
vec3 frontPosition = color.x * rayDirection + rayOrigin;
|
|
1979
|
-
vec3 frontPositionWorld =
|
|
1951
|
+
vec3 frontPositionWorld = (ecefToWorldMatrix * vec4(frontPosition - altitudeCorrection, 1.0)).xyz;
|
|
1980
1952
|
vec4 prevClip = reprojectionMatrices[cascadeIndex] * vec4(frontPositionWorld, 1.0);
|
|
1981
1953
|
prevClip /= prevClip.w;
|
|
1982
1954
|
vec2 prevUv = prevClip.xy * 0.5 + 0.5;
|
|
@@ -2001,18 +1973,12 @@ void main() {
|
|
|
2001
1973
|
}
|
|
2002
1974
|
`,We=`precision highp float;
|
|
2003
1975
|
|
|
2004
|
-
uniform vec3 ellipsoidCenter;
|
|
2005
|
-
uniform vec3 altitudeCorrection;
|
|
2006
|
-
|
|
2007
1976
|
layout(location = 0) in vec3 position;
|
|
2008
1977
|
|
|
2009
1978
|
out vec2 vUv;
|
|
2010
|
-
out vec3 vEllipsoidCenter;
|
|
2011
1979
|
|
|
2012
1980
|
void main() {
|
|
2013
1981
|
vUv = position.xy * 0.5 + 0.5;
|
|
2014
|
-
vEllipsoidCenter = ellipsoidCenter + altitudeCorrection;
|
|
2015
|
-
|
|
2016
1982
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
2017
1983
|
}
|
|
2018
1984
|
`,Be=`// Implements Structured Volume Sampling in fragment shader:
|
|
@@ -2116,7 +2082,7 @@ void intersectStructuredPlanes(
|
|
|
2116
2082
|
stepOffset += stepSize;
|
|
2117
2083
|
}
|
|
2118
2084
|
}
|
|
2119
|
-
`;var Ge=Object.defineProperty,
|
|
2085
|
+
`;var Ge=Object.defineProperty,L=(o,e,t,a)=>{for(var r=void 0,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=s(e,t,r)||r);return r&&Ge(e,t,r),r};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:j,parameters:oe,structuredSampling:Be,clouds:ie})),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(l.shadow.maxIterationCount),minStepSize:new n.Uniform(l.shadow.minStepSize),maxStepSize:new n.Uniform(l.shadow.maxStepSize),minDensity:new n.Uniform(l.shadow.minDensity),minExtinction:new n.Uniform(l.shadow.minExtinction),minTransmittance:new n.Uniform(l.shadow.minTransmittance),opticalDepthTailScale:new n.Uniform(2)},defines:{SHADOW:"1",TEMPORAL_PASS:"1",TEMPORAL_JITTER:"1"}}),this.localWeatherChannels="rgba",this.cascadeCount=l.shadow.cascadeCount,this.temporalPass=!0,this.temporalJitter=!0,this.shapeDetail=l.shapeDetail,this.turbulence=l.turbulence,this.cascadeCount=l.shadow.cascadeCount}setSize(e,t){this.uniforms.resolution.value.set(e,t)}}L([u.defineExpression("LOCAL_WEATHER_CHANNELS",{validate:o=>/^[rgba]{4}$/.test(o)})],E.prototype,"localWeatherChannels");L([u.defineInt("CASCADE_COUNT",{min:1,max:4})],E.prototype,"cascadeCount");L([u.define("TEMPORAL_PASS")],E.prototype,"temporalPass");L([u.define("TEMPORAL_JITTER")],E.prototype,"temporalJitter");L([u.define("SHAPE_DETAIL")],E.prototype,"shapeDetail");L([u.define("TURBULENCE")],E.prototype,"turbulence");const Ve=`precision highp float;
|
|
2120
2086
|
precision highp sampler2DArray;
|
|
2121
2087
|
|
|
2122
2088
|
#define VARIANCE_9_SAMPLES 1
|
|
@@ -2202,7 +2168,7 @@ void main() {
|
|
|
2202
2168
|
vUv = position.xy * 0.5 + 0.5;
|
|
2203
2169
|
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
2204
2170
|
}
|
|
2205
|
-
`;var je=Object.defineProperty,Ye=(o,e,t,a)=>{for(var
|
|
2171
|
+
`;var je=Object.defineProperty,Ye=(o,e,t,a)=>{for(var r=void 0,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=s(e,t,r)||r);return r&&je(e,t,r),r};class he 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=l.shadow.cascadeCount}setSize(e,t){this.uniforms.texelSize.value.set(1/e,1/t)}}Ye([u.defineInt("CASCADE_COUNT",{min:1,max:4})],he.prototype,"cascadeCount");function V(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 Ze extends le{constructor({parameterUniforms:e,layerUniforms:t,atmosphereUniforms:a,...r}){super("ShadowPass",r),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 i,s,c;(i=this.currentRenderTarget)==null||i.dispose(),(s=this.resolveRenderTarget)==null||s.dispose(),(c=this.historyRenderTarget)==null||c.dispose();const e=V("Shadow"),t=this.temporalPass?V("Shadow.A"):null,a=this.temporalPass?V("Shadow.B"):null;this.currentRenderTarget=e,this.resolveRenderTarget=t,this.historyRenderTarget=a;const r=this.resolveMaterial.uniforms;r.inputBuffer.value=e.texture,r.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 r=e.cascades[a];t.inverseShadowMatrices.value[a].copy(r.inverseMatrix)}}copyReprojection(){const e=this.shadow,t=this.currentMaterial.uniforms;for(let a=0;a<e.cascadeCount;++a){const r=e.cascades[a];t.reprojectionMatrices.value[a].copy(r.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 r,i;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),(r=this.resolveRenderTarget)==null||r.setSize(e,t,a),(i=this.historyRenderTarget)==null||i.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 qe(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 k=[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,r=0,i=1/0,s=0;k.fill(0);for(let c=0;c<e.length;++c){const{altitude:h,height:d,shadow:p}=e[c],f=h+d;d>0&&(h<a&&(a=h),p&&h<i&&(i=h),f>r&&(r=f),p&&f>s&&(s=f)),k[c]=p?1:0}a!==1/0?(o.minHeight.value=a,o.maxHeight.value=r):(D(r===0),o.minHeight.value=0),i!==1/0?(o.shadowBottomHeight.value=i,o.shadowTopHeight.value=s):(D(s===0),o.shadowBottomHeight.value=0),o.shadowLayerMask.value.fromArray(k)}function $e(o,e){return{bottomRadius:new n.Uniform(o.bottomRadius),topRadius:new n.Uniform(o.topRadius),worldToECEFMatrix:new n.Uniform(e.worldToECEFMatrix),ecefToWorldMatrix:new n.Uniform(e.ecefToWorldMatrix),altitudeCorrection:new n.Uniform(e.altitudeCorrection),sunDirection:new n.Uniform(e.sunDirection)}}const Je=`uniform sampler2D cloudsBuffer;
|
|
2206
2172
|
|
|
2207
2173
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
|
2208
2174
|
#ifdef SKIP_RENDERING
|
|
@@ -2213,5 +2179,5 @@ void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
|
|
2213
2179
|
outputColor.a = inputColor.a * (1.0 - clouds.a) + clouds.a;
|
|
2214
2180
|
#endif // SKIP_RENDERING
|
|
2215
2181
|
}
|
|
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;
|
|
2182
|
+
`;var Qe=Object.defineProperty,et=(o,e,t,a)=>{for(var r=void 0,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=s(e,t,r)||r);return r&&Qe(e,t,r),r};const U=new n.Vector3,tt=new n.Vector2,nt=new n.Matrix3,at=["maxIterationCount","minStepSize","maxStepSize","maxRayDistance","perspectiveStepScale","minDensity","minExtinction","minTransmittance","maxIterationCountToSun","maxIterationCountToGround","minSecondaryStepSize","secondaryStepScale","maxShadowFilterRadius","maxShadowLengthIterationCount","minShadowLengthStepSize","maxShadowLengthRayDistance","hazeDensityScale","hazeExponent","hazeScatteringCoefficient","hazeAbsorptionCoefficient"],rt=["multiScatteringOctaves","accurateSunSkyLight","accuratePhaseFunction"],it=["maxIterationCount","minStepSize","maxStepSize","minDensity","minExtinction","minTransmittance","opticalDepthTailScale"],ot=["temporalJitter"],st=["temporalPass"],ct=["cascadeCount","mapSize","maxFar","farScale","splitMode","splitLambda"],w={type:"change"},ue={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=z.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=W.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.worldToECEFMatrix=new n.Matrix4,this.ecefToWorldMatrix=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:r,width:i,height:s,resolutionX:c=i,resolutionY:h=s}={...ue,...t};this.shadowMaps=new Ee({cascadeCount:l.shadow.cascadeCount,mapSize:l.shadow.mapSize,splitLambda:.6}),this.parameterUniforms=qe({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,{worldToECEFMatrix:this.worldToECEFMatrix,ecefToWorldMatrix:this.ecefToWorldMatrix,altitudeCorrection:this.altitudeCorrection,sunDirection:this.sunDirection});const d={shadow:this.shadowMaps,parameterUniforms:this.parameterUniforms,layerUniforms:this.layerUniforms,atmosphereUniforms:this.atmosphereUniforms};this.shadowPass=new Ze(d),this.shadowPass.mainCamera=e,this.cloudsPass=new He(d,a),this.cloudsPass.mainCamera=e,this.clouds=u.definePropertyShorthand(u.defineUniformShorthand({},this.cloudsPass.currentMaterial,at),this.cloudsPass.currentMaterial,rt),this.shadow=u.definePropertyShorthand(u.defineUniformShorthand({},this.shadowPass.currentMaterial,it),this.shadowPass.currentMaterial,ot,this.shadowPass,st,this.shadowMaps,ct),this.resolution=new C.Resolution(this,c,h,r),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(U.copy(this.shapeVelocity).multiplyScalar(e)),t.shapeDetailOffset.value.add(U.copy(this.shapeDetailVelocity).multiplyScalar(e));const a=this.worldToECEFMatrix;this.ecefToWorldMatrix.copy(a).invert();const r=this.camera.getWorldPosition(U).applyMatrix4(this.worldToECEFMatrix),i=this.altitudeCorrection;this.correctAltitude?z.getAltitudeCorrectionOffset(r,this.atmosphere.bottomRadius,this.ellipsoid,i):i.setScalar(0);const s=this.ellipsoid.getSurfaceNormal(r,U),c=this.sunDirection.dot(s),h=u.lerp(1e6,1e3,c),d=nt.setFromMatrix4(a).transpose();this.shadowMaps.update(this.camera,U.copy(this.sunDirection).applyMatrix3(d),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,r=t.currentMaterial.uniforms,i=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:i.shadowIntervals.value,matrices:i.shadowMatrices.value,inverseMatrices:r.inverseShadowMatrices.value,far:e.far,topHeight:i.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:r,shadowPass:i,cloudsPass:s}=this;if(r.cascadeCount!==this.shadowCascadeCount||!r.mapSize.equals(this.shadowMapSize)){const{width:f,height:m}=r.mapSize,v=r.cascadeCount;this.shadowMapSize.set(f,m),this.shadowCascadeCount=v,i.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(),i.update(e,this.frame,a),s.shadowBuffer=i.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:r,height:i}=a;this.cloudsPass.setSize(r,i)}setDepthTexture(e,t){this.shadowPass.setDepthTexture(e,t),this.cloudsPass.setDepthTexture(e,t)}set qualityPreset(e){const{clouds:t,shadow:a,...r}=_e[e];Object.assign(this,r),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 lt=128,ht=32,B="45a1c6c1bb9fd38b3680fd120795ff4c32df68ff",ut=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${B}/packages/clouds/assets/local_weather.png`,dt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${B}/packages/clouds/assets/shape.bin`,pt=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${B}/packages/clouds/assets/shape_detail.bin`,ft=`https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${B}/packages/clouds/assets/turbulence.png`;exports.CLOUD_SHAPE_DETAIL_TEXTURE_SIZE=ht;exports.CLOUD_SHAPE_TEXTURE_SIZE=lt;exports.CloudLayer=x;exports.CloudLayers=W;exports.CloudsEffect=de;exports.DEFAULT_LOCAL_WEATHER_URL=ut;exports.DEFAULT_SHAPE_DETAIL_URL=pt;exports.DEFAULT_SHAPE_URL=dt;exports.DEFAULT_TURBULENCE_URL=ft;exports.DensityProfile=b;exports.cloudsPassOptionsDefaults=ue;
|
|
2217
2183
|
//# sourceMappingURL=shared.cjs.map
|