@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.
package/README.md CHANGED
@@ -9,7 +9,7 @@ The three.js picture of [`@adatechnology/game-weather`](../game-weather): the ra
9
9
  | **Near rain** (`createNearRain`) | the Workshop's streaks (`engine.rain`, up to 4 000, slanted by the wind), the splashes on the `normal` sprite pool and the rings (only where `puddleAt` says there is a puddle, within `12 / (1 + quality)` m); `game-vfx-three` draws them | Workshop W313-331 |
10
10
  | **Mist and ash** (`emitAirborne`) | `mistPerSecond` puffs of low mist and `ashPerSecond` flakes of falling ash a second around the camera, into the same pool | Workshop `neblina`, W1085-1086 |
11
11
  | **Fog** (`createFog`, `fogOf`) | linear fog (near 25 m, far from the weather: 220 clear, 140 rain) or exponential-squared fog where the weather has a density (`fog` 0.075), and the zone fog (colour, far, weight; near 4 m at full weight) | game `skyUpdate` and `ZONA_NEBLINA` |
12
- | **Sky** (`createSky`) | night colour `0x0b0f18` to day `0x8796a6` by `sample.sun`, times `sample.skyScale` (the page's 0.8 in rain), pulled to the zone colour; it also gives the fog its colour | game `skyUpdate` |
12
+ | **Sky** (`createSky`, `createWeatherRenderer({ sun })`) | colour `0x0b0f18` to `0x8796a6` by `sample.sun`, times `sample.skyScale`, pulled to the zone colour; it is the fog's colour and the dome's horizon. With a camera it also builds one dome that follows it (renders first, no depth, no ray target): zenith-to-horizon gradient, sun disc and glow in the host sun's direction (the hour's arc without one), sunrise and sunset warmth, one procedural cloud layer whose cover follows the weather (`cloudCoverOf`: scattered clear, full overcast in rain, darker in storms) and drifts with the wind, and at night the moon and stars (`starVisibilityOf`: none under overcast). `dispose()` releases it | game `skyUpdate` for the colour; the dome is the kit's |
13
13
  | **Lightning** (`createLightning`) | the double flash of `sample.flash`: hemisphere light `+ 3.2 I`, background `+ I * (.25, .27, .32)`, screen white `I * .12` | Workshop `chuva`, W1068-1072 |
14
14
  | **Headlights** (`createHeadlights`) | two spot lights and two additive beam cones on any `Object3D`, lit at night, in rain or in fog, real light only within 40 m of the camera, and rain that glows inside the beam (up to 600 lit drops a second) | Workshop `farol`, W101-103 and W1161-1170 |
15
15
  | **Heat haze** (`createHeatHaze`) | warm bands that rise over the lower half of the view, by `sample.haze` | SDK-made: no team delivered it |
@@ -35,7 +35,7 @@ picture.update(dt)
35
35
  `createWeatherTestModule({ visual: createWeatherVisual({ vfx: room.vfx }) })` (the module of `game-weather`) adds the picture to the weather bench: seven layers
36
36
  (rain curtain, near rain and splashes, mist and ash, sky, lightning, headlights, heat haze; names in pt-BR and en), and a lamp rig in front of the camera to show the headlights. The rig's car is not drawn here: pass
37
37
  `vehicles: (THREE) => createVehiclesThree(THREE, { kit })` (game-vehicles-three, with the fleet installed) and it builds a fleet car (`rigVehicle`, default
38
- `midsize_sedan`) under the lamps, so it follows the vehicles SDK; without it the rig has only the lamps and their beams. `layers: { sky: false }` keeps a room's own sky; the bench's own `fog` layer reaches the
38
+ `midsize_sedan`) under the lamps, so it follows the vehicles SDK; without it the rig has only the lamps and their beams. `layers: { sky: false }` keeps a room's own sky (the dome follows the host's shadow-casting `DirectionalLight`, or `sun`); the bench's own `fog` layer reaches the
39
39
  renderer too. The fog layer gives back the fog the host had when it is switched off.
40
40
 
41
41
  ## Proof
@@ -132,22 +132,282 @@ function createHeadlights(THREE, rules = {}) {
132
132
  // src/fog.ts
133
133
  import { createFog as createStableFog } from "@adatechnology/game-render-three";
134
134
 
135
+ // src/sky-shader.ts
136
+ var SKY_VERTEX = (
137
+ /* glsl */
138
+ `
139
+ varying vec3 vDir;
140
+ void main() {
141
+ vDir = normalize(position);
142
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
143
+ }
144
+ `
145
+ );
146
+ var SKY_FRAGMENT = (
147
+ /* glsl */
148
+ `
149
+ precision highp float;
150
+ uniform vec3 uZenith;
151
+ uniform vec3 uHorizon;
152
+ uniform vec3 uTint;
153
+ uniform vec3 uSunDir;
154
+ uniform vec3 uSunColor;
155
+ uniform vec3 uMoonDir;
156
+ uniform vec3 uCloudLit;
157
+ uniform vec3 uCloudShade;
158
+ uniform vec3 uDrift;
159
+ uniform float uSunsetAmount;
160
+ uniform float uSunVis;
161
+ uniform float uMoonVis;
162
+ uniform float uStars;
163
+ uniform float uCover;
164
+ uniform float uTime;
165
+ uniform float uFlash;
166
+ varying vec3 vDir;
167
+
168
+ float hash2(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
169
+ float hash3(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }
170
+ float noise(vec2 p) {
171
+ vec2 i = floor(p);
172
+ vec2 f = fract(p);
173
+ f = f * f * (3.0 - 2.0 * f);
174
+ 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);
175
+ }
176
+ float fbm(vec2 p) {
177
+ float value = 0.0;
178
+ float amplitude = 0.5;
179
+ for (int octave = 0; octave < 4; octave++) {
180
+ value += amplitude * noise(p);
181
+ p = p * 2.03 + vec2(17.1, 9.2);
182
+ amplitude *= 0.5;
183
+ }
184
+ return value;
185
+ }
186
+
187
+ void main() {
188
+ vec3 d = normalize(vDir);
189
+ float height = max(d.y, 0.0);
190
+ vec3 color = mix(uHorizon, uZenith, pow(height, 0.6));
191
+
192
+ vec2 azimuth = normalize(d.xz + vec2(1e-5));
193
+ vec2 sunAzimuth = normalize(uSunDir.xz + vec2(1e-5));
194
+ float towardSun = max(dot(azimuth, sunAzimuth), 0.0);
195
+ color = mix(color, uTint, uSunsetAmount * exp(-height * 6.0) * (0.25 + 0.75 * towardSun * towardSun));
196
+
197
+ float aboveHorizon = smoothstep(-0.05, 0.05, d.y);
198
+ if (uStars > 0.001 && d.y > 0.0) {
199
+ vec3 p = d * 120.0;
200
+ vec3 cell = floor(p);
201
+ float pick = hash3(cell);
202
+ if (pick > 0.985) {
203
+ vec3 spot = vec3(hash3(cell + 1.7), hash3(cell + 5.3), hash3(cell + 9.1)) * 0.4 + 0.3;
204
+ float twinkle = 0.78 + 0.22 * sin(uTime * 2.0 + pick * 60.0);
205
+ float star = (1.0 - smoothstep(0.04, 0.32, length(fract(p) - spot))) * (0.45 + 0.55 * fract(pick * 97.0)) * twinkle;
206
+ color += vec3(0.85, 0.9, 1.0) * star * uStars * smoothstep(0.0, 0.12, d.y);
207
+ }
208
+ }
209
+
210
+ if (uMoonVis > 0.001) {
211
+ float toMoon = dot(d, uMoonDir);
212
+ vec3 tangent = normalize(cross(uMoonDir, vec3(0.0, 1.0, 0.0)));
213
+ vec2 onDisc = vec2(dot(d, tangent), dot(d, cross(uMoonDir, tangent))) / 0.045;
214
+ float disc = (1.0 - smoothstep(0.93, 1.0, length(onDisc))) * step(0.0, toMoon);
215
+ vec3 moon = vec3(0.7, 0.73, 0.8) * (0.62 + 0.38 * fbm(onDisc * 3.0 + 3.0));
216
+ color += (moon * disc + vec3(0.55, 0.62, 0.8) * pow(max(toMoon, 0.0), 220.0) * 0.5) * uMoonVis * aboveHorizon;
217
+ }
218
+
219
+ if (uSunVis > 0.001) {
220
+ float toSun = dot(d, uSunDir);
221
+ float disc = smoothstep(0.99935, 0.99965, toSun);
222
+ float glow = pow(max(toSun, 0.0), 48.0) * 0.5 + pow(max(toSun, 0.0), 6.0) * 0.14;
223
+ color += uSunColor * (glow + disc * 2.5) * uSunVis * aboveHorizon;
224
+ }
225
+
226
+ if (d.y > -0.05) {
227
+ vec2 uv = d.xz / (height + 0.18) * 1.1 + uDrift.xy;
228
+ float density = fbm(uv);
229
+ float threshold = 0.74 - uCover * 0.9;
230
+ float coverage = smoothstep(threshold, threshold + 0.22, density) * smoothstep(-0.05, 0.12, d.y);
231
+ float thick = smoothstep(threshold, threshold + 0.5, density);
232
+ vec3 cloud = mix(uCloudLit, uCloudShade, thick * 0.8);
233
+ cloud = mix(uHorizon, cloud, smoothstep(0.0, 0.3, d.y));
234
+ color = mix(color, cloud, coverage);
235
+ }
236
+
237
+ color = mix(color, vec3(0.78, 0.82, 0.95), uFlash * 0.7);
238
+ gl_FragColor = vec4(color, 1.0);
239
+ #include <colorspace_fragment>
240
+ }
241
+ `
242
+ );
243
+
244
+ // src/sky-state.ts
245
+ var clamp01 = (value) => value < 0 ? 0 : value > 1 ? 1 : value;
246
+ var smoothstep = (from, to, value) => {
247
+ const t = clamp01((value - from) / (to - from));
248
+ return t * t * (3 - 2 * t);
249
+ };
250
+ var CLOUD_COVER = { clear: 0.2, perSkyDimming: 7, perRainMm: 0.4, rainFullAtMm: 5, windMax: 0.15, windFullAt: 20 };
251
+ var DARK_FROM_SKY_SCALE = 0.95;
252
+ var DARK_SPAN = 0.45;
253
+ function cloudCoverOf(sample) {
254
+ const dimming = clamp01(1 - sample.skyScale);
255
+ const rain = Math.min(1, sample.rain / CLOUD_COVER.rainFullAtMm);
256
+ const wind = Math.min(1, Math.hypot(sample.windX, sample.windZ) / CLOUD_COVER.windFullAt) * CLOUD_COVER.windMax;
257
+ return clamp01(CLOUD_COVER.clear + dimming * CLOUD_COVER.perSkyDimming + rain * CLOUD_COVER.perRainMm + wind);
258
+ }
259
+ function cloudDarknessOf(sample) {
260
+ return clamp01((DARK_FROM_SKY_SCALE - sample.skyScale) / DARK_SPAN);
261
+ }
262
+ var nightnessOf = (sample) => clamp01(sample.nightFactor) ** 3;
263
+ function starVisibilityOf(sample) {
264
+ return nightnessOf(sample) * clamp01(1 - cloudCoverOf(sample) * 1.25);
265
+ }
266
+ function sunsetOf(sample) {
267
+ const low = smoothstep(0.02, 0.15, sample.sun) * (1 - smoothstep(0.15, 0.5, sample.sun));
268
+ return low * (1 - cloudCoverOf(sample) * 0.75);
269
+ }
270
+ var sunVisibilityOf = (sample) => smoothstep(0.02, 0.15, sample.sun);
271
+ function sunDirectionOf(sample, host, out) {
272
+ if (host) {
273
+ const target = host.target?.position;
274
+ out.x = host.position.x - (target?.x ?? 0);
275
+ out.y = host.position.y - (target?.y ?? 0);
276
+ out.z = host.position.z - (target?.z ?? 0);
277
+ } else {
278
+ const angle = (sample.dayFraction - 0.25) * Math.PI * 2;
279
+ out.x = Math.cos(angle);
280
+ out.y = Math.sin(angle);
281
+ out.z = -0.3;
282
+ }
283
+ const length = Math.hypot(out.x, out.y, out.z) || 1;
284
+ out.x /= length;
285
+ out.y /= length;
286
+ out.z /= length;
287
+ return out;
288
+ }
289
+
135
290
  // src/sky.ts
136
291
  var SKY_NIGHT = 724760;
137
292
  var SKY_DAY = 8885926;
138
293
  var ZONE_LIGHT = { base: 0.35, sun: 0.65 };
139
294
  var ZONE_FOG_DEFAULTS = { color: 3820090, far: 60 };
140
- function createSky(THREE, scene) {
295
+ var SKY_DOME = {
296
+ zenithDay: 4159684,
297
+ zenithNight: 132106,
298
+ sunsetTint: 16742973,
299
+ sunDay: 16774368,
300
+ sunSet: 16751184,
301
+ cloudDay: 16054010,
302
+ cloudOvercast: 12107462,
303
+ cloudStorm: 4080460,
304
+ cloudNight: 1712176,
305
+ /** How much of the sunset warmth the horizon (and so the fog) takes. */
306
+ fogWarmth: 0.3,
307
+ /** Clouds drift this many noise units per second for each m/s of wind (wind capped at `driftMaxWind`). */
308
+ drift: 25e-4,
309
+ driftMaxWind: 20,
310
+ /** Largest radius of the dome; it is 90 % of the camera's far plane when that is smaller. */
311
+ radius: 900,
312
+ renderOrder: -1e3
313
+ };
314
+ function createDome(THREE, camera) {
315
+ const vector = () => ({ value: new THREE.Vector3() });
316
+ const colour = (hex) => ({ value: new THREE.Color(hex) });
317
+ const uniforms = {
318
+ uZenith: colour(SKY_DOME.zenithDay),
319
+ uHorizon: colour(SKY_DAY),
320
+ uTint: colour(SKY_DOME.sunsetTint),
321
+ uSunDir: vector(),
322
+ uSunColor: colour(SKY_DOME.sunDay),
323
+ uMoonDir: vector(),
324
+ uCloudLit: colour(SKY_DOME.cloudDay),
325
+ uCloudShade: colour(SKY_DOME.cloudOvercast),
326
+ uDrift: vector(),
327
+ uSunsetAmount: { value: 0 },
328
+ uSunVis: { value: 0 },
329
+ uMoonVis: { value: 0 },
330
+ uStars: { value: 0 },
331
+ uCover: { value: 0 },
332
+ uTime: { value: 0 },
333
+ uFlash: { value: 0 }
334
+ };
335
+ const geometry = new THREE.SphereGeometry(1, 24, 12);
336
+ const material = new THREE.ShaderMaterial({ uniforms, vertexShader: SKY_VERTEX, fragmentShader: SKY_FRAGMENT, side: THREE.BackSide, depthTest: false, depthWrite: false, fog: false, toneMapped: false });
337
+ const mesh = new THREE.Mesh(geometry, material);
338
+ mesh.name = "sky-dome";
339
+ mesh.renderOrder = SKY_DOME.renderOrder;
340
+ mesh.frustumCulled = false;
341
+ mesh.raycast = () => void 0;
342
+ const far = camera.far;
343
+ mesh.scale.setScalar(far > 0 ? Math.min(SKY_DOME.radius, far * 0.9) : SKY_DOME.radius);
344
+ return {
345
+ mesh,
346
+ uniforms,
347
+ dispose() {
348
+ mesh.removeFromParent();
349
+ geometry.dispose();
350
+ material.dispose();
351
+ }
352
+ };
353
+ }
354
+ function createSky(THREE, scene, options = {}) {
141
355
  const night = new THREE.Color(SKY_NIGHT);
142
356
  const day = new THREE.Color(SKY_DAY);
143
357
  const zoneColor = new THREE.Color(ZONE_FOG_DEFAULTS.color);
144
358
  const tint = new THREE.Color();
145
359
  const color = new THREE.Color();
360
+ const sunsetColor = new THREE.Color(SKY_DOME.sunsetTint);
361
+ const zenithDay = new THREE.Color(SKY_DOME.zenithDay);
362
+ const zenithNight = new THREE.Color(SKY_DOME.zenithNight);
363
+ const sunDay = new THREE.Color(SKY_DOME.sunDay);
364
+ const sunSet = new THREE.Color(SKY_DOME.sunSet);
365
+ const cloudDay = new THREE.Color(SKY_DOME.cloudDay);
366
+ const cloudOvercast = new THREE.Color(SKY_DOME.cloudOvercast);
367
+ const cloudStorm = new THREE.Color(SKY_DOME.cloudStorm);
368
+ const cloudNight = new THREE.Color(SKY_DOME.cloudNight);
369
+ const sunDirection = { x: 0, y: 1, z: 0 };
370
+ const dome = options.camera ? createDome(THREE, options.camera) : void 0;
371
+ let time = 0;
372
+ const updateDome = (sample, dt) => {
373
+ if (!dome || !options.camera) return;
374
+ const { uniforms, mesh } = dome;
375
+ time += dt;
376
+ const cover = cloudCoverOf(sample);
377
+ const sunset = sunsetOf(sample);
378
+ const dark = cloudDarknessOf(sample);
379
+ mesh.visible = true;
380
+ mesh.position.copy(options.camera.position);
381
+ const zenith = uniforms.uZenith.value;
382
+ zenith.lerpColors(zenithNight, zenithDay, sample.sun).multiplyScalar(sample.skyScale).lerp(color, cover * 0.85);
383
+ uniforms.uHorizon.value.copy(color);
384
+ const lit = uniforms.uCloudLit.value;
385
+ lit.lerpColors(cloudDay, cloudOvercast, cover * cover).lerp(cloudStorm, dark).lerp(cloudNight, 1 - Math.min(1, sample.sun * 2.2));
386
+ lit.lerp(sunsetColor, sunset * 0.45);
387
+ uniforms.uCloudShade.value.copy(lit).multiplyScalar(0.62);
388
+ uniforms.uSunColor.value.lerpColors(sunDay, sunSet, sunset);
389
+ const sunVector = uniforms.uSunDir.value;
390
+ sunDirectionOf(sample, options.sun, sunDirection);
391
+ sunVector.set(sunDirection.x, sunDirection.y, sunDirection.z);
392
+ uniforms.uMoonDir.value.set(-sunDirection.x, Math.abs(sunDirection.y) * 0.9 + 0.1, -sunDirection.z).normalize();
393
+ const drift = uniforms.uDrift.value;
394
+ drift.x += Math.max(-SKY_DOME.driftMaxWind, Math.min(SKY_DOME.driftMaxWind, sample.windX)) * SKY_DOME.drift * dt;
395
+ drift.y += Math.max(-SKY_DOME.driftMaxWind, Math.min(SKY_DOME.driftMaxWind, sample.windZ)) * SKY_DOME.drift * dt;
396
+ uniforms.uCover.value = cover;
397
+ uniforms.uSunsetAmount.value = sunset;
398
+ uniforms.uSunVis.value = sunVisibilityOf(sample);
399
+ uniforms.uMoonVis.value = nightnessOf(sample);
400
+ uniforms.uStars.value = starVisibilityOf(sample);
401
+ uniforms.uTime.value = time;
402
+ uniforms.uFlash.value = sample.flash;
403
+ };
146
404
  return {
147
405
  color,
148
- update(sample, zone) {
406
+ ...dome ? { object: dome.mesh } : {},
407
+ update(sample, zone, dt = 0) {
149
408
  color.lerpColors(night, day, sample.sun);
150
409
  color.multiplyScalar(sample.skyScale);
410
+ if (dome) color.lerp(sunsetColor, sunsetOf(sample) * SKY_DOME.fogWarmth);
151
411
  if (zone && zone.weight > 0) {
152
412
  zoneColor.setHex(zone.color ?? ZONE_FOG_DEFAULTS.color);
153
413
  color.lerp(tint.copy(zoneColor).multiplyScalar(ZONE_LIGHT.base + sample.sun * ZONE_LIGHT.sun), zone.weight);
@@ -155,7 +415,11 @@ function createSky(THREE, scene) {
155
415
  const background = scene.background;
156
416
  if (background && background.isColor) background.copy(color);
157
417
  else scene.background = color.clone();
418
+ updateDome(sample, dt);
158
419
  return color;
420
+ },
421
+ dispose() {
422
+ dome?.dispose();
159
423
  }
160
424
  };
161
425
  }
@@ -319,6 +583,7 @@ function createNearRain(vfx, options = {}) {
319
583
  if (field.on) field.clear();
320
584
  return;
321
585
  }
586
+ field.coverTopAt = options.cover && !options.cover.isEmpty() ? options.cover.coverTopAt : void 0;
322
587
  field.puddleAt = options.puddleAt ?? ((x, z) => inPuddle(puddles, x, z));
323
588
  field.drive(sample.drops, sample.windX, camera[0], camera[2]);
324
589
  field.update(dt, sample.rain >= (options.splashFrom ?? SPLASH_FROM_MM), camera);
@@ -335,6 +600,10 @@ var RAIN_CURTAIN = { count: 14e3, width: 70, height: 25, speed: 13, pointSize: 1
335
600
  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; }";
336
601
  var RAIN_CURTAIN_FRAGMENT = "uniform float uDay; void main(){ gl_FragColor = vec4(vec3(.68,.72,.78)*(0.25+0.75*uDay), .22+.1*uDay); }";
337
602
  var RAIN_CURTAIN_PROFILES = { low: 0.35, medium: 0.7, high: 1 };
603
+ 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; }";
604
+ var RAIN_COVER_CELLS = 130;
605
+ var RAIN_COVER_CELL = RAIN_CURTAIN.width / 128;
606
+ var NO_COVER_HEIGHT = -1;
338
607
  var RAIN_CURTAIN_FULL_AT = 4e3;
339
608
  function rainCurtainPositions(random = Math.random, count = RAIN_CURTAIN.count) {
340
609
  const positions = new Float32Array(count * 3);
@@ -350,7 +619,36 @@ function createRainCurtain(THREE, options = {}) {
350
619
  const geometry = new THREE.BufferGeometry();
351
620
  geometry.setAttribute("position", new THREE.BufferAttribute(rainCurtainPositions(options.random, count), 3));
352
621
  const uniforms = { uTime: { value: 0 }, uCam: { value: new THREE.Vector3() }, uDay: { value: 1 } };
353
- const material = new THREE.ShaderMaterial({ uniforms, transparent: true, depthWrite: false, vertexShader: RAIN_CURTAIN_VERTEX, fragmentShader: RAIN_CURTAIN_FRAGMENT });
622
+ const cover = options.cover;
623
+ const coverCells = cover ? new Float32Array(RAIN_COVER_CELLS * RAIN_COVER_CELLS) : void 0;
624
+ const coverTexture = coverCells ? new THREE.DataTexture(coverCells, RAIN_COVER_CELLS, RAIN_COVER_CELLS, THREE.RedFormat, THREE.FloatType) : void 0;
625
+ if (coverTexture) {
626
+ coverTexture.minFilter = THREE.NearestFilter;
627
+ coverTexture.magFilter = THREE.NearestFilter;
628
+ }
629
+ const coverBox = new THREE.Vector3();
630
+ const coverUniforms = coverTexture ? { uCover: { value: coverTexture }, uCoverBox: { value: coverBox } } : {};
631
+ 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 });
632
+ let cutX = NaN;
633
+ let cutZ = NaN;
634
+ let cutVersion = -1;
635
+ const cutCover = (camera) => {
636
+ if (!cover || !coverCells || !coverTexture) return;
637
+ const originX = Math.floor((camera.x - RAIN_CURTAIN.width / 2) / RAIN_COVER_CELL) * RAIN_COVER_CELL;
638
+ const originZ = Math.floor((camera.z - RAIN_CURTAIN.width / 2) / RAIN_COVER_CELL) * RAIN_COVER_CELL;
639
+ const version = cover.version();
640
+ if (originX === cutX && originZ === cutZ && version === cutVersion) return;
641
+ cutX = originX;
642
+ cutZ = originZ;
643
+ cutVersion = version;
644
+ for (let row = 0; row < RAIN_COVER_CELLS; row++) {
645
+ for (let column = 0; column < RAIN_COVER_CELLS; column++) {
646
+ 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;
647
+ }
648
+ }
649
+ coverTexture.needsUpdate = true;
650
+ coverBox.set(originX, originZ, RAIN_COVER_CELL);
651
+ };
354
652
  const object = new THREE.Points(geometry, material);
355
653
  object.frustumCulled = false;
356
654
  object.name = "weather-rain-curtain";
@@ -367,6 +665,7 @@ function createRainCurtain(THREE, options = {}) {
367
665
  uniforms.uTime.value = time;
368
666
  uniforms.uDay.value = daylight;
369
667
  uniforms.uCam.value.set(camera.x, camera.y, camera.z);
668
+ if (drawn > 0) cutCover(camera);
370
669
  },
371
670
  setProfile(profile) {
372
671
  share = RAIN_CURTAIN_PROFILES[profile];
@@ -374,6 +673,7 @@ function createRainCurtain(THREE, options = {}) {
374
673
  drawn: () => drawn,
375
674
  dispose() {
376
675
  geometry.dispose();
676
+ coverTexture?.dispose();
377
677
  material.dispose();
378
678
  }
379
679
  };
@@ -386,14 +686,15 @@ function createWeatherRenderer(THREE, options) {
386
686
  const group = new THREE.Group();
387
687
  group.name = "weather";
388
688
  scene.add(group);
389
- const curtain = createRainCurtain(THREE, { ...options.random ? { random: options.random } : {}, ...options.profile ? { profile: options.profile } : {} });
689
+ const curtain = createRainCurtain(THREE, { ...options.cover ? { cover: options.cover } : {}, ...options.random ? { random: options.random } : {}, ...options.profile ? { profile: options.profile } : {} });
390
690
  const haze = createHeatHaze(THREE);
391
691
  group.add(curtain.object, haze.object);
392
- const sky = createSky(THREE, scene);
692
+ const sky = createSky(THREE, scene, { camera, ...options.sun ? { sun: options.sun } : {} });
693
+ if (sky.object) group.add(sky.object);
393
694
  const fog = createFog(THREE, scene, { stable: options.lights !== void 0 });
394
695
  const lightning = createLightning(THREE, scene, vfx, options.lights ? { lights: options.lights } : {});
395
696
  const headlights = createHeadlights(THREE, options.lights ? { ...options.headlights, lights: options.lights } : options.headlights);
396
- const nearRain = createNearRain(vfx, { ...options.puddles ? { puddles: options.puddles } : {}, ...options.puddleAt ? { puddleAt: options.puddleAt } : {} });
697
+ const nearRain = createNearRain(vfx, { ...options.cover ? { cover: options.cover } : {}, ...options.puddles ? { puddles: options.puddles } : {}, ...options.puddleAt ? { puddleAt: options.puddleAt } : {} });
397
698
  const on = new Map(WEATHER_LAYERS.map((id) => [id, options.layers?.[id] ?? true]));
398
699
  let zone = options.zone;
399
700
  let time = 0;
@@ -404,6 +705,7 @@ function createWeatherRenderer(THREE, options) {
404
705
  else if (id === "fog") fog.clear();
405
706
  else if (id === "lightning") lightning.light.intensity = 0;
406
707
  else if (id === "haze") haze.object.visible = false;
708
+ else if (id === "sky" && sky.object) sky.object.visible = false;
407
709
  };
408
710
  return {
409
711
  curtain,
@@ -423,7 +725,7 @@ function createWeatherRenderer(THREE, options) {
423
725
  const where = [eye.x, eye.y, eye.z];
424
726
  const background = scene.background ?? void 0;
425
727
  const ownSky = on.get("sky") === true;
426
- const color = ownSky ? sky.update(sample, zone) : background && background.isColor ? background : sky.color;
728
+ const color = ownSky ? sky.update(sample, zone, dt) : background && background.isColor ? background : sky.color;
427
729
  if (on.get("fog")) fog.update(sample, color, zone);
428
730
  if (on.get("lightning")) lightning.update(sample, ownSky ? scene.background : void 0);
429
731
  if (on.get("far_rain")) curtain.update(sample, eye, time, sample.sun);
@@ -450,6 +752,7 @@ function createWeatherRenderer(THREE, options) {
450
752
  scene.remove(group);
451
753
  curtain.dispose();
452
754
  haze.dispose();
755
+ sky.dispose();
453
756
  lightning.dispose();
454
757
  headlights.dispose();
455
758
  nearRain.clear();
@@ -498,6 +801,7 @@ function createWeatherVisual(options = {}) {
498
801
  camera: host.camera,
499
802
  weather,
500
803
  ...options.vfx ? { vfx: options.vfx } : {},
804
+ ...host.rainCover ? { cover: host.rainCover } : {},
501
805
  ...options.profile ? { profile: options.profile } : {},
502
806
  ...options.random ? { random: options.random } : {},
503
807
  ...options.zone ? { zone: options.zone } : {},
@@ -505,6 +809,7 @@ function createWeatherVisual(options = {}) {
505
809
  ...options.puddleAt ? { puddleAt: options.puddleAt } : {},
506
810
  ...options.headlights ? { headlights: options.headlights } : {},
507
811
  ...options.layers ? { layers: options.layers } : {},
812
+ ...sunOption(options.sun ?? sunOf(host.scene)),
508
813
  ...isLightBudget(host.lights) ? { lights: host.lights } : {}
509
814
  });
510
815
  const item = options.rigItem && host.addObject ? options.rigItem : void 0;
@@ -512,6 +817,15 @@ function createWeatherVisual(options = {}) {
512
817
  }
513
818
  };
514
819
  }
820
+ function sunOf(scene) {
821
+ let found;
822
+ scene.traverse((node) => {
823
+ const light = node;
824
+ if (!found && light.isDirectionalLight && light.castShadow) found = light;
825
+ });
826
+ return found;
827
+ }
828
+ var sunOption = (sun) => sun ? { sun } : {};
515
829
  function footprintOf(car) {
516
830
  if (!car.width) return void 0;
517
831
  const z = car.group.position.z;
@@ -581,10 +895,19 @@ function attachRig(THREE, host, renderer, place, vehicles, key, item) {
581
895
  var WEATHER_IDS = ["far_rain", "near_rain", "mist", "fog", "sky", "lightning", "headlights", "haze"];
582
896
 
583
897
  export {
898
+ CLOUD_COVER,
899
+ cloudCoverOf,
900
+ cloudDarknessOf,
901
+ nightnessOf,
902
+ starVisibilityOf,
903
+ sunsetOf,
904
+ sunVisibilityOf,
905
+ sunDirectionOf,
584
906
  SKY_NIGHT,
585
907
  SKY_DAY,
586
908
  ZONE_LIGHT,
587
909
  ZONE_FOG_DEFAULTS,
910
+ SKY_DOME,
588
911
  createSky,
589
912
  FOG_NEAR,
590
913
  FOG_ZONE_NEAR,
@@ -610,6 +933,9 @@ export {
610
933
  RAIN_CURTAIN_VERTEX,
611
934
  RAIN_CURTAIN_FRAGMENT,
612
935
  RAIN_CURTAIN_PROFILES,
936
+ RAIN_CURTAIN_COVERED_VERTEX,
937
+ RAIN_COVER_CELLS,
938
+ RAIN_COVER_CELL,
613
939
  RAIN_CURTAIN_FULL_AT,
614
940
  rainCurtainPositions,
615
941
  createRainCurtain,
@@ -618,4 +944,4 @@ export {
618
944
  weatherVisualTextOf,
619
945
  createWeatherVisual
620
946
  };
621
- //# sourceMappingURL=chunk-SOEOSGSU.js.map
947
+ //# sourceMappingURL=chunk-EWWBQHTX.js.map