@takram/three-clouds 0.7.0 → 0.7.2

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
@@ -1,7 +1,7 @@
1
- import { Pass as Fe, ShaderPass as q, Resolution as $, Effect as ze, EffectAttribute as We } from "postprocessing";
1
+ import { Pass as Fe, ShaderPass as K, Resolution as $, Effect as ze, EffectAttribute as We } from "postprocessing";
2
2
  import { Vector3 as p, Vector2 as f, Matrix4 as m, Object3D as se, Box3 as Be, Uniform as r, GLSL3 as G, Vector4 as S, RawShaderMaterial as Q, Camera as we, WebGLRenderTarget as Ge, HalfFloatType as Ce, LinearFilter as B, RedFormat as Ve, WebGLArrayRenderTarget as ke, EventDispatcher as je, Matrix3 as Ye, Texture as ce, Data3DTexture as le } from "three";
3
- import { AtmosphereMaterialBase as Ze, AtmosphereParameters as Te, getAltitudeCorrectionOffset as Ke } from "@takram/three-atmosphere";
4
- import { lerp as De, defineInt as L, defineExpression as Ee, define as x, defineFloat as ee, unrollLoops as V, resolveIncludes as H, reinterpretType as qe, Geodetic as $e, definePropertyShorthand as he, defineUniformShorthand as ue } from "@takram/three-geospatial";
3
+ import { AtmosphereMaterialBase as Ze, AtmosphereParameters as Te, getAltitudeCorrectionOffset as qe } from "@takram/three-atmosphere";
4
+ import { lerp as De, defineInt as L, defineExpression as Ee, define as x, defineFloat as ee, unrollLoops as V, resolveIncludes as H, reinterpretType as Ke, Geodetic as $e, definePropertyShorthand as he, defineUniformShorthand as ue } from "@takram/three-geospatial";
5
5
  import { runtime as de, definitions as pe, common as fe } from "@takram/three-atmosphere/shaders/bruneton";
6
6
  import { vogelDisk as Xe, interleavedGradientNoise as Je, cascadedShadowMaps as Qe, raySphereIntersection as Ae, generators as et, turbo as _e, math as Pe, depth as tt } from "@takram/three-geospatial/shaders";
7
7
  class k {
@@ -62,7 +62,7 @@ let w = b;
62
62
  const R = /* @__PURE__ */ Array.from(
63
63
  { length: 8 },
64
64
  () => ({ value: 0, flag: 0 })
65
- ), M = /* @__PURE__ */ Array.from(
65
+ ), I = /* @__PURE__ */ Array.from(
66
66
  { length: 3 },
67
67
  () => ({ min: 0, max: 0 })
68
68
  );
@@ -124,17 +124,17 @@ const U = class U extends Array {
124
124
  for (let s = 0; s < R.length; ++s) {
125
125
  const { value: l, flag: h } = R[s];
126
126
  if (a === 0 && s > 0) {
127
- const u = M[n++];
127
+ const u = I[n++];
128
128
  u.min = R[s - 1].value, u.max = l;
129
129
  }
130
130
  a += h === 0 ? 1 : -1;
131
131
  }
132
132
  for (; n < 3; ++n) {
133
- const s = M[n];
133
+ const s = I[n];
134
134
  s.min = 0, s.max = 0;
135
135
  }
136
- let i = M[0];
137
- e.x = i.min, t.x = i.max, i = M[1], e.y = i.min, t.y = i.max, i = M[2], e.z = i.min, t.z = i.max;
136
+ let i = I[0];
137
+ e.x = i.min, t.x = i.max, i = I[1], e.y = i.min, t.y = i.max, i = I[2], e.z = i.min, t.z = i.max;
138
138
  }
139
139
  };
140
140
  U.DEFAULT = /* @__PURE__ */ new U([
@@ -535,6 +535,7 @@ precision highp sampler2DArray;
535
535
  #include <common>
536
536
  #include <packing>
537
537
 
538
+ #include "core/depth"
538
539
  #include "core/math"
539
540
  #include "core/turbo"
540
541
  #include "core/generators"
@@ -627,14 +628,6 @@ layout(location = 1) out vec3 outputDepthVelocity;
627
628
  layout(location = 2) out float outputShadowLength;
628
629
  #endif // SHADOW_LENGTH
629
630
 
630
- float readDepth(const vec2 uv) {
631
- #if DEPTH_PACKING == 3201
632
- return unpackRGBAToDepth(texture(depthBuffer, uv));
633
- #else // DEPTH_PACKING == 3201
634
- return texture(depthBuffer, uv).r;
635
- #endif // DEPTH_PACKING == 3201
636
- }
637
-
638
631
  float getViewZ(const float depth) {
639
632
  #ifdef PERSPECTIVE_CAMERA
640
633
  return perspectiveDepthToViewZ(depth, cameraNear, cameraFar);
@@ -1347,8 +1340,10 @@ vec2 getHazeRayNearFar(const IntersectionResult intersections) {
1347
1340
  #endif // HAZE
1348
1341
 
1349
1342
  float getRayDistanceToScene(const vec3 rayDirection, out float viewZ) {
1350
- float depth = readDepth(vUv * targetUvScale + temporalJitter);
1343
+ float depth = readDepthValue(depthBuffer, vUv * targetUvScale + temporalJitter);
1344
+ depth = reverseLogDepth(depth, cameraNear, cameraFar);
1351
1345
  if (depth < 1.0 - 1e-7) {
1346
+ depth = reverseLogDepth(depth, cameraNear, cameraFar);
1352
1347
  viewZ = getViewZ(depth);
1353
1348
  return -viewZ / dot(rayDirection, vCameraDirection);
1354
1349
  }
@@ -2029,7 +2024,7 @@ class g extends Ze {
2029
2024
  t.temporalJitter.value.set(P, O), t.mipLevelScale.value = 0.25, i.copy(e.projectionMatrix), i.elements[8] += P * 2, i.elements[9] += O * 2, i.invert(), l.copy(n), l.elements[8] += P * 2, l.elements[9] += O * 2, l.multiply(a), h.copy(l).multiply(s);
2030
2025
  } else
2031
2026
  t.temporalJitter.value.setScalar(0), t.mipLevelScale.value = 1, i.copy(e.projectionMatrixInverse), l.copy(n).multiply(a), h.copy(l).multiply(s);
2032
- qe(e), t.cameraNear.value = e.near, t.cameraFar.value = e.far;
2027
+ Ke(e), t.cameraNear.value = e.near, t.cameraFar.value = e.far;
2033
2028
  const u = e.getWorldPosition(
2034
2029
  t.cameraPosition.value
2035
2030
  ), d = St.copy(u).applyMatrix4(t.worldToECEFMatrix.value);
@@ -2403,7 +2398,7 @@ void main() {
2403
2398
  vUv = position.xy * 0.5 + 0.5;
2404
2399
  gl_Position = vec4(position.xy, 1.0, 1.0);
2405
2400
  }
2406
- `, Ie = `#ifdef VARIANCE_9_SAMPLES
2401
+ `, Me = `#ifdef VARIANCE_9_SAMPLES
2407
2402
  #define VARIANCE_OFFSET_COUNT 8
2408
2403
  const ivec2 varianceOffsets[8] = ivec2[8](
2409
2404
  ivec2(-1, -1),
@@ -2518,7 +2513,7 @@ vec4 varianceClipping(
2518
2513
  return varianceClipping(inputBuffer, coord, current, history, 1.0);
2519
2514
  }
2520
2515
  `;
2521
- var Tt = Object.defineProperty, Me = (o, e, t, n) => {
2516
+ var Tt = Object.defineProperty, Ie = (o, e, t, n) => {
2522
2517
  for (var a = void 0, i = o.length - 1, s; i >= 0; i--)
2523
2518
  (s = o[i]) && (a = s(e, t, a) || a);
2524
2519
  return a && Tt(e, t, a), a;
@@ -2539,7 +2534,7 @@ class te extends Q {
2539
2534
  H(wt, {
2540
2535
  core: { turbo: _e },
2541
2536
  catmullRomSampling: xt,
2542
- varianceClipping: Ie
2537
+ varianceClipping: Me
2543
2538
  })
2544
2539
  ),
2545
2540
  uniforms: {
@@ -2564,10 +2559,10 @@ class te extends Q {
2564
2559
  this.uniforms.jitterOffset.value.set(d, v);
2565
2560
  }
2566
2561
  }
2567
- Me([
2562
+ Ie([
2568
2563
  x("TEMPORAL_UPSCALE")
2569
2564
  ], te.prototype, "temporalUpscale");
2570
- Me([
2565
+ Ie([
2571
2566
  x("SHADOW_LENGTH")
2572
2567
  ], te.prototype, "shadowLength");
2573
2568
  class Ne extends Fe {
@@ -2611,7 +2606,7 @@ class Dt extends Ne {
2611
2606
  atmosphereUniforms: n
2612
2607
  },
2613
2608
  i
2614
- ), this.currentPass = new q(this.currentMaterial), this.resolveMaterial = new te(), this.resolvePass = new q(this.resolveMaterial), this.initRenderTargets({
2609
+ ), this.currentPass = new K(this.currentMaterial), this.resolveMaterial = new te(), this.resolvePass = new K(this.resolveMaterial), this.initRenderTargets({
2615
2610
  depthVelocity: !0,
2616
2611
  shadowLength: c.lightShafts
2617
2612
  });
@@ -2717,7 +2712,7 @@ function Et(o, e) {
2717
2712
  ), i.push(a.COLOR_ATTACHMENT0 + s);
2718
2713
  a.drawBuffers(i);
2719
2714
  }
2720
- class xe extends q {
2715
+ class xe extends K {
2721
2716
  render(e, t, n, a, i) {
2722
2717
  const s = this.fullscreenMaterial.uniforms;
2723
2718
  t !== null && s?.[this.input] != null && (s[this.input].value = t.texture), Et(e, n), e.render(this.scene, this.camera);
@@ -3028,7 +3023,7 @@ void intersectStructuredPlanes(
3028
3023
  }
3029
3024
  }
3030
3025
  `;
3031
- var Ot = Object.defineProperty, I = (o, e, t, n) => {
3026
+ var Ot = Object.defineProperty, M = (o, e, t, n) => {
3032
3027
  for (var a = void 0, i = o.length - 1, s; i >= 0; i--)
3033
3028
  (s = o[i]) && (a = s(e, t, a) || a);
3034
3029
  return a && Ot(e, t, a), a;
@@ -3090,24 +3085,24 @@ class _ extends Q {
3090
3085
  this.uniforms.resolution.value.set(e, t);
3091
3086
  }
3092
3087
  }
3093
- I([
3088
+ M([
3094
3089
  Ee("LOCAL_WEATHER_CHANNELS", {
3095
3090
  validate: (o) => /^[rgba]{4}$/.test(o)
3096
3091
  })
3097
3092
  ], _.prototype, "localWeatherChannels");
3098
- I([
3093
+ M([
3099
3094
  L("CASCADE_COUNT", { min: 1, max: 4 })
3100
3095
  ], _.prototype, "cascadeCount");
3101
- I([
3096
+ M([
3102
3097
  x("TEMPORAL_PASS")
3103
3098
  ], _.prototype, "temporalPass");
3104
- I([
3099
+ M([
3105
3100
  x("TEMPORAL_JITTER")
3106
3101
  ], _.prototype, "temporalJitter");
3107
- I([
3102
+ M([
3108
3103
  x("SHAPE_DETAIL")
3109
3104
  ], _.prototype, "shapeDetail");
3110
- I([
3105
+ M([
3111
3106
  x("TURBULENCE")
3112
3107
  ], _.prototype, "turbulence");
3113
3108
  const Rt = `precision highp float;
@@ -3197,10 +3192,10 @@ void main() {
3197
3192
  gl_Position = vec4(position.xy, 1.0, 1.0);
3198
3193
  }
3199
3194
  `;
3200
- var It = Object.defineProperty, Mt = (o, e, t, n) => {
3195
+ var Mt = Object.defineProperty, It = (o, e, t, n) => {
3201
3196
  for (var a = void 0, i = o.length - 1, s; i >= 0; i--)
3202
3197
  (s = o[i]) && (a = s(e, t, a) || a);
3203
- return a && It(e, t, a), a;
3198
+ return a && Mt(e, t, a), a;
3204
3199
  };
3205
3200
  class be extends Q {
3206
3201
  constructor({
@@ -3213,7 +3208,7 @@ class be extends Q {
3213
3208
  vertexShader: Lt,
3214
3209
  fragmentShader: V(
3215
3210
  H(Rt, {
3216
- varianceClipping: Ie
3211
+ varianceClipping: Me
3217
3212
  })
3218
3213
  ),
3219
3214
  uniforms: {
@@ -3234,7 +3229,7 @@ class be extends Q {
3234
3229
  this.uniforms.texelSize.value.set(1 / e, 1 / t);
3235
3230
  }
3236
3231
  }
3237
- Mt([
3232
+ It([
3238
3233
  L("CASCADE_COUNT", { min: 1, max: 4 })
3239
3234
  ], be.prototype, "cascadeCount");
3240
3235
  function Z(o) {
@@ -3352,7 +3347,7 @@ function Ut() {
3352
3347
  })
3353
3348
  };
3354
3349
  }
3355
- const K = [0, 0, 0, 0];
3350
+ const q = [0, 0, 0, 0];
3356
3351
  function Ht(o, e) {
3357
3352
  e.packValues("altitude", o.minLayerHeights.value), e.packSums("altitude", "height", o.maxLayerHeights.value), e.packIntervalHeights(
3358
3353
  o.minIntervalHeights.value,
@@ -3361,12 +3356,12 @@ function Ht(o, e) {
3361
3356
  const t = o.densityProfile.value;
3362
3357
  e.packDensityProfiles("expTerm", t.expTerms), e.packDensityProfiles("exponent", t.exponents), e.packDensityProfiles("linearTerm", t.linearTerms), e.packDensityProfiles("constantTerm", t.constantTerms);
3363
3358
  let n = 1 / 0, a = 0, i = 1 / 0, s = 0;
3364
- K.fill(0);
3359
+ q.fill(0);
3365
3360
  for (let l = 0; l < e.length; ++l) {
3366
3361
  const { altitude: h, height: u, shadow: d } = e[l], v = h + u;
3367
- u > 0 && (h < n && (n = h), d && h < i && (i = h), v > a && (a = v), d && v > s && (s = v)), K[l] = d ? 1 : 0;
3362
+ u > 0 && (h < n && (n = h), d && h < i && (i = h), v > a && (a = v), d && v > s && (s = v)), q[l] = d ? 1 : 0;
3368
3363
  }
3369
- 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(K);
3364
+ 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(q);
3370
3365
  }
3371
3366
  function Ft(o, e) {
3372
3367
  return {
@@ -3430,9 +3425,9 @@ const N = /* @__PURE__ */ new p(), Gt = /* @__PURE__ */ new f(), Vt = /* @__PURE
3430
3425
  "opticalDepthTailScale"
3431
3426
  ], Zt = [
3432
3427
  "temporalJitter"
3433
- ], Kt = [
3434
- "temporalPass"
3435
3428
  ], qt = [
3429
+ "temporalPass"
3430
+ ], Kt = [
3436
3431
  "cascadeCount",
3437
3432
  "mapSize",
3438
3433
  "maxFar",
@@ -3509,9 +3504,9 @@ class Xt extends ze {
3509
3504
  this.shadowPass.currentMaterial,
3510
3505
  Zt,
3511
3506
  this.shadowPass,
3512
- Kt,
3507
+ qt,
3513
3508
  this.shadowMaps,
3514
- qt
3509
+ Kt
3515
3510
  ), this.resolution = new $(
3516
3511
  this,
3517
3512
  l,
@@ -3541,7 +3536,7 @@ class Xt extends ze {
3541
3536
  const n = this.worldToECEFMatrix;
3542
3537
  this.ecefToWorldMatrix.copy(n).invert();
3543
3538
  const a = this.camera.getWorldPosition(N).applyMatrix4(this.worldToECEFMatrix), i = this.altitudeCorrection;
3544
- this.correctAltitude ? Ke(
3539
+ this.correctAltitude ? qe(
3545
3540
  a,
3546
3541
  this.atmosphere.bottomRadius,
3547
3542
  this.ellipsoid,