@adatechnology/game-weather-three 0.5.20 → 0.6.1

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.
@@ -22,6 +22,7 @@ var GameWeatherThree = (() => {
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
24
  ASH: () => ASH,
25
+ CLOUD_COVER: () => CLOUD_COVER,
25
26
  FOG_EXP_FROM: () => FOG_EXP_FROM,
26
27
  FOG_NEAR: () => FOG_NEAR,
27
28
  FOG_ZONE_NEAR: () => FOG_ZONE_NEAR,
@@ -31,17 +32,23 @@ var GameWeatherThree = (() => {
31
32
  HEAT_HAZE_VERTEX: () => HEAT_HAZE_VERTEX,
32
33
  LIGHTNING: () => LIGHTNING,
33
34
  MIST: () => MIST,
35
+ RAIN_COVER_CELL: () => RAIN_COVER_CELL,
36
+ RAIN_COVER_CELLS: () => RAIN_COVER_CELLS,
34
37
  RAIN_CURTAIN: () => RAIN_CURTAIN,
38
+ RAIN_CURTAIN_COVERED_VERTEX: () => RAIN_CURTAIN_COVERED_VERTEX,
35
39
  RAIN_CURTAIN_FRAGMENT: () => RAIN_CURTAIN_FRAGMENT,
36
40
  RAIN_CURTAIN_FULL_AT: () => RAIN_CURTAIN_FULL_AT,
37
41
  RAIN_CURTAIN_PROFILES: () => RAIN_CURTAIN_PROFILES,
38
42
  RAIN_CURTAIN_VERTEX: () => RAIN_CURTAIN_VERTEX,
39
43
  SKY_DAY: () => SKY_DAY,
44
+ SKY_DOME: () => SKY_DOME,
40
45
  SKY_NIGHT: () => SKY_NIGHT,
41
46
  SPLASH_FROM_MM: () => SPLASH_FROM_MM,
42
47
  WEATHER_LAYERS: () => WEATHER_LAYERS,
43
48
  ZONE_FOG_DEFAULTS: () => ZONE_FOG_DEFAULTS,
44
49
  ZONE_LIGHT: () => ZONE_LIGHT,
50
+ cloudCoverOf: () => cloudCoverOf,
51
+ cloudDarknessOf: () => cloudDarknessOf,
45
52
  createFog: () => createFog2,
46
53
  createHeadlights: () => createHeadlights,
47
54
  createHeatHaze: () => createHeatHaze,
@@ -55,7 +62,12 @@ var GameWeatherThree = (() => {
55
62
  densityForFar: () => densityForFar,
56
63
  emitAirborne: () => emitAirborne,
57
64
  fogOf: () => fogOf,
65
+ nightnessOf: () => nightnessOf,
58
66
  rainCurtainPositions: () => rainCurtainPositions,
67
+ starVisibilityOf: () => starVisibilityOf,
68
+ sunDirectionOf: () => sunDirectionOf,
69
+ sunVisibilityOf: () => sunVisibilityOf,
70
+ sunsetOf: () => sunsetOf,
59
71
  weatherVisualTextOf: () => weatherVisualTextOf
60
72
  });
61
73
 
@@ -236,22 +248,282 @@ var GameWeatherThree = (() => {
236
248
  }
237
249
  var EFFECT_STEP_SECONDS = 1 / 50;
238
250
 
251
+ // src/sky-shader.ts
252
+ var SKY_VERTEX = (
253
+ /* glsl */
254
+ `
255
+ varying vec3 vDir;
256
+ void main() {
257
+ vDir = normalize(position);
258
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
259
+ }
260
+ `
261
+ );
262
+ var SKY_FRAGMENT = (
263
+ /* glsl */
264
+ `
265
+ precision highp float;
266
+ uniform vec3 uZenith;
267
+ uniform vec3 uHorizon;
268
+ uniform vec3 uTint;
269
+ uniform vec3 uSunDir;
270
+ uniform vec3 uSunColor;
271
+ uniform vec3 uMoonDir;
272
+ uniform vec3 uCloudLit;
273
+ uniform vec3 uCloudShade;
274
+ uniform vec3 uDrift;
275
+ uniform float uSunsetAmount;
276
+ uniform float uSunVis;
277
+ uniform float uMoonVis;
278
+ uniform float uStars;
279
+ uniform float uCover;
280
+ uniform float uTime;
281
+ uniform float uFlash;
282
+ varying vec3 vDir;
283
+
284
+ float hash2(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
285
+ float hash3(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }
286
+ float noise(vec2 p) {
287
+ vec2 i = floor(p);
288
+ vec2 f = fract(p);
289
+ f = f * f * (3.0 - 2.0 * f);
290
+ return mix(mix(hash2(i), hash2(i + vec2(1.0, 0.0)), f.x), mix(hash2(i + vec2(0.0, 1.0)), hash2(i + vec2(1.0, 1.0)), f.x), f.y);
291
+ }
292
+ float fbm(vec2 p) {
293
+ float value = 0.0;
294
+ float amplitude = 0.5;
295
+ for (int octave = 0; octave < 4; octave++) {
296
+ value += amplitude * noise(p);
297
+ p = p * 2.03 + vec2(17.1, 9.2);
298
+ amplitude *= 0.5;
299
+ }
300
+ return value;
301
+ }
302
+
303
+ void main() {
304
+ vec3 d = normalize(vDir);
305
+ float height = max(d.y, 0.0);
306
+ vec3 color = mix(uHorizon, uZenith, pow(height, 0.6));
307
+
308
+ vec2 azimuth = normalize(d.xz + vec2(1e-5));
309
+ vec2 sunAzimuth = normalize(uSunDir.xz + vec2(1e-5));
310
+ float towardSun = max(dot(azimuth, sunAzimuth), 0.0);
311
+ color = mix(color, uTint, uSunsetAmount * exp(-height * 6.0) * (0.25 + 0.75 * towardSun * towardSun));
312
+
313
+ float aboveHorizon = smoothstep(-0.05, 0.05, d.y);
314
+ if (uStars > 0.001 && d.y > 0.0) {
315
+ vec3 p = d * 120.0;
316
+ vec3 cell = floor(p);
317
+ float pick = hash3(cell);
318
+ if (pick > 0.985) {
319
+ vec3 spot = vec3(hash3(cell + 1.7), hash3(cell + 5.3), hash3(cell + 9.1)) * 0.4 + 0.3;
320
+ float twinkle = 0.78 + 0.22 * sin(uTime * 2.0 + pick * 60.0);
321
+ float star = (1.0 - smoothstep(0.04, 0.32, length(fract(p) - spot))) * (0.45 + 0.55 * fract(pick * 97.0)) * twinkle;
322
+ color += vec3(0.85, 0.9, 1.0) * star * uStars * smoothstep(0.0, 0.12, d.y);
323
+ }
324
+ }
325
+
326
+ if (uMoonVis > 0.001) {
327
+ float toMoon = dot(d, uMoonDir);
328
+ vec3 tangent = normalize(cross(uMoonDir, vec3(0.0, 1.0, 0.0)));
329
+ vec2 onDisc = vec2(dot(d, tangent), dot(d, cross(uMoonDir, tangent))) / 0.045;
330
+ float disc = (1.0 - smoothstep(0.93, 1.0, length(onDisc))) * step(0.0, toMoon);
331
+ vec3 moon = vec3(0.7, 0.73, 0.8) * (0.62 + 0.38 * fbm(onDisc * 3.0 + 3.0));
332
+ color += (moon * disc + vec3(0.55, 0.62, 0.8) * pow(max(toMoon, 0.0), 220.0) * 0.5) * uMoonVis * aboveHorizon;
333
+ }
334
+
335
+ if (uSunVis > 0.001) {
336
+ float toSun = dot(d, uSunDir);
337
+ float disc = smoothstep(0.99935, 0.99965, toSun);
338
+ float glow = pow(max(toSun, 0.0), 48.0) * 0.5 + pow(max(toSun, 0.0), 6.0) * 0.14;
339
+ color += uSunColor * (glow + disc * 2.5) * uSunVis * aboveHorizon;
340
+ }
341
+
342
+ if (d.y > -0.05) {
343
+ vec2 uv = d.xz / (height + 0.18) * 1.1 + uDrift.xy;
344
+ float density = fbm(uv);
345
+ float threshold = 0.74 - uCover * 0.9;
346
+ float coverage = smoothstep(threshold, threshold + 0.22, density) * smoothstep(-0.05, 0.12, d.y);
347
+ float thick = smoothstep(threshold, threshold + 0.5, density);
348
+ vec3 cloud = mix(uCloudLit, uCloudShade, thick * 0.8);
349
+ cloud = mix(uHorizon, cloud, smoothstep(0.0, 0.3, d.y));
350
+ color = mix(color, cloud, coverage);
351
+ }
352
+
353
+ color = mix(color, vec3(0.78, 0.82, 0.95), uFlash * 0.7);
354
+ gl_FragColor = vec4(color, 1.0);
355
+ #include <colorspace_fragment>
356
+ }
357
+ `
358
+ );
359
+
360
+ // src/sky-state.ts
361
+ var clamp01 = (value) => value < 0 ? 0 : value > 1 ? 1 : value;
362
+ var smoothstep = (from, to, value) => {
363
+ const t = clamp01((value - from) / (to - from));
364
+ return t * t * (3 - 2 * t);
365
+ };
366
+ var CLOUD_COVER = { clear: 0.2, perSkyDimming: 7, perRainMm: 0.4, rainFullAtMm: 5, windMax: 0.15, windFullAt: 20 };
367
+ var DARK_FROM_SKY_SCALE = 0.95;
368
+ var DARK_SPAN = 0.45;
369
+ function cloudCoverOf(sample) {
370
+ const dimming = clamp01(1 - sample.skyScale);
371
+ const rain = Math.min(1, sample.rain / CLOUD_COVER.rainFullAtMm);
372
+ const wind = Math.min(1, Math.hypot(sample.windX, sample.windZ) / CLOUD_COVER.windFullAt) * CLOUD_COVER.windMax;
373
+ return clamp01(CLOUD_COVER.clear + dimming * CLOUD_COVER.perSkyDimming + rain * CLOUD_COVER.perRainMm + wind);
374
+ }
375
+ function cloudDarknessOf(sample) {
376
+ return clamp01((DARK_FROM_SKY_SCALE - sample.skyScale) / DARK_SPAN);
377
+ }
378
+ var nightnessOf = (sample) => clamp01(sample.nightFactor) ** 3;
379
+ function starVisibilityOf(sample) {
380
+ return nightnessOf(sample) * clamp01(1 - cloudCoverOf(sample) * 1.25);
381
+ }
382
+ function sunsetOf(sample) {
383
+ const low = smoothstep(0.02, 0.15, sample.sun) * (1 - smoothstep(0.15, 0.5, sample.sun));
384
+ return low * (1 - cloudCoverOf(sample) * 0.75);
385
+ }
386
+ var sunVisibilityOf = (sample) => smoothstep(0.02, 0.15, sample.sun);
387
+ function sunDirectionOf(sample, host, out) {
388
+ if (host) {
389
+ const target = host.target?.position;
390
+ out.x = host.position.x - (target?.x ?? 0);
391
+ out.y = host.position.y - (target?.y ?? 0);
392
+ out.z = host.position.z - (target?.z ?? 0);
393
+ } else {
394
+ const angle = (sample.dayFraction - 0.25) * Math.PI * 2;
395
+ out.x = Math.cos(angle);
396
+ out.y = Math.sin(angle);
397
+ out.z = -0.3;
398
+ }
399
+ const length = Math.hypot(out.x, out.y, out.z) || 1;
400
+ out.x /= length;
401
+ out.y /= length;
402
+ out.z /= length;
403
+ return out;
404
+ }
405
+
239
406
  // src/sky.ts
240
407
  var SKY_NIGHT = 724760;
241
408
  var SKY_DAY = 8885926;
242
409
  var ZONE_LIGHT = { base: 0.35, sun: 0.65 };
243
410
  var ZONE_FOG_DEFAULTS = { color: 3820090, far: 60 };
244
- function createSky(THREE, scene) {
411
+ var SKY_DOME = {
412
+ zenithDay: 4159684,
413
+ zenithNight: 132106,
414
+ sunsetTint: 16742973,
415
+ sunDay: 16774368,
416
+ sunSet: 16751184,
417
+ cloudDay: 16054010,
418
+ cloudOvercast: 12107462,
419
+ cloudStorm: 4080460,
420
+ cloudNight: 1712176,
421
+ /** How much of the sunset warmth the horizon (and so the fog) takes. */
422
+ fogWarmth: 0.3,
423
+ /** Clouds drift this many noise units per second for each m/s of wind (wind capped at `driftMaxWind`). */
424
+ drift: 25e-4,
425
+ driftMaxWind: 20,
426
+ /** Largest radius of the dome; it is 90 % of the camera's far plane when that is smaller. */
427
+ radius: 900,
428
+ renderOrder: -1e3
429
+ };
430
+ function createDome(THREE, camera2) {
431
+ const vector2 = () => ({ value: new THREE.Vector3() });
432
+ const colour = (hex) => ({ value: new THREE.Color(hex) });
433
+ const uniforms = {
434
+ uZenith: colour(SKY_DOME.zenithDay),
435
+ uHorizon: colour(SKY_DAY),
436
+ uTint: colour(SKY_DOME.sunsetTint),
437
+ uSunDir: vector2(),
438
+ uSunColor: colour(SKY_DOME.sunDay),
439
+ uMoonDir: vector2(),
440
+ uCloudLit: colour(SKY_DOME.cloudDay),
441
+ uCloudShade: colour(SKY_DOME.cloudOvercast),
442
+ uDrift: vector2(),
443
+ uSunsetAmount: { value: 0 },
444
+ uSunVis: { value: 0 },
445
+ uMoonVis: { value: 0 },
446
+ uStars: { value: 0 },
447
+ uCover: { value: 0 },
448
+ uTime: { value: 0 },
449
+ uFlash: { value: 0 }
450
+ };
451
+ const geometry = new THREE.SphereGeometry(1, 24, 12);
452
+ const material = new THREE.ShaderMaterial({ uniforms, vertexShader: SKY_VERTEX, fragmentShader: SKY_FRAGMENT, side: THREE.BackSide, depthTest: false, depthWrite: false, fog: false, toneMapped: false });
453
+ const mesh2 = new THREE.Mesh(geometry, material);
454
+ mesh2.name = "sky-dome";
455
+ mesh2.renderOrder = SKY_DOME.renderOrder;
456
+ mesh2.frustumCulled = false;
457
+ mesh2.raycast = () => void 0;
458
+ const far = camera2.far;
459
+ mesh2.scale.setScalar(far > 0 ? Math.min(SKY_DOME.radius, far * 0.9) : SKY_DOME.radius);
460
+ return {
461
+ mesh: mesh2,
462
+ uniforms,
463
+ dispose() {
464
+ mesh2.removeFromParent();
465
+ geometry.dispose();
466
+ material.dispose();
467
+ }
468
+ };
469
+ }
470
+ function createSky(THREE, scene, options = {}) {
245
471
  const night = new THREE.Color(SKY_NIGHT);
246
472
  const day = new THREE.Color(SKY_DAY);
247
473
  const zoneColor = new THREE.Color(ZONE_FOG_DEFAULTS.color);
248
474
  const tint = new THREE.Color();
249
475
  const color = new THREE.Color();
476
+ const sunsetColor = new THREE.Color(SKY_DOME.sunsetTint);
477
+ const zenithDay = new THREE.Color(SKY_DOME.zenithDay);
478
+ const zenithNight = new THREE.Color(SKY_DOME.zenithNight);
479
+ const sunDay = new THREE.Color(SKY_DOME.sunDay);
480
+ const sunSet = new THREE.Color(SKY_DOME.sunSet);
481
+ const cloudDay = new THREE.Color(SKY_DOME.cloudDay);
482
+ const cloudOvercast = new THREE.Color(SKY_DOME.cloudOvercast);
483
+ const cloudStorm = new THREE.Color(SKY_DOME.cloudStorm);
484
+ const cloudNight = new THREE.Color(SKY_DOME.cloudNight);
485
+ const sunDirection = { x: 0, y: 1, z: 0 };
486
+ const dome = options.camera ? createDome(THREE, options.camera) : void 0;
487
+ let time = 0;
488
+ const updateDome = (sample, dt) => {
489
+ if (!dome || !options.camera) return;
490
+ const { uniforms, mesh: mesh2 } = dome;
491
+ time += dt;
492
+ const cover = cloudCoverOf(sample);
493
+ const sunset = sunsetOf(sample);
494
+ const dark = cloudDarknessOf(sample);
495
+ mesh2.visible = true;
496
+ mesh2.position.copy(options.camera.position);
497
+ const zenith = uniforms.uZenith.value;
498
+ zenith.lerpColors(zenithNight, zenithDay, sample.sun).multiplyScalar(sample.skyScale).lerp(color, cover * 0.85);
499
+ uniforms.uHorizon.value.copy(color);
500
+ const lit = uniforms.uCloudLit.value;
501
+ lit.lerpColors(cloudDay, cloudOvercast, cover * cover).lerp(cloudStorm, dark).lerp(cloudNight, 1 - Math.min(1, sample.sun * 2.2));
502
+ lit.lerp(sunsetColor, sunset * 0.45);
503
+ uniforms.uCloudShade.value.copy(lit).multiplyScalar(0.62);
504
+ uniforms.uSunColor.value.lerpColors(sunDay, sunSet, sunset);
505
+ const sunVector = uniforms.uSunDir.value;
506
+ sunDirectionOf(sample, options.sun, sunDirection);
507
+ sunVector.set(sunDirection.x, sunDirection.y, sunDirection.z);
508
+ uniforms.uMoonDir.value.set(-sunDirection.x, Math.abs(sunDirection.y) * 0.9 + 0.1, -sunDirection.z).normalize();
509
+ const drift = uniforms.uDrift.value;
510
+ drift.x += Math.max(-SKY_DOME.driftMaxWind, Math.min(SKY_DOME.driftMaxWind, sample.windX)) * SKY_DOME.drift * dt;
511
+ drift.y += Math.max(-SKY_DOME.driftMaxWind, Math.min(SKY_DOME.driftMaxWind, sample.windZ)) * SKY_DOME.drift * dt;
512
+ uniforms.uCover.value = cover;
513
+ uniforms.uSunsetAmount.value = sunset;
514
+ uniforms.uSunVis.value = sunVisibilityOf(sample);
515
+ uniforms.uMoonVis.value = nightnessOf(sample);
516
+ uniforms.uStars.value = starVisibilityOf(sample);
517
+ uniforms.uTime.value = time;
518
+ uniforms.uFlash.value = sample.flash;
519
+ };
250
520
  return {
251
521
  color,
252
- update(sample, zone) {
522
+ ...dome ? { object: dome.mesh } : {},
523
+ update(sample, zone, dt = 0) {
253
524
  color.lerpColors(night, day, sample.sun);
254
525
  color.multiplyScalar(sample.skyScale);
526
+ if (dome) color.lerp(sunsetColor, sunsetOf(sample) * SKY_DOME.fogWarmth);
255
527
  if (zone && zone.weight > 0) {
256
528
  zoneColor.setHex(zone.color ?? ZONE_FOG_DEFAULTS.color);
257
529
  color.lerp(tint.copy(zoneColor).multiplyScalar(ZONE_LIGHT.base + sample.sun * ZONE_LIGHT.sun), zone.weight);
@@ -259,7 +531,11 @@ var GameWeatherThree = (() => {
259
531
  const background = scene.background;
260
532
  if (background && background.isColor) background.copy(color);
261
533
  else scene.background = color.clone();
534
+ updateDome(sample, dt);
262
535
  return color;
536
+ },
537
+ dispose() {
538
+ dome?.dispose();
263
539
  }
264
540
  };
265
541
  }
@@ -2442,8 +2718,11 @@ var GameWeatherThree = (() => {
2442
2718
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
2443
2719
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
2444
2720
  aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
2445
- /** A hole in the tank: the page's petrol leak without the fire and the blast (the pool and the drips). A normal bullet does only this. */
2446
- aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", {}),
2721
+ /**
2722
+ * A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
2723
+ * host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
2724
+ */
2725
+ aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
2447
2726
  /** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
2448
2727
  aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
2449
2728
  ];
@@ -2492,6 +2771,7 @@ var GameWeatherThree = (() => {
2492
2771
  if (field.on) field.clear();
2493
2772
  return;
2494
2773
  }
2774
+ field.coverTopAt = options.cover && !options.cover.isEmpty() ? options.cover.coverTopAt : void 0;
2495
2775
  field.puddleAt = options.puddleAt ?? ((x, z) => inPuddle(puddles, x, z));
2496
2776
  field.drive(sample.drops, sample.windX, camera2[0], camera2[2]);
2497
2777
  field.update(dt, sample.rain >= (options.splashFrom ?? SPLASH_FROM_MM), camera2);
@@ -2508,6 +2788,10 @@ var GameWeatherThree = (() => {
2508
2788
  var RAIN_CURTAIN_VERTEX = "uniform float uTime; uniform vec3 uCam; void main(){ vec3 p = position; p.y = mod(p.y - uTime*13., 25.); p.xz = uCam.xz + mod(p.xz - uCam.xz + 35., 70.) - 35.; gl_Position = projectionMatrix*viewMatrix*vec4(p,1.); gl_PointSize = 1.6; }";
2509
2789
  var RAIN_CURTAIN_FRAGMENT = "uniform float uDay; void main(){ gl_FragColor = vec4(vec3(.68,.72,.78)*(0.25+0.75*uDay), .22+.1*uDay); }";
2510
2790
  var RAIN_CURTAIN_PROFILES = { low: 0.35, medium: 0.7, high: 1 };
2791
+ var RAIN_CURTAIN_COVERED_VERTEX = "uniform float uTime; uniform vec3 uCam; uniform sampler2D uCover; uniform vec3 uCoverBox; void main(){ vec3 p = position; p.y = mod(p.y - uTime*13., 25.); p.xz = uCam.xz + mod(p.xz - uCam.xz + 35., 70.) - 35.; float top = texture2D(uCover, (p.xz - uCoverBox.xy) / (uCoverBox.z * 130.)).r; if (p.y < top) { gl_Position = vec4(2., 2., 2., 1.); gl_PointSize = 0.; return; } gl_Position = projectionMatrix*viewMatrix*vec4(p,1.); gl_PointSize = 1.6; }";
2792
+ var RAIN_COVER_CELLS = 130;
2793
+ var RAIN_COVER_CELL = RAIN_CURTAIN.width / 128;
2794
+ var NO_COVER_HEIGHT = -1;
2511
2795
  var RAIN_CURTAIN_FULL_AT = 4e3;
2512
2796
  function rainCurtainPositions(random = Math.random, count = RAIN_CURTAIN.count) {
2513
2797
  const positions = new Float32Array(count * 3);
@@ -2523,7 +2807,36 @@ var GameWeatherThree = (() => {
2523
2807
  const geometry = new THREE.BufferGeometry();
2524
2808
  geometry.setAttribute("position", new THREE.BufferAttribute(rainCurtainPositions(options.random, count), 3));
2525
2809
  const uniforms = { uTime: { value: 0 }, uCam: { value: new THREE.Vector3() }, uDay: { value: 1 } };
2526
- const material = new THREE.ShaderMaterial({ uniforms, transparent: true, depthWrite: false, vertexShader: RAIN_CURTAIN_VERTEX, fragmentShader: RAIN_CURTAIN_FRAGMENT });
2810
+ const cover = options.cover;
2811
+ const coverCells = cover ? new Float32Array(RAIN_COVER_CELLS * RAIN_COVER_CELLS) : void 0;
2812
+ const coverTexture = coverCells ? new THREE.DataTexture(coverCells, RAIN_COVER_CELLS, RAIN_COVER_CELLS, THREE.RedFormat, THREE.FloatType) : void 0;
2813
+ if (coverTexture) {
2814
+ coverTexture.minFilter = THREE.NearestFilter;
2815
+ coverTexture.magFilter = THREE.NearestFilter;
2816
+ }
2817
+ const coverBox = new THREE.Vector3();
2818
+ const coverUniforms = coverTexture ? { uCover: { value: coverTexture }, uCoverBox: { value: coverBox } } : {};
2819
+ const material = new THREE.ShaderMaterial({ uniforms: { ...uniforms, ...coverUniforms }, transparent: true, depthWrite: false, vertexShader: coverTexture ? RAIN_CURTAIN_COVERED_VERTEX : RAIN_CURTAIN_VERTEX, fragmentShader: RAIN_CURTAIN_FRAGMENT });
2820
+ let cutX = NaN;
2821
+ let cutZ = NaN;
2822
+ let cutVersion = -1;
2823
+ const cutCover = (camera2) => {
2824
+ if (!cover || !coverCells || !coverTexture) return;
2825
+ const originX = Math.floor((camera2.x - RAIN_CURTAIN.width / 2) / RAIN_COVER_CELL) * RAIN_COVER_CELL;
2826
+ const originZ = Math.floor((camera2.z - RAIN_CURTAIN.width / 2) / RAIN_COVER_CELL) * RAIN_COVER_CELL;
2827
+ const version = cover.version();
2828
+ if (originX === cutX && originZ === cutZ && version === cutVersion) return;
2829
+ cutX = originX;
2830
+ cutZ = originZ;
2831
+ cutVersion = version;
2832
+ for (let row = 0; row < RAIN_COVER_CELLS; row++) {
2833
+ for (let column = 0; column < RAIN_COVER_CELLS; column++) {
2834
+ coverCells[row * RAIN_COVER_CELLS + column] = cover.coverTopAt(originX + (column + 0.5) * RAIN_COVER_CELL, originZ + (row + 0.5) * RAIN_COVER_CELL) ?? NO_COVER_HEIGHT;
2835
+ }
2836
+ }
2837
+ coverTexture.needsUpdate = true;
2838
+ coverBox.set(originX, originZ, RAIN_COVER_CELL);
2839
+ };
2527
2840
  const object = new THREE.Points(geometry, material);
2528
2841
  object.frustumCulled = false;
2529
2842
  object.name = "weather-rain-curtain";
@@ -2540,6 +2853,7 @@ var GameWeatherThree = (() => {
2540
2853
  uniforms.uTime.value = time;
2541
2854
  uniforms.uDay.value = daylight;
2542
2855
  uniforms.uCam.value.set(camera2.x, camera2.y, camera2.z);
2856
+ if (drawn > 0) cutCover(camera2);
2543
2857
  },
2544
2858
  setProfile(profile) {
2545
2859
  share = RAIN_CURTAIN_PROFILES[profile];
@@ -2547,6 +2861,7 @@ var GameWeatherThree = (() => {
2547
2861
  drawn: () => drawn,
2548
2862
  dispose() {
2549
2863
  geometry.dispose();
2864
+ coverTexture?.dispose();
2550
2865
  material.dispose();
2551
2866
  }
2552
2867
  };
@@ -2559,14 +2874,15 @@ var GameWeatherThree = (() => {
2559
2874
  const group = new THREE.Group();
2560
2875
  group.name = "weather";
2561
2876
  scene.add(group);
2562
- const curtain = createRainCurtain(THREE, { ...options.random ? { random: options.random } : {}, ...options.profile ? { profile: options.profile } : {} });
2877
+ const curtain = createRainCurtain(THREE, { ...options.cover ? { cover: options.cover } : {}, ...options.random ? { random: options.random } : {}, ...options.profile ? { profile: options.profile } : {} });
2563
2878
  const haze = createHeatHaze(THREE);
2564
2879
  group.add(curtain.object, haze.object);
2565
- const sky = createSky(THREE, scene);
2880
+ const sky = createSky(THREE, scene, { camera: camera2, ...options.sun ? { sun: options.sun } : {} });
2881
+ if (sky.object) group.add(sky.object);
2566
2882
  const fog = createFog2(THREE, scene, { stable: options.lights !== void 0 });
2567
2883
  const lightning = createLightning(THREE, scene, vfx, options.lights ? { lights: options.lights } : {});
2568
2884
  const headlights = createHeadlights(THREE, options.lights ? { ...options.headlights, lights: options.lights } : options.headlights);
2569
- const nearRain = createNearRain(vfx, { ...options.puddles ? { puddles: options.puddles } : {}, ...options.puddleAt ? { puddleAt: options.puddleAt } : {} });
2885
+ const nearRain = createNearRain(vfx, { ...options.cover ? { cover: options.cover } : {}, ...options.puddles ? { puddles: options.puddles } : {}, ...options.puddleAt ? { puddleAt: options.puddleAt } : {} });
2570
2886
  const on = new Map(WEATHER_LAYERS.map((id) => [id, options.layers?.[id] ?? true]));
2571
2887
  let zone = options.zone;
2572
2888
  let time = 0;
@@ -2577,6 +2893,7 @@ var GameWeatherThree = (() => {
2577
2893
  else if (id === "fog") fog.clear();
2578
2894
  else if (id === "lightning") lightning.light.intensity = 0;
2579
2895
  else if (id === "haze") haze.object.visible = false;
2896
+ else if (id === "sky" && sky.object) sky.object.visible = false;
2580
2897
  };
2581
2898
  return {
2582
2899
  curtain,
@@ -2596,7 +2913,7 @@ var GameWeatherThree = (() => {
2596
2913
  const where = [eye.x, eye.y, eye.z];
2597
2914
  const background = scene.background ?? void 0;
2598
2915
  const ownSky = on.get("sky") === true;
2599
- const color = ownSky ? sky.update(sample, zone) : background && background.isColor ? background : sky.color;
2916
+ const color = ownSky ? sky.update(sample, zone, dt) : background && background.isColor ? background : sky.color;
2600
2917
  if (on.get("fog")) fog.update(sample, color, zone);
2601
2918
  if (on.get("lightning")) lightning.update(sample, ownSky ? scene.background : void 0);
2602
2919
  if (on.get("far_rain")) curtain.update(sample, eye, time, sample.sun);
@@ -2623,6 +2940,7 @@ var GameWeatherThree = (() => {
2623
2940
  scene.remove(group);
2624
2941
  curtain.dispose();
2625
2942
  haze.dispose();
2943
+ sky.dispose();
2626
2944
  lightning.dispose();
2627
2945
  headlights.dispose();
2628
2946
  nearRain.clear();
@@ -2671,6 +2989,7 @@ var GameWeatherThree = (() => {
2671
2989
  camera: host.camera,
2672
2990
  weather,
2673
2991
  ...options.vfx ? { vfx: options.vfx } : {},
2992
+ ...host.rainCover ? { cover: host.rainCover } : {},
2674
2993
  ...options.profile ? { profile: options.profile } : {},
2675
2994
  ...options.random ? { random: options.random } : {},
2676
2995
  ...options.zone ? { zone: options.zone } : {},
@@ -2678,6 +2997,7 @@ var GameWeatherThree = (() => {
2678
2997
  ...options.puddleAt ? { puddleAt: options.puddleAt } : {},
2679
2998
  ...options.headlights ? { headlights: options.headlights } : {},
2680
2999
  ...options.layers ? { layers: options.layers } : {},
3000
+ ...sunOption(options.sun ?? sunOf(host.scene)),
2681
3001
  ...isLightBudget(host.lights) ? { lights: host.lights } : {}
2682
3002
  });
2683
3003
  const item = options.rigItem && host.addObject ? options.rigItem : void 0;
@@ -2685,6 +3005,15 @@ var GameWeatherThree = (() => {
2685
3005
  }
2686
3006
  };
2687
3007
  }
3008
+ function sunOf(scene) {
3009
+ let found;
3010
+ scene.traverse((node) => {
3011
+ const light = node;
3012
+ if (!found && light.isDirectionalLight && light.castShadow) found = light;
3013
+ });
3014
+ return found;
3015
+ }
3016
+ var sunOption = (sun) => sun ? { sun } : {};
2688
3017
  function footprintOf(car) {
2689
3018
  if (!car.width) return void 0;
2690
3019
  const z = car.group.position.z;