@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/build/shared.js CHANGED
@@ -115,17 +115,17 @@ const b = class b extends Array {
115
115
  // Redundant, but need to avoid creating garbage here as this runs every frame.
116
116
  packIntervalHeights(e, t) {
117
117
  for (let s = 0; s < 4; ++s) {
118
- const c = this[s];
118
+ const l = this[s];
119
119
  let h = P[s];
120
- h.value = c.altitude, h.flag = 0, h = P[s + 4], h.value = c.altitude + c.height, h.flag = 1;
120
+ h.value = l.altitude, h.flag = 0, h = P[s + 4], h.value = l.altitude + l.height, h.flag = 1;
121
121
  }
122
122
  P.sort(nt);
123
123
  let n = 0, a = 0;
124
124
  for (let s = 0; s < P.length; ++s) {
125
- const { value: c, flag: h } = P[s];
125
+ const { value: l, flag: h } = P[s];
126
126
  if (a === 0 && s > 0) {
127
127
  const u = L[n++];
128
- u.min = P[s - 1].value, u.max = c;
128
+ u.min = P[s - 1].value, u.max = l;
129
129
  }
130
130
  a += h === 0 ? 1 : -1;
131
131
  }
@@ -176,7 +176,7 @@ b.DEFAULT = /* @__PURE__ */ new b([
176
176
  { channel: "a" }
177
177
  ]);
178
178
  let K = b;
179
- var at = process.env.NODE_ENV === "production", fe = "Invariant failed";
179
+ var at = "production" === "production", fe = "Invariant failed";
180
180
  function A(o, e) {
181
181
  if (!o) {
182
182
  if (at)
@@ -206,8 +206,8 @@ class U {
206
206
  for (let i = 0; i < 4; ++i) {
207
207
  const s = this.far[i];
208
208
  s.applyMatrix4(a);
209
- const c = Math.abs(s.z);
210
- n ? s.z *= Math.min(t / c, 1) : s.multiplyScalar(Math.min(t / c, 1));
209
+ const l = Math.abs(s.z);
210
+ n ? s.z *= Math.min(t / l, 1) : s.multiplyScalar(Math.min(t / l, 1));
211
211
  }
212
212
  return this;
213
213
  }
@@ -256,8 +256,8 @@ const it = {
256
256
  },
257
257
  practical: (o, e, t, n = 0.5, a = []) => {
258
258
  for (let i = 0; i < o; ++i) {
259
- const s = (e + (t - e) * (i + 1) / o) / t, c = e * (t / e) ** ((i + 1) / o) / t;
260
- a[i] = Te(s, c, n);
259
+ const s = (e + (t - e) * (i + 1) / o) / t, l = e * (t / e) ** ((i + 1) / o) / t;
260
+ a[i] = Te(s, l, n);
261
261
  }
262
262
  return a.length = o, a;
263
263
  }
@@ -282,14 +282,14 @@ class ht {
282
282
  maxFar: a,
283
283
  farScale: i,
284
284
  splitMode: s,
285
- splitLambda: c,
285
+ splitLambda: l,
286
286
  margin: h,
287
287
  fade: u
288
288
  } = {
289
289
  ...lt,
290
290
  ...e
291
291
  };
292
- this.cascadeCount = t, this.mapSize.copy(n), this.maxFar = a, this.farScale = i, this.splitMode = s, this.splitLambda = c, this.margin = h, this.fade = u;
292
+ this.cascadeCount = t, this.mapSize.copy(n), this.maxFar = a, this.farScale = i, this.splitMode = s, this.splitLambda = l, this.margin = h, this.fade = u;
293
293
  }
294
294
  get cascadeCount() {
295
295
  return this.cascades.length;
@@ -334,8 +334,8 @@ class ht {
334
334
  a[0].distanceTo(n[2])
335
335
  );
336
336
  if (this.fade) {
337
- const s = e.near, c = this.far, h = a[0].z / (c - s);
338
- i += 0.25 * h ** 2 * (c - s);
337
+ const s = e.near, l = this.far, h = a[0].z / (l - s);
338
+ i += 0.25 * h ** 2 * (l - s);
339
339
  }
340
340
  return i * 0.5;
341
341
  }
@@ -347,11 +347,11 @@ class ht {
347
347
  ), i = ge.multiplyMatrices(
348
348
  ge.copy(a).invert(),
349
349
  e.matrixWorld
350
- ), s = this.frusta, c = this.cascades;
351
- A(s.length === c.length);
350
+ ), s = this.frusta, l = this.cascades;
351
+ A(s.length === l.length);
352
352
  const h = this.margin, u = this.mapSize;
353
353
  for (let d = 0; d < s.length; ++d) {
354
- const p = s[d], g = c[d], S = this.getFrustumRadius(e, s[d]), ee = -S, te = S, ne = S, ae = -S;
354
+ const p = s[d], g = l[d], S = this.getFrustumRadius(e, s[d]), ee = -S, te = S, ne = S, ae = -S;
355
355
  g.projectionMatrix.makeOrthographic(
356
356
  ee,
357
357
  te,
@@ -378,14 +378,14 @@ class ht {
378
378
  const a = this.cascades, i = this.cascadeCount;
379
379
  for (let s = 0; s < i; ++s) {
380
380
  const {
381
- matrix: c,
381
+ matrix: l,
382
382
  inverseMatrix: h,
383
383
  projectionMatrix: u,
384
384
  inverseProjectionMatrix: d,
385
385
  viewMatrix: p,
386
386
  inverseViewMatrix: g
387
387
  } = a[s];
388
- d.copy(u).invert(), p.copy(g).invert(), c.copy(u).multiply(p), h.copy(g).multiply(d);
388
+ d.copy(u).invert(), p.copy(g).invert(), l.copy(u).multiply(p), h.copy(g).multiply(d);
389
389
  }
390
390
  }
391
391
  }
@@ -457,12 +457,12 @@ const Se = [
457
457
  minExtinction: 1e-5,
458
458
  minTransmittance: 1e-4
459
459
  }
460
- }, l = ut, dt = {
460
+ }, c = ut, dt = {
461
461
  // TODO: We cloud decrease multi-scattering octaves for lower quality presets,
462
462
  // but it leads to a loss of higher frequency scattering, making it darker
463
463
  // overall, which suggests the need for a fudge factor to scale the radiance.
464
464
  low: {
465
- ...l,
465
+ ...c,
466
466
  lightShafts: !1,
467
467
  // Expensive
468
468
  shapeDetail: !1,
@@ -470,7 +470,7 @@ const Se = [
470
470
  turbulence: !1,
471
471
  // Expensive
472
472
  clouds: {
473
- ...l.clouds,
473
+ ...c.clouds,
474
474
  accurateSunSkyIrradiance: !1,
475
475
  // Greatly reduces texel reads.
476
476
  maxIterationCount: 200,
@@ -486,7 +486,7 @@ const Se = [
486
486
  // Only 1 march makes big difference
487
487
  },
488
488
  shadow: {
489
- ...l.shadow,
489
+ ...c.shadow,
490
490
  maxIterationCount: 25,
491
491
  minDensity: 1e-4,
492
492
  minExtinction: 1e-4,
@@ -499,13 +499,13 @@ const Se = [
499
499
  }
500
500
  },
501
501
  medium: {
502
- ...l,
502
+ ...c,
503
503
  lightShafts: !1,
504
504
  // Expensive
505
505
  turbulence: !1,
506
506
  // Expensive
507
507
  clouds: {
508
- ...l.clouds,
508
+ ...c.clouds,
509
509
  minDensity: 1e-4,
510
510
  minExtinction: 1e-4,
511
511
  accurateSunSkyIrradiance: !1,
@@ -513,22 +513,22 @@ const Se = [
513
513
  maxIterationCountToGround: 1
514
514
  },
515
515
  shadow: {
516
- ...l.shadow,
516
+ ...c.shadow,
517
517
  minDensity: 1e-4,
518
518
  minExtinction: 1e-4,
519
519
  mapSize: /* @__PURE__ */ new m(256, 256)
520
520
  }
521
521
  },
522
- high: l,
522
+ high: c,
523
523
  // Consider high quality preset as default.
524
524
  ultra: {
525
- ...l,
525
+ ...c,
526
526
  clouds: {
527
- ...l.clouds,
527
+ ...c.clouds,
528
528
  minStepSize: 10
529
529
  },
530
530
  shadow: {
531
- ...l.shadow,
531
+ ...c.shadow,
532
532
  mapSize: /* @__PURE__ */ new m(1024, 1024)
533
533
  }
534
534
  }
@@ -952,6 +952,7 @@ vec3 getGroundSunSkyIrradiance(
952
952
  #ifdef ACCURATE_SUN_SKY_IRRADIANCE
953
953
  return GetSunAndSkyIrradiance(
954
954
  (position - surfaceNormal * height) * METER_TO_LENGTH_UNIT,
955
+ surfaceNormal,
955
956
  sunDirection,
956
957
  skyIrradiance
957
958
  );
@@ -963,7 +964,11 @@ vec3 getGroundSunSkyIrradiance(
963
964
 
964
965
  vec3 getCloudsSunSkyIrradiance(const vec3 position, const float height, out vec3 skyIrradiance) {
965
966
  #ifdef ACCURATE_SUN_SKY_IRRADIANCE
966
- return GetSunAndSkyIrradiance(position * METER_TO_LENGTH_UNIT, sunDirection, skyIrradiance);
967
+ return GetSunAndSkyIrradianceForParticle(
968
+ position * METER_TO_LENGTH_UNIT,
969
+ sunDirection,
970
+ skyIrradiance
971
+ );
967
972
  #else // ACCURATE_SUN_SKY_IRRADIANCE
968
973
  float alpha = remapClamped(height, minHeight, maxHeight);
969
974
  skyIrradiance = mix(vCloudsIrradiance.minSky, vCloudsIrradiance.maxSky, alpha);
@@ -989,10 +994,9 @@ vec3 approximateIrradianceFromGround(
989
994
  vec3 skyIrradiance;
990
995
  vec3 sunIrradiance = getGroundSunSkyIrradiance(position, surfaceNormal, height, skyIrradiance);
991
996
  const float groundAlbedo = 0.3;
992
- vec3 groundIrradiance = skyIrradiance + (1.0 - coverage) * sunIrradiance * RECIPROCAL_PI2;
993
- vec3 bouncedLight = groundAlbedo * RECIPROCAL_PI * groundIrradiance;
994
- vec3 bouncedIrradiance = bouncedLight * exp(-opticalDepthToGround);
995
- return albedo * bouncedIrradiance * RECIPROCAL_PI4 * groundIrradianceScale;
997
+ vec3 groundIrradiance = skyIrradiance + (1.0 - coverage) * sunIrradiance;
998
+ vec3 bouncedRadiance = groundAlbedo * RECIPROCAL_PI * groundIrradiance;
999
+ return bouncedRadiance * exp(-opticalDepthToGround);
996
1000
  }
997
1001
  #endif // GROUND_IRRADIANCE
998
1002
 
@@ -1082,28 +1086,28 @@ vec4 marchClouds(
1082
1086
  );
1083
1087
  }
1084
1088
 
1085
- float scattering = approximateMultipleScattering(opticalDepth, cosTheta);
1086
- vec3 radiance = albedo * sunIrradiance * scattering;
1089
+ vec3 radiance = sunIrradiance * approximateMultipleScattering(opticalDepth, cosTheta);
1087
1090
 
1088
1091
  #ifdef GROUND_IRRADIANCE
1089
1092
  // Fudge factor for the irradiance from ground.
1090
1093
  if (height < shadowTopHeight && mipLevel < 0.5) {
1091
- radiance += approximateIrradianceFromGround(
1094
+ vec3 groundIrradiance = approximateIrradianceFromGround(
1092
1095
  position,
1093
1096
  surfaceNormal,
1094
1097
  height,
1095
1098
  mipLevel,
1096
1099
  jitter
1097
1100
  );
1101
+ radiance += groundIrradiance * RECIPROCAL_PI4 * groundIrradianceScale;
1098
1102
  }
1099
1103
  #endif // GROUND_IRRADIANCE
1100
1104
 
1101
1105
  // Crude approximation of sky gradient. Better than none in the shadows.
1102
- float skyGradient = dot(0.5 + weather.heightFraction, media.weight);
1103
- radiance += albedo * skyIrradiance * RECIPROCAL_PI4 * skyGradient * skyIrradianceScale;
1106
+ float skyGradient = dot(weather.heightFraction * 0.5 + 0.5, media.weight);
1107
+ radiance += skyIrradiance * RECIPROCAL_PI4 * skyGradient * skyIrradianceScale;
1104
1108
 
1105
- // Finally multiply by extinction (redundant but kept for clarity).
1106
- radiance *= media.extinction;
1109
+ // Finally multiply by scattering.
1110
+ radiance *= media.scattering;
1107
1111
 
1108
1112
  #ifdef POWDER
1109
1113
  radiance *= 1.0 - powderScale * exp(-media.extinction * powderExponent);
@@ -1156,7 +1160,7 @@ float marchShadowLength(
1156
1160
  float maxRayDistance = rayNearFar.y - rayNearFar.x;
1157
1161
  float stepSize = minShadowLengthStepSize;
1158
1162
  float rayDistance = stepSize * jitter;
1159
- const float attenuationFactor = 1.0 - 1e-3;
1163
+ const float attenuationFactor = 1.0 - 5e-4;
1160
1164
  float attenuation = 1.0;
1161
1165
 
1162
1166
  // TODO: This march is closed, and sample resolution can be much lower.
@@ -1202,25 +1206,33 @@ vec4 approximateHaze(
1202
1206
  return vec4(0.0); // Prevent artifact in views from space
1203
1207
  }
1204
1208
 
1209
+ // Blend two normals by the difference in angle so that normal near the
1210
+ // ground becomes that of the origin, and in the sky that of the horizon.
1211
+ vec3 normalAtOrigin = normalize(rayOrigin);
1212
+ vec3 normalAtHorizon = (rayOrigin - dot(rayOrigin, rayDirection) * rayDirection) / bottomRadius;
1213
+ float alpha = remapClamped(dot(normalAtOrigin, normalAtHorizon), 0.9, 1.0);
1214
+ vec3 normal = mix(normalAtOrigin, normalAtHorizon, alpha);
1215
+
1205
1216
  // Analytical optical depth where density exponentially decreases with height.
1206
1217
  // Based on: https://iquilezles.org/articles/fog/
1207
- float angle = max(dot(normalize(rayOrigin), rayDirection), 1e-5);
1218
+ float angle = max(dot(normal, rayDirection), 1e-5);
1208
1219
  float exponent = angle * hazeExponent;
1220
+ float linearTerm = density / hazeExponent / angle;
1221
+
1209
1222
  // Derive the optical depths separately for with and without shadow length.
1210
1223
  float expTerm = 1.0 - exp(-maxRayDistance * exponent);
1211
1224
  float shadowExpTerm = 1.0 - exp(-min(maxRayDistance, shadowLength) * exponent);
1212
- float linearTerm = density / hazeExponent / angle;
1213
1225
  float opticalDepth = expTerm * linearTerm;
1214
- float effectiveOpticalDepth = max((expTerm - shadowExpTerm) * linearTerm, 0.0);
1226
+ float shadowOpticalDepth = max((expTerm - shadowExpTerm) * linearTerm, 0.0);
1227
+ float transmittance = saturate(1.0 - exp(-opticalDepth));
1228
+ float shadowTransmittance = saturate(1.0 - exp(-shadowOpticalDepth));
1215
1229
 
1216
1230
  vec3 skyIrradiance = vGroundIrradiance.sky;
1217
1231
  vec3 sunIrradiance = vGroundIrradiance.sun;
1218
- vec3 irradiance = sunIrradiance * phaseFunction(cosTheta);
1219
- irradiance += skyIrradiance * RECIPROCAL_PI4 * skyIrradianceScale;
1220
- vec3 inscatter = albedo * irradiance * saturate(1.0 - exp(-effectiveOpticalDepth));
1221
-
1222
- // Inscatter is attenuated by shadow length, but transmittance is not.
1223
- return vec4(inscatter, saturate(1.0 - exp(-opticalDepth)));
1232
+ vec3 inscatter = sunIrradiance * phaseFunction(cosTheta) * shadowTransmittance;
1233
+ inscatter += skyIrradiance * RECIPROCAL_PI4 * skyIrradianceScale * transmittance;
1234
+ inscatter *= hazeScatteringCoefficient / (hazeAbsorptionCoefficient + hazeScatteringCoefficient);
1235
+ return vec4(inscatter, transmittance);
1224
1236
  }
1225
1237
 
1226
1238
  #endif // HAZE
@@ -1239,8 +1251,7 @@ void applyAerialPerspective(
1239
1251
  sunDirection,
1240
1252
  transmittance
1241
1253
  );
1242
- float clampedAlpha = max(color.a, 1e-7);
1243
- color.rgb = mix(vec3(0.0), color.rgb * transmittance / clampedAlpha + inscatter, color.a);
1254
+ color.rgb = color.rgb * transmittance + inscatter * color.a;
1244
1255
  }
1245
1256
 
1246
1257
  bool rayIntersectsGround(const vec3 cameraPosition, const vec3 rayDirection) {
@@ -1519,7 +1530,8 @@ void main() {
1519
1530
  cosTheta,
1520
1531
  shadowLength
1521
1532
  );
1522
- color = color * (1.0 - haze.a) + haze;
1533
+ color.rgb = mix(color.rgb, haze.rgb, haze.a);
1534
+ color.a = color.a * (1.0 - haze.a) + haze.a;
1523
1535
  #endif // HAZE
1524
1536
 
1525
1537
  outputColor = color;
@@ -1697,7 +1709,7 @@ MediaSample sampleMedia(
1697
1709
  }
1698
1710
  #endif // SHAPE_DETAIL
1699
1711
 
1700
- // Nicely decrease the density at the bottom.
1712
+ // Apply the density profiles.
1701
1713
  density = saturate(density * densityScales * getLayerDensity(weather.heightFraction));
1702
1714
 
1703
1715
  MediaSample media;
@@ -1752,7 +1764,7 @@ out GroundIrradiance vGroundIrradiance;
1752
1764
  out CloudsIrradiance vCloudsIrradiance;
1753
1765
 
1754
1766
  void sampleSunSkyIrradiance(const vec3 positionECEF) {
1755
- vGroundIrradiance.sun = GetSunAndSkyIrradiance(
1767
+ vGroundIrradiance.sun = GetSunAndSkyIrradianceForParticle(
1756
1768
  positionECEF * METER_TO_LENGTH_UNIT,
1757
1769
  sunDirection,
1758
1770
  vGroundIrradiance.sky
@@ -1760,12 +1772,12 @@ void sampleSunSkyIrradiance(const vec3 positionECEF) {
1760
1772
 
1761
1773
  vec3 surfaceNormal = normalize(positionECEF);
1762
1774
  vec2 radii = (bottomRadius + vec2(minHeight, maxHeight)) * METER_TO_LENGTH_UNIT;
1763
- vCloudsIrradiance.minSun = GetSunAndSkyIrradiance(
1775
+ vCloudsIrradiance.minSun = GetSunAndSkyIrradianceForParticle(
1764
1776
  surfaceNormal * radii.x,
1765
1777
  sunDirection,
1766
1778
  vCloudsIrradiance.minSky
1767
1779
  );
1768
- vCloudsIrradiance.maxSun = GetSunAndSkyIrradiance(
1780
+ vCloudsIrradiance.maxSun = GetSunAndSkyIrradianceForParticle(
1769
1781
  surfaceNormal * radii.y,
1770
1782
  sunDirection,
1771
1783
  vCloudsIrradiance.maxSky
@@ -1800,7 +1812,6 @@ uniform vec3 sunDirection;
1800
1812
  // Participating medium
1801
1813
  uniform float scatteringCoefficient;
1802
1814
  uniform float absorptionCoefficient;
1803
- uniform vec3 albedo;
1804
1815
 
1805
1816
  // Primary raymarch
1806
1817
  uniform float minDensity;
@@ -1832,6 +1843,8 @@ uniform float turbulenceDisplacement;
1832
1843
  #ifdef HAZE
1833
1844
  uniform float hazeDensityScale;
1834
1845
  uniform float hazeExponent;
1846
+ uniform float hazeScatteringCoefficient;
1847
+ uniform float hazeAbsorptionCoefficient;
1835
1848
  #endif // HAZE
1836
1849
 
1837
1850
  // Cloud layers
@@ -1934,25 +1947,24 @@ class y extends je {
1934
1947
  mipLevelScale: new r(1),
1935
1948
  stbnTexture: new r(null),
1936
1949
  // Scattering
1937
- albedo: new r(new f()),
1938
- skyIrradianceScale: new r(2.5),
1939
- groundIrradianceScale: new r(3),
1950
+ skyIrradianceScale: new r(1),
1951
+ groundIrradianceScale: new r(1),
1940
1952
  powderScale: new r(0.8),
1941
1953
  powderExponent: new r(150),
1942
1954
  // Primary raymarch
1943
- maxIterationCount: new r(l.clouds.maxIterationCount),
1944
- minStepSize: new r(l.clouds.minStepSize),
1945
- maxStepSize: new r(l.clouds.maxStepSize),
1946
- maxRayDistance: new r(l.clouds.maxRayDistance),
1947
- perspectiveStepScale: new r(l.clouds.perspectiveStepScale),
1948
- minDensity: new r(l.clouds.minDensity),
1949
- minExtinction: new r(l.clouds.minExtinction),
1950
- minTransmittance: new r(l.clouds.minTransmittance),
1955
+ maxIterationCount: new r(c.clouds.maxIterationCount),
1956
+ minStepSize: new r(c.clouds.minStepSize),
1957
+ maxStepSize: new r(c.clouds.maxStepSize),
1958
+ maxRayDistance: new r(c.clouds.maxRayDistance),
1959
+ perspectiveStepScale: new r(c.clouds.perspectiveStepScale),
1960
+ minDensity: new r(c.clouds.minDensity),
1961
+ minExtinction: new r(c.clouds.minExtinction),
1962
+ minTransmittance: new r(c.clouds.minTransmittance),
1951
1963
  // Secondary raymarch
1952
- maxIterationCountToSun: new r(l.clouds.maxIterationCountToSun),
1953
- maxIterationCountToGround: new r(l.clouds.maxIterationCountToGround),
1954
- minSecondaryStepSize: new r(l.clouds.minSecondaryStepSize),
1955
- secondaryStepScale: new r(l.clouds.secondaryStepScale),
1964
+ maxIterationCountToSun: new r(c.clouds.maxIterationCountToSun),
1965
+ maxIterationCountToGround: new r(c.clouds.maxIterationCountToGround),
1966
+ minSecondaryStepSize: new r(c.clouds.minSecondaryStepSize),
1967
+ secondaryStepScale: new r(c.clouds.secondaryStepScale),
1956
1968
  // Beer shadow map
1957
1969
  shadowBuffer: new r(null),
1958
1970
  shadowTexelSize: new r(new m()),
@@ -1969,26 +1981,26 @@ class y extends je {
1969
1981
  shadowLayerMask: new r(new x().setScalar(1)),
1970
1982
  // Disable mask
1971
1983
  // Shadow length
1972
- maxShadowLengthIterationCount: new r(l.clouds.maxShadowLengthIterationCount),
1973
- minShadowLengthStepSize: new r(l.clouds.minShadowLengthStepSize),
1974
- maxShadowLengthRayDistance: new r(l.clouds.maxShadowLengthRayDistance),
1984
+ maxShadowLengthIterationCount: new r(c.clouds.maxShadowLengthIterationCount),
1985
+ minShadowLengthStepSize: new r(c.clouds.minShadowLengthStepSize),
1986
+ maxShadowLengthRayDistance: new r(c.clouds.maxShadowLengthRayDistance),
1975
1987
  // Haze
1976
1988
  hazeDensityScale: new r(3e-5),
1977
- hazeExponent: new r(1e-3)
1989
+ hazeExponent: new r(1e-3),
1990
+ hazeScatteringCoefficient: new r(0.9),
1991
+ hazeAbsorptionCoefficient: new r(0.5)
1978
1992
  }
1979
1993
  },
1980
1994
  a
1981
- ), 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.accurateSunSkyIrradiance = l.clouds.accurateSunSkyIrradiance, this.accuratePhaseFunction = l.clouds.accuratePhaseFunction, this.shadowCascadeCount = l.shadow.cascadeCount, this.shadowSampleCount = 8, this.scatterAnisotropy1 = 0.7, this.scatterAnisotropy2 = -0.2, this.scatterAnisotropyMix = 0.5;
1995
+ ), 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 = 0.7, this.scatterAnisotropy2 = -0.2, this.scatterAnisotropyMix = 0.5;
1982
1996
  }
1983
1997
  onBeforeRender(e, t, n, a, i, s) {
1984
- const c = this.uniforms;
1985
- c.albedo.value.setScalar(
1986
- c.scatteringCoefficient.value / (c.absorptionCoefficient.value + c.scatteringCoefficient.value)
1987
- );
1988
- const h = this.defines.POWDER != null, u = this.uniforms.powderScale.value > 0;
1989
- u !== h && (u ? this.defines.POWDER = "1" : delete this.defines.POWDER, this.needsUpdate = !0);
1990
- const d = this.defines.GROUND_IRRADIANCE != null;
1991
- (this.uniforms.groundIrradianceScale.value > 0 && this.uniforms.maxIterationCountToGround.value > 0) !== d && (u ? this.defines.GROUND_IRRADIANCE = "1" : delete this.defines.GROUND_IRRADIANCE, this.needsUpdate = !0);
1998
+ const l = this.defines.USE_LOGDEPTHBUF != null, h = e.capabilities.logarithmicDepthBuffer;
1999
+ h !== l && (h ? this.defines.USE_LOGDEPTHBUF = "1" : delete this.defines.USE_LOGDEPTHBUF);
2000
+ const u = this.defines.POWDER != null, d = this.uniforms.powderScale.value > 0;
2001
+ d !== u && (d ? this.defines.POWDER = "1" : delete this.defines.POWDER, this.needsUpdate = !0);
2002
+ const p = this.defines.GROUND_IRRADIANCE != null;
2003
+ (this.uniforms.groundIrradianceScale.value > 0 && this.uniforms.maxIterationCountToGround.value > 0) !== p && (d ? this.defines.GROUND_IRRADIANCE = "1" : delete this.defines.GROUND_IRRADIANCE, this.needsUpdate = !0);
1992
2004
  }
1993
2005
  copyCameraSettings(e) {
1994
2006
  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);
@@ -2001,9 +2013,9 @@ class y extends je {
2001
2013
  } else
2002
2014
  t.temporalJitter.value.setScalar(0), t.mipLevelScale.value = 1, i.copy(e.projectionMatrixInverse), s.copy(n).multiply(a);
2003
2015
  Ze(e), t.cameraNear.value = e.near, t.cameraFar.value = e.far;
2004
- const c = e.getWorldPosition(
2016
+ const l = e.getWorldPosition(
2005
2017
  t.cameraPosition.value
2006
- ), h = vt.copy(c).applyMatrix4(t.inverseEllipsoidMatrix.value).sub(t.ellipsoidCenter.value);
2018
+ ), h = vt.copy(l).applyMatrix4(t.inverseEllipsoidMatrix.value).sub(t.ellipsoidCenter.value);
2007
2019
  try {
2008
2020
  t.cameraHeight.value = gt.setFromECEF(h).height;
2009
2021
  } catch {
@@ -2610,7 +2622,7 @@ class Ct extends Ne {
2610
2622
  i
2611
2623
  ), this.currentPass = new Z(this.currentMaterial), this.resolveMaterial = new Q(), this.resolvePass = new Z(this.resolveMaterial), this.initRenderTargets({
2612
2624
  depthVelocity: !0,
2613
- shadowLength: l.lightShafts
2625
+ shadowLength: c.lightShafts
2614
2626
  });
2615
2627
  }
2616
2628
  copyCameraSettings(e) {
@@ -2620,8 +2632,8 @@ class Ct extends Ne {
2620
2632
  this.currentPass.initialize(e, t, n), this.resolvePass.initialize(e, t, n);
2621
2633
  }
2622
2634
  initRenderTargets(e) {
2623
- var s, c, h;
2624
- (s = this.currentRenderTarget) == null || s.dispose(), (c = this.resolveRenderTarget) == null || c.dispose(), (h = this.historyRenderTarget) == null || h.dispose();
2635
+ var s, l, h;
2636
+ (s = this.currentRenderTarget) == null || s.dispose(), (l = this.resolveRenderTarget) == null || l.dispose(), (h = this.historyRenderTarget) == null || h.dispose();
2625
2637
  const t = k("Clouds", e), n = k("Clouds.A", {
2626
2638
  ...e,
2627
2639
  depthVelocity: !1
@@ -3079,12 +3091,12 @@ class _ extends X {
3079
3091
  frame: new r(0),
3080
3092
  stbnTexture: new r(null),
3081
3093
  // Primary raymarch
3082
- maxIterationCount: new r(l.shadow.maxIterationCount),
3083
- minStepSize: new r(l.shadow.minStepSize),
3084
- maxStepSize: new r(l.shadow.maxStepSize),
3085
- minDensity: new r(l.shadow.minDensity),
3086
- minExtinction: new r(l.shadow.minExtinction),
3087
- minTransmittance: new r(l.shadow.minTransmittance),
3094
+ maxIterationCount: new r(c.shadow.maxIterationCount),
3095
+ minStepSize: new r(c.shadow.minStepSize),
3096
+ maxStepSize: new r(c.shadow.maxStepSize),
3097
+ minDensity: new r(c.shadow.minDensity),
3098
+ minExtinction: new r(c.shadow.minExtinction),
3099
+ minTransmittance: new r(c.shadow.minTransmittance),
3088
3100
  opticalDepthTailScale: new r(2)
3089
3101
  },
3090
3102
  defines: {
@@ -3092,7 +3104,7 @@ class _ extends X {
3092
3104
  TEMPORAL_PASS: "1",
3093
3105
  TEMPORAL_JITTER: "1"
3094
3106
  }
3095
- }), 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;
3107
+ }), 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;
3096
3108
  }
3097
3109
  setSize(e, t) {
3098
3110
  this.uniforms.resolution.value.set(e, t);
@@ -3236,7 +3248,7 @@ class be extends X {
3236
3248
  temporalAlpha: new r(0.01)
3237
3249
  },
3238
3250
  defines: {}
3239
- }), this.cascadeCount = l.shadow.cascadeCount;
3251
+ }), this.cascadeCount = c.shadow.cascadeCount;
3240
3252
  }
3241
3253
  setSize(e, t) {
3242
3254
  this.uniforms.texelSize.value.set(1 / e, 1 / t);
@@ -3269,8 +3281,8 @@ class It extends Ne {
3269
3281
  this.currentPass.initialize(e, t, n), this.resolvePass.initialize(e, t, n);
3270
3282
  }
3271
3283
  initRenderTargets() {
3272
- var i, s, c;
3273
- (i = this.currentRenderTarget) == null || i.dispose(), (s = this.resolveRenderTarget) == null || s.dispose(), (c = this.historyRenderTarget) == null || c.dispose();
3284
+ var i, s, l;
3285
+ (i = this.currentRenderTarget) == null || i.dispose(), (s = this.resolveRenderTarget) == null || s.dispose(), (l = this.historyRenderTarget) == null || l.dispose();
3274
3286
  const e = j("Shadow"), t = this.temporalPass ? j("Shadow.A") : null, n = this.temporalPass ? j("Shadow.B") : null;
3275
3287
  this.currentRenderTarget = e, this.resolveRenderTarget = t, this.historyRenderTarget = n;
3276
3288
  const a = this.resolveMaterial.uniforms;
@@ -3373,9 +3385,9 @@ function Mt(o, e) {
3373
3385
  e.packDensityProfiles("expTerm", t.expTerms), e.packDensityProfiles("exponent", t.exponents), e.packDensityProfiles("linearTerm", t.linearTerms), e.packDensityProfiles("constantTerm", t.constantTerms);
3374
3386
  let n = 1 / 0, a = 0, i = 1 / 0, s = 0;
3375
3387
  Y.fill(0);
3376
- for (let c = 0; c < e.length; ++c) {
3377
- const { altitude: h, height: u, shadow: d } = e[c], p = h + u;
3378
- u > 0 && (h < n && (n = h), d && h < i && (i = h), p > a && (a = p), d && p > s && (s = p)), Y[c] = d ? 1 : 0;
3388
+ for (let l = 0; l < e.length; ++l) {
3389
+ const { altitude: h, height: u, shadow: d } = e[l], p = h + u;
3390
+ u > 0 && (h < n && (n = h), d && h < i && (i = h), p > a && (a = p), d && p > s && (s = p)), Y[l] = d ? 1 : 0;
3379
3391
  }
3380
3392
  n !== 1 / 0 ? (o.minHeight.value = n, o.maxHeight.value = a) : (A(a === 0), o.minHeight.value = 0), i !== 1 / 0 ? (o.shadowBottomHeight.value = i, o.shadowTopHeight.value = s) : (A(s === 0), o.shadowBottomHeight.value = 0), o.shadowLayerMask.value.fromArray(Y);
3381
3393
  }
@@ -3425,7 +3437,9 @@ const I = /* @__PURE__ */ new f(), Wt = /* @__PURE__ */ new m(), Gt = [
3425
3437
  "minShadowLengthStepSize",
3426
3438
  "maxShadowLengthRayDistance",
3427
3439
  "hazeDensityScale",
3428
- "hazeExponent"
3440
+ "hazeExponent",
3441
+ "hazeScatteringCoefficient",
3442
+ "hazeAbsorptionCoefficient"
3429
3443
  ], Bt = [
3430
3444
  "multiScatteringOctaves",
3431
3445
  "accurateSunSkyIrradiance",
@@ -3452,7 +3466,7 @@ const I = /* @__PURE__ */ new f(), Wt = /* @__PURE__ */ new m(), Gt = [
3452
3466
  ], D = {
3453
3467
  type: "change"
3454
3468
  }, Zt = {
3455
- resolutionScale: l.resolutionScale,
3469
+ resolutionScale: c.resolutionScale,
3456
3470
  width: q.AUTO_SIZE,
3457
3471
  height: q.AUTO_SIZE
3458
3472
  };
@@ -3469,15 +3483,15 @@ class qt extends Fe {
3469
3483
  resolutionScale: a,
3470
3484
  width: i,
3471
3485
  height: s,
3472
- resolutionX: c = i,
3486
+ resolutionX: l = i,
3473
3487
  resolutionY: h = s
3474
3488
  } = {
3475
3489
  ...Zt,
3476
3490
  ...t
3477
3491
  };
3478
3492
  this.shadowMaps = new ht({
3479
- cascadeCount: l.shadow.cascadeCount,
3480
- mapSize: l.shadow.mapSize,
3493
+ cascadeCount: c.shadow.cascadeCount,
3494
+ mapSize: c.shadow.mapSize,
3481
3495
  splitLambda: 0.6
3482
3496
  }), this.parameterUniforms = Nt({
3483
3497
  localWeatherTexture: ((d = this.proceduralLocalWeather) == null ? void 0 : d.texture) ?? null,
@@ -3526,7 +3540,7 @@ class qt extends Fe {
3526
3540
  Yt
3527
3541
  ), this.resolution = new q(
3528
3542
  this,
3529
- c,
3543
+ l,
3530
3544
  h,
3531
3545
  a
3532
3546
  ), this.resolution.addEventListener("change", this.onResolutionChange);
@@ -3561,7 +3575,7 @@ class qt extends Fe {
3561
3575
  const s = this.ellipsoid.getSurfaceNormal(
3562
3576
  a,
3563
3577
  I
3564
- ), c = this.sunDirection.dot(s), h = Te(1e6, 1e3, c);
3578
+ ), l = this.sunDirection.dot(s), h = Te(1e6, 1e3, l);
3565
3579
  this.shadowMaps.update(
3566
3580
  this.camera,
3567
3581
  // The sun direction must be rotated with the ellipsoid to ensure the
@@ -3576,10 +3590,10 @@ class qt extends Fe {
3576
3590
  this.cloudsPass.currentMaterial.localWeatherChannels = e, this.shadowPass.currentMaterial.localWeatherChannels = e;
3577
3591
  }
3578
3592
  updateAtmosphereComposition() {
3579
- const { shadowMaps: e, shadowPass: t, cloudsPass: n } = this, a = t.currentMaterial.uniforms, i = n.currentMaterial.uniforms, s = this._atmosphereOverlay, c = Object.assign(this._atmosphereOverlay ?? {}, {
3593
+ const { shadowMaps: e, shadowPass: t, cloudsPass: n } = this, a = t.currentMaterial.uniforms, i = n.currentMaterial.uniforms, s = this._atmosphereOverlay, l = Object.assign(this._atmosphereOverlay ?? {}, {
3580
3594
  map: n.outputBuffer
3581
3595
  });
3582
- s !== c && (this._atmosphereOverlay = c, D.target = this, D.property = "atmosphereOverlay", this.events.dispatchEvent(D));
3596
+ s !== l && (this._atmosphereOverlay = l, D.target = this, D.property = "atmosphereOverlay", this.events.dispatchEvent(D));
3583
3597
  const h = this._atmosphereShadow, u = Object.assign(this._atmosphereShadow ?? {}, {
3584
3598
  map: t.outputBuffer,
3585
3599
  mapSize: e.mapSize,
@@ -3597,13 +3611,13 @@ class qt extends Fe {
3597
3611
  d !== p && (this._atmosphereShadowLength = p, D.target = this, D.property = "atmosphereShadowLength", this.events.dispatchEvent(D));
3598
3612
  }
3599
3613
  update(e, t, n = 0) {
3600
- var c, h, u, d;
3614
+ var l, h, u, d;
3601
3615
  const { shadowMaps: a, shadowPass: i, cloudsPass: s } = this;
3602
3616
  if (a.cascadeCount !== this.shadowCascadeCount || !a.mapSize.equals(this.shadowMapSize)) {
3603
3617
  const { width: p, height: g } = a.mapSize, S = a.cascadeCount;
3604
3618
  this.shadowMapSize.set(p, g), this.shadowCascadeCount = S, i.setSize(p, g, S), s.setShadowSize(p, g, S);
3605
3619
  }
3606
- (c = this.proceduralLocalWeather) == null || c.render(e, n), (h = this.proceduralShape) == null || h.render(e, n), (u = this.proceduralShapeDetail) == null || u.render(e, n), (d = this.proceduralTurbulence) == null || d.render(e, n), ++this.frame, this.updateSharedUniforms(n), this.updateWeatherTextureChannels(), i.update(e, this.frame, n), s.shadowBuffer = i.outputBuffer, s.update(e, this.frame, n), this.updateAtmosphereComposition(), this.uniforms.get("cloudsBuffer").value = this.cloudsPass.outputBuffer;
3620
+ (l = this.proceduralLocalWeather) == null || l.render(e, n), (h = this.proceduralShape) == null || h.render(e, n), (u = this.proceduralShapeDetail) == null || u.render(e, n), (d = this.proceduralTurbulence) == null || d.render(e, n), ++this.frame, this.updateSharedUniforms(n), this.updateWeatherTextureChannels(), i.update(e, this.frame, n), s.shadowBuffer = i.outputBuffer, s.update(e, this.frame, n), this.updateAtmosphereComposition(), this.uniforms.get("cloudsBuffer").value = this.cloudsPass.outputBuffer;
3607
3621
  }
3608
3622
  setSize(e, t) {
3609
3623
  const { resolution: n } = this;