Rise
The Vieneo Province
Loading...
Searching...
No Matches
weather.cpp
Go to the documentation of this file.
1#include "weather.h"
2#include "Viewscreen.h"
3#include "../MathUtilities.h"
5#include "NightVisionGain.h"
6#include "CloudNightVision.h"
7#include "CockpitLighting.h"
8#include "LocalLightning.h"
9#include "WeatherOverrides.h"
10
12{
13 viewscreen = ptr;
14 logger = ptr->logger;
15 gridLightning.Seed(uint32_t(GetTickCount64()) ^ GetCurrentProcessId());
16
17 cloudVisTarget1 = 0.0f;
18 cloudVisSmooth1 = 0.0f;
19}
20
21// This is the attenuation through the atmosphere to the top of the clouds
23{
24 // ensure positive
25 float z = RiseMath::Max(10.0f, playerships[0].mslKm);
26 // optical depth above z ... 1.2f is the extinction factor
27 float tau = 0.5f * expf(-z / ScaleHeightC);
28 // Beer-Lambert attenuation
29 return expf(-tau);
30}
31
32void weather::FrameMove(float fElapsedTime)
33{
34 logger->AddToCallStack("weather::FrameMove");
35 if (playerships[0].isSimulator || !std::isfinite(playerships[0].mslKm) || playerships[0].mslKm >= 63.f)
37
38 RiseMath::Vector3 result;
39 RiseMath::Color colorzenith;
40 float shiplightCloudOpacity = 0.f;
41 const RiseMath::Vector3 Xsunlight = viewscreen->sunlight.Direction; // Start of the ray
42 // Recompute from the current celestial frame, including SUN overrides.
43 // The simulator clears the occluder immediately, with no retained event state.
44 const auto& iomere = allobjects[ourplanetC];
45 const auto& sun = allobjects[ourstarC];
47 {-iomere.position.x,-iomere.position.y,-iomere.position.z},iomere.scale,
48 CelestialEclipse::SolarAngularRadius(sun.scale,sun.range));
50 {-playerships[0].position.x,-playerships[0].position.y,-playerships[0].position.z},
51 {-Xsunlight.x,-Xsunlight.y,-Xsunlight.z});
52 // ReSharper disable once CppJoinDeclarationAndAssignment
53 HRESULT hr;
54
55 // this datapacket.f_z is from the client to the sound module and appears to have been calculated
56 if (!hullIonization && GetPrecip() > 12.5f)
57 {
58 hullIonization = true;
59 if (playerships[0].reference != REF_ONGROUND)
60 {
61 Command command;
62 command.name = "AuralHullIonization";
63 viewscreen->gameclass->bus->commandStream.emplace_back(command);
64 logger->Log("Hull ionization detected!");
65 ourcockpit.adrenolinBPM += 20.0f;
66 }
67 }
68 else if (hullIonization && GetPrecip() < 12.5f)
69 {
70 hullIonization = false;
71 }
72
73
74 // Above or below clouds and sunlight on or off and set g_bAboveClouds
75 if (playerships[0].mslKm > cloudTopsMslC)
76 {
77 if (!g_bAboveClouds)
78 {
79 g_bAboveClouds = true;
80 if (playerships[0].reference == REF_APNMODE)
82
84
85 logger->Log("----------------------------------- ACMPL");
86 }
87 }
88 else if (playerships[0].mslKm < cloudBufferMslC)
89 {
91 {
92 g_bAboveClouds = false;
93 if (playerships[0].reference == REF_ACLMODE)
95
97
98 logger->Log("----------------------------------- BCMPL");
99 }
100 }
101
103 AdvanceSpatialFog(fElapsedTime);
104 UpdateCloudBaseWeather(fElapsedTime);
105 UpdateTerrainSnow(fElapsedTime);
106 UpdateLightningSpawns(fElapsedTime);
107
108 float f_temp;
109 // Distance from CG
110 if (playerships[0].mslKm > 0.0f)
111 f_temp = playerships[0].mslKm + radiusC;
112 else
113 f_temp = radiusC;
114
115 // Sun elevation (light level hitting flat plane)
116 // Admin commands reposition the shared sun; use its geometry here too.
117 if (!playerships[0].isSimulator || daylightOverride != -1.0f)
118 {
119 const float angle = RiseMath::HalfPi - acosf(radiusC / f_temp); // one half view width on surface (1A)
121 elevation = RiseMath::Vec3Dot(&result1, &Xsunlight); // Elevation needs adjustment after cloud illum.
122 elevation += cosf(angle); // passed in, accounts for the planet obstructing our view
123 elevation = Clamp(elevation, -1.0f, 1.0f);
124 }
125 else
126 {
127 elevation = 1.0f; // needs to be adjustable by slider
128 }
130
131
132 float inview;
134 inview = static_cast<float>(m_dwSunViz) / powf(viewscreen->gameclass->displayWidth / 1024.0f * 10.25f, 2.0f);
135 else
136 inview = -RiseMath::Vec3Dot(&viewscreen->forwardVector, &Xsunlight); // 1 means it is in view
137 inview = Clamp(inview, 0, 1);
138
139
140 // Shear rate calculations ----------------------------------------------------------------------
141 RiseMath::Vec3Subtract(&result, &playerships[0].velocity, &playerships[0].barycentric);
142 shearRate = RiseMath::Vec3Length(&result) + 0.0353f * cosf(viewscreen->gameclass->bus->LatitudeRad);
143 shearRate *= 0.6f * fElapsedTime; // /1.5km to be safe in which it can change over
144 if (shearRate > 100.0f || shearRate < -100.0f || _isnan(shearRate) || isinf(shearRate))
145 {
146 sprintf_s(msg, sizeof(msg), " velocity %.3f %.3f %.3f", playerships[0].velocity.x, playerships[0].velocity.y, playerships[0].velocity.z);
148 sprintf_s(msg, sizeof(msg), " barycentric %.3f %.3f %.3f", playerships[0].barycentric.x, playerships[0].barycentric.y, playerships[0].barycentric.z);
150 sprintf_s(msg, sizeof(msg), " LatitudeRad %.3f", viewscreen->gameclass->bus->LatitudeRad);
152 sprintf_s(msg, sizeof(msg), "Trapped a violation with shearRate...");
154 }
155
156
157 // Precip smoothing -----------------------------------------------------------------------
159 {
160 SetPrecip(1.0f); // theoretical limit of pure clean air
161 smoothPrecip = 1.0f;
162 }
163 else if (smoothPrecip != -1.0f)
164 {
165 if (smoothPrecip < precip)
166 {
168 if (smoothPrecip > precip) // NOLINT(readability-use-std-min-max)
170 }
171 else if (smoothPrecip > precip)
172 {
174 if (smoothPrecip < precip) // NOLINT(readability-use-std-min-max)
176 }
177 }
179
180
181 // Visibility smoothing -----------------------------------------------------------------------
183 {
184 SetVisibility(168.64f); // legacy clear-air override
185 smoothVisibility = 168.64f;
186 }
188 {
190 {
191 smoothVisibility += shearRate * 5.0f;
192 if (smoothVisibility > visibility) // NOLINT(readability-use-std-min-max)
194 }
195 else if (smoothVisibility > visibility)
196 {
197 smoothVisibility -= shearRate * 5.0f;
198 if (smoothVisibility < visibility) // NOLINT(readability-use-std-min-max)
200 }
201 }
203
204
205
206 // Ceiling smoothing -----------------------------------------------------------------------
207 if (cloudCeilingOverrideKm != -1.0f)
209 else if (cloudCeilingSmoothAglKm != -1.0f) // got a target value
210 {
212 cloudCeilingSmoothAglKm += f_temp * fElapsedTime * 0.01f; // 50 meters in 100 seconds
213 }
215
216
217 // Base smoothing -----------------------------------------------------------------------
218 if (cloudSurfaceSmoothKm != -1.0f) // got a target value
219 {
221 cloudSurfaceSmoothKm += f_temp * fElapsedTime * 0.01f;
222 }
223
224 if (cloudSurfaceSmoothKm != -1.0f && cloudCeilingSmoothAglKm != -1.0f && !g_bAboveClouds && playerships[0].mslKm != -1.0f)
226 else
227 f_BCL = -20.0f;
228
231
232
233 // Clear pending flashes on simulator entry; the volume draw is also
234 // excluded by VolumeCloudsEnabled() while simulating.
235 // CPU density and native passes enter/leave the organic field together.
236 // Simulator and unavailable/mismatched shader sets retain the baseline.
241 else if (!viewscreen->VolumeCloudsEnabled())
242 {
245 }
246
247 // One continuous planet-fixed field drives geometry, opacity and visibility.
248 // Retain the last below-deck activity aloft: the legacy weather path forces
249 // clear-air precipitation above 10 km and must not collapse the towers.
251 {
256 const auto observedWind=g_bAboveClouds ? CloudVolume::Point{} : ObservedWindKms();
258 GetCloudCeilingMslKm(),GetNormalizedPrecip()*.8f+GetTurbulence()*.2f,observedWind,fElapsedTime,
262 // Admin bases also bypass the normal 8.5 km upper limit.
263 if (cloudCeilingOverrideKm != -1.0f)
265 const auto p = -playerships[0].position;
266 const CloudVolume::Point sample{p.x,p.y,p.z};
269 f_ACL = playerships[0].mslKm-column.top;
270 f_BCL = column.base-playerships[0].mslKm;
271 cloudThickness = column.top-column.base;
272 // Fog follows the eye entering a wisp, not the vehicle origin entering
273 // it first. The raymarcher uses this same planet-fixed camera position.
274 RiseMath::Matrix inverseView;
275 auto eyeSample=sample;
276 if (RiseMath::MatrixInverse(&inverseView,nullptr,&viewscreen->matrixLook))
277 eyeSample=CloudVolume::Add(sample,{inverseView._41,inverseView._42,inverseView._43});
279 cloudDensity=medium.density;
280 // Flight dynamics sample the vehicle, independently of the selected camera.
281 const auto vehicleMedium=CloudVolume::SampleMedium(sample,cloudParameters,viewscreen->cloudVolume.Seed());
282 cloudPocket=vehicleMedium.pocket;
283 shiplightCloudOpacity=1.f-expf(-vehicleMedium.extinction*CloudVolume::ShiplightScatterDistanceKm);
284 cloudTurbulenceBlend=CloudVolume::Smooth(vehicleMedium.density*4.f);
286 }
287
288 const auto weatherNow = GetTickCount64();
289 if (weatherNow < weatherDiagnosticUntil && weatherNow >= weatherNextDiagnostic)
290 {
291 weatherNextDiagnostic = weatherNow + 1000;
292 char diagnostic[768];
293 sprintf_s(diagnostic, sizeof diagnostic,
294 "WEATHER sample settling=%d pendingReset=%d terrainReady=%d terrainPending=%d mslKm=%.6f aglKm=%.6f "
295 "surfaceTargetKm=%.6f surfaceSmoothKm=%.6f ceilingTargetKm=%.6f ceilingSmoothKm=%.6f "
296 "nominalBaseMslKm=%.6f renderedBaseMslKm=%.6f bclKm=%.6f "
297 "visibilityTargetKm=%.6f visibilitySmoothKm=%.6f visibilityKm=%.6f "
298 "cloudActivity=%.6f cloudMapBlend=%.6f",
304 logger->Log(diagnostic);
305 }
306
307 // Inside cloud in-cloud adjustment of turbidity
308 f_temp = RiseMath::Max(f_ACL, f_BCL);
309
310
311 if (f_temp <= 0.0f) // in cloud
312 {
313 viewscreen->alphascreen.a = 0.0f; // no visibility
314 }
315 else if (f_temp > 0.0f && f_temp <= 0.05f) // Failsafe transition zone 50m
316 {
317 // take existing smooth value and modulate it (and the target) forceable to 0
318 viewscreen->alphascreen.a = f_temp / 0.05f;
319 }
320 else // above or below the transition area
321 {
322 viewscreen->alphascreen.a = 1.0f;
323 }
326 // this gets inversed down below
327
328
329
330
331 // wind direction smoothing =========================
332 // 350 - 010 = 340 ... if > RiseMath::Pi then we go DOWN
333 // 010 - 350 = -340 ... if < -RiseMath::Pi then we go UP
334 // 240 - 220 = 20 // we go up
335 // 220 - 240 = -20
336 const float winddiff = winddir - smoothwinddir; // radians
337 if (winddiff > RiseMath::Pi)
338 {
340 if (smoothwinddir < 0)
342 }
343 else if (winddiff < -RiseMath::Pi)
344 {
348 }
349 else if (fabsf(winddiff) > shearRate)
350 smoothwinddir += shearRate * copysignf(1.0f, winddiff);
351 else
353
354 const float windspeeddiff = windspeed - smoothwindspeed;
355 if (fabsf(windspeeddiff) > shearRate)
356 smoothwindspeed += shearRate * copysignf(1.0f, windspeeddiff);
357 else
359
360 logger->AddToCallStack("TemperatureSmoothingDiff");
361
362 // temperature and winds above 63km
363 const float whereWeThinkWeLeaveOffAt63 = -27.89f;
364 if (playerships[0].mslKm >= 63.0f && playerships[0].mslKm < 80.0f) // server stops sending updates at 63km ... added this filler 5/23/2018
365 {
366 //63km to 80km we are losing 4.12 per km
367 temperature = whereWeThinkWeLeaveOffAt63 - (playerships[0].mslKm - 63.0f) * 4.12f;
368 SetWindspeedKms(0.0f);
369 }
370 else if (playerships[0].mslKm >= 80.0f && playerships[0].mslKm < 90.0f)
371 {
372 //80km to 90km constant
373 temperature = whereWeThinkWeLeaveOffAt63 - 70.0f;
374 SetWindspeedKms(0.0f);
375 }
376 else if (playerships[0].mslKm >= 90.0f) // thermosphere
377 {
379 temperature = 1006.115f - 1097.39779f / (1.0f + powf(playerships[0].mslKm / 179.8561f, 9.161937f));
380 SetWindspeedKms(0.0f);
381 }
382
383 // == Temperature Smoothing ==
384 const float tempdiff = temperature - smoothTemperature;
385 smoothTemperature += tempdiff * fElapsedTime * 0.1f;
386
387 const float snowStartTemp = -1.0f; // full snow below this
388 const float snowEndTemp = 2.0f; // full rain above this
389 if (smoothTemperature <= snowStartTemp)
390 snowBlend = 1.0f; // full snow
391 else if (smoothTemperature >= snowEndTemp)
392 snowBlend = 0.0f; // full rain
393 else
394 snowBlend = (snowEndTemp - smoothTemperature) / (snowEndTemp - snowStartTemp); // 0.0 to 1.0
395
396
397
398
399 //char msg[999], msg2[99];
400 //sprintf_s(msg, sizeof msg, "g_bAboveClouds %i ", g_bAboveClouds ? 1 : 0);
401
402
403
404 // Rain not only reduces visibility but should lower light level because of build up overhead from convection
405 // https://jira.risetvp.com/view.php?id=422
406 // Precip is 2-16 BCL at 16 (heaviest rain) I would imagine half the light level, 2 is 100%
407 // brightness factor: 1.0 at I=2, 0.58 at I=16
408 float precipAttenuation = 1.0f - (0.03f - 0.015f * snowBlend) * (GetPrecip() - 2.0f);
409 //sprintf_s(msg2, sizeof msg2, "precip %.1f ", GetPrecip());
410 //strcat_s(msg, sizeof msg, msg2);
411
412 // so at precip 2 we get sqrt(1)=1 * .5 is .5 + .5 is 1, perfecto
413 // so at precip 16 we get sqrt(0)=0 * .5 is 0 + .5 is .5, perfecto
414 // so at precip 9 we get sqrtf(.5)=.707 * .5 is .353 is .8535, perfecto
415 // so at precip 3 we get sqrt(0.9286)=0.96363893653172815327029561361547*.5=0.48181946826586407663514780680774+.5=.982, perfecto
416
417 float thicknessAboveKm;
418 if (g_bAboveClouds)
419 {
420 if (f_ACL <= 0.0f) // In clouds
421 thicknessAboveKm = -f_ACL;// playerships[0].mslKm - cloudTopsMslC;
422 else
423 thicknessAboveKm = 0.0f;
424 }
425 else
426 {
427 if (f_BCL <= 0.0f) // In clouds
428 thicknessAboveKm = cloudThickness + f_BCL;
429 else // Below the lower layer
430 thicknessAboveKm = cloudThickness;
431 }
432
433 RiseMath::Color bcllight, top = sunColorC * SunAttenuation(), bottom = RiseMath::Color(0.07843137254901960784313725490196f, 0.11764705882352941176470588235294f, 0.1960784313725490196078431372549f, 0.11498588f); // 10km worth of clouds
434 RiseMath::ColorLerp(&bcllight, &top, &bottom, Clamp(thicknessAboveKm / 10.0f,0.f,1.f));
435
436
437 // Illumination under clouds --------------------------------------------------------------------
438 bcllight *= RiseMath::Max(elevation, 0.05f) * precipAttenuation; // Don't want them to get turned off because they can't see ANYTHING
440 {
441 const auto p=-playerships[0].position;
442 const float transmission=CloudVolume::DiffuseSunTransmission({p.x,p.y,p.z},
443 {-Xsunlight.x,-Xsunlight.y,-Xsunlight.z},cloudParameters,viewscreen->cloudVolume.Seed());
444 // Share the shader's solar column. Cached rain must not darken an
445 // exposed top after the observer has climbed out of the cloud.
446 const float localSun=Clamp(RiseMath::Vec3Dot(&playerships[0].position,&Xsunlight)/RiseMath::Vec3Length(&playerships[0].position),0.f,1.f);
447 const float incident=expf(-.5f*expf(-cloudParameters.top/ScaleHeightC));
448 const RiseMath::Color incoming=sunColorC*incident;
449 // Object illumination receives scattered sunlight, never cloud airglow.
450 // Retain the legacy faint night-visibility floor without green emission.
451 const auto scattered=CloudVolume::ScatteredSunlight({incoming.r,incoming.g,incoming.b},RiseMath::Max(localSun,.05f),transmission);
452 // Alpha carries the day/night control used by building and runway light
453 // maps via (1-alpha)^2. Replacing it with opacity 1 disables those lights.
454 bcllight=RiseMath::Color(scattered.x,scattered.y,scattered.z,bcllight.a);
455 }
456
457
458 // Only the solar contribution is eclipsed. Local lights, fireworks,
459 // lightning, instrument emission and the airglow model remain independent.
460 bcllight *= solarVisibility;
461
462 // desaturate because of rain
463 float luma = 0.2126f * bcllight.r + 0.7152f * bcllight.g + 0.0722f * bcllight.b;
465 // the gray color of equal brightness
466 RiseMath::Color gray = RiseMath::Color(luma, luma, luma, bcllight.a);
467 float desatAmount = precipAttenuation * (1.0f - 0.5f * snowBlend); // less for snow
468 RiseMath::ColorLerp(&bcllight, &gray, &bcllight, desatAmount);
469
470
471
472 //sprintf_s(msg2, sizeof msg2, "bcllight r %.1f g %.1f b %.1f a %.1f ", bcllight.r, bcllight.g, bcllight.b, bcllight.a);
473 //strcat_s(msg, sizeof msg, msg2);
474 //static float timetrack = 0;
475 //timetrack += fElapsedTime;
476 //if (timetrack > 0.5f)
477 //{
478 // logger->Log(msg);
479 // timetrack -= 0.5f;
480 //}
481
482
483 float nightVisionFlashStimulus = 0.0f;
485 {
486 lightningbelow.Update(fElapsedTime);
487 }
488
489
490 // All lighting reads the final pulse used by the bolt and cloud renderer.
492 playerships[0].reference != REF_WINDOWLESS && f_ACL < .150f)
493 {
494 const auto delta=(lightningbelow.groundpos+lightningbelow.cloudpos)*.5f-playerships[0].position;
495 const float distanceSquared=RiseMath::Vec3Dot(&delta,&delta);
497 *64.f/(64.f+distanceSquared)*expf(-sqrtf(distanceSquared)/RiseMath::Max(.25f,fFogEndHorizon));
498 }
499
500 // Image intensifiers cannot instantly adapt to a lightning flash. Saturate the
501 // NVG image during the burst, then let the simulated sensor recover gradually.
502 const bool nightVisionActive = viewscreen->InventoryItemEffectsEnabled() &&
505 // Entering the simulator also clears any real-flight flash afterimage.
506 NightVisionExposure::Update(nightVisionActive && !playerships[0].isSimulator, nightVisionFlashStimulus, luma, fElapsedTime,
508
509
510 // Fireworks
511 if (f_ACL < 0.150f)
512 {
513 float r = 0.0f, g = 0.0f, b = 0.0f, avg = 0.0f;
514 for (t = 0; t < fireworksC; t++)
515 {
516 if (fireworks[t].inuse)
517 {
518 result = -viewscreen->position - fireworks[t].position;
519 f_temp = RiseMath::Vec3Length(&result) / 20.0f;
520 if (f_temp <= 1.0f)
521 {
522 f_temp = sqrtf(1.0f - f_temp) * 0.15f;
523 // in addition it depends on where it is in the sequence
524 // like dark light dark
525 if (fireworks[t].type == 0)
526 f_temp *= sinf(RiseMath::Pi * static_cast<float>(fireworks[t].texture) / (firework1C - 1));
527 else if (fireworks[t].type == 1)
528 f_temp *= sinf(RiseMath::Pi * static_cast<float>(fireworks[t].texture) / (firework2C - 1));
529 else
530 f_temp *= sinf(RiseMath::Pi * static_cast<float>(fireworks[t].texture) / (firework3C - 1));
531 r += fireworks[t].color.r * f_temp;
532 g += fireworks[t].color.g * f_temp;
533 b += fireworks[t].color.b * f_temp;
534 avg++;
535 }
536 }
537 }
538 if (avg > 0.0f)
539 {
540 bcllight.r += r / avg;
541 if (bcllight.r > 1.0f)
542 bcllight.r = 1.0f;
543 bcllight.g += g / avg;
544 if (bcllight.g > 1.0f)
545 bcllight.g = 1.0f;
546 bcllight.b += b / avg;
547 if (bcllight.b > 1.0f)
548 bcllight.b = 1.0f;
549 }
550 }
551
552 // Color night vision amplifies the scene lighting itself instead of placing a
553 // bright overlay over the finished frame. Gain fades out as the available
554 // light approaches normal daytime levels, avoiding a daytime whitewash.
555 // Recompute even when inactive: equipment/camera/simulator transitions must
556 // never retain a previous frame's enhanced exterior response.
557 luma = 0.2126f * bcllight.r + 0.7152f * bcllight.g + 0.0722f * bcllight.b;
558 cockpitVision = NightVisionGain::Calculate(nightVisionActive, playerships[0].isSimulator, luma);
559 const auto& nvgGain = cockpitVision;
560 nightVisionCloudGain = nvgGain.clouds
561 ? RiseMath::Vector4(nvgGain.red,nvgGain.green,nvgGain.blue,1)
562 : RiseMath::Vector4(1,1,1,0);
563 const RiseMath::Color unassistedCloudLight=bcllight;
564 cockpitRawCloudLight=unassistedCloudLight;
565 if (nightVisionActive)
566 {
567 bcllight.r = Clamp(bcllight.r * nvgGain.red, 0.0f, 1.0f);
568 bcllight.g = Clamp(bcllight.g * nvgGain.green, 0.0f, 1.0f);
569 bcllight.b = Clamp(bcllight.b * nvgGain.blue, 0.0f, 1.0f);
570 }
571
572
573 // Azimuth and zenith color calculation --------------------------------------------------------------------
574 float atmosphericSun = viewscreen->ProbeBoundSphere(&playerships[0].position, &Xsunlight);
576 {
577 const auto from=-playerships[0].position;
578 const auto to=from-Xsunlight*(radiusC*3);
579 atmosphericSun*=CloudVolume::Transmittance({from.x,from.y,from.z},{to.x,to.y,to.z},
581 }
582 shadow = atmosphericSun * solarVisibility;
584 {
585 float effElev = Lerp(elevation, 1.0f, atmosphericSun);
586 solarHorizon = SampleColorGradient(effElev, aStops);
588
590 colorzenith.r = test.r;
591 colorzenith.g = test.g;
592 colorzenith.b = test.b;
593 }
594 // Azimuth and zenith color calculation --------------------------------------------------------------------
595
596
597 // The diffuse light through clouds on city and ground (if normals were available)
598 viewscreen->sunlight.Diffuse = bcllight;
599
600
601 // Inverse
603
604 // Illumination under clouds --------------------------------------------------------------------
605
606
607 // Vessel illumination --------------------------------------------------------------------------
608 RiseMath::Color shiplight;
609
610 // Start with exterior hull illumination
611 shiplight.r = 0; shiplight.g = 0; shiplight.b = 0; // zeroed out 5/27/2018 looks like Ian is adding hull lights to models now
612
613 int index = 0;
614 if (playerships[0].reference == REF_INANOTHER)
615 index = playerships[0].inarray;
616 if (playerships[index].logolight)
617 {
618 // so this has revealed that it isn't a simple "max" between two lights...
619 // it is additive, 2 flashlights shining on the same spot doubles the brightness
620 // problem is we have a finite limit to the brightness unless we go to HDR
621 const short temptype = playerships[index].VB;
622 for (s = 0; s < static_cast<short>(polyobjects[temptype].effects.size()); s++)
623 {
624 const s_light_effect effect = polyobjects[temptype].effects.at(s);
625 if (effect.sequencing & playerships[index].compare)
626 {
627 if (effect.power == 2.0f)
628 {
629 if (!playerships[index].headlight)
630 continue;
631 f_temp = 0.025f;
632 }
633 else if (effect.power == 1.5f) // rotating lights
634 {
635 continue;
636 //if (playerships[index].type == VehicleType::P13)
637 //{
638 // if (!playerships[index].police || !playerships[index].specialight)
639 // continue;
640 //}
641 }
642 else if (effect.power == 0.5f) // strobe
643 f_temp = 0.075f;
644 else
645 f_temp = 0.05f; // needs to be set or continue!!
646
647 shiplight.r += effect.diffuse.r * f_temp;
648 shiplight.g += effect.diffuse.g * f_temp;
649 shiplight.b += effect.diffuse.b * f_temp;
650 }
651 }
652 if (index == 0)
653 shiplight *= ourcockpit.power;
654 else if (playerships[0].reference == REF_INANOTHER && !viewscreen->camera->outside)
655 shiplight *= playerships[index].baydoorextent;
656
657 shiplight *= sqrtf(playerships[index].bound / 0.037208f);
658 }
659
660 if (!playerships[0].isSimulator)
661 {
663 shiplightCloudOpacity = viewscreen->alphascreen.a; // Legacy local cloud opacity.
664 else if (index != 0)
665 {
666 // Scattering belongs to the lamp source, independently of camera position.
667 const auto p = -playerships[index].position;
668 const auto medium = CloudVolume::SampleMedium({p.x,p.y,p.z},cloudParameters,viewscreen->cloudVolume.Seed());
669 shiplightCloudOpacity = 1.f-expf(-medium.extinction*CloudVolume::ShiplightScatterDistanceKm);
670 }
672 GetVisibilityKm(),shiplightCloudOpacity);
673 }
674
675 RiseMath::Vector4 shipdiff;
676 shipdiff.x = shiplight.r; shipdiff.y = shiplight.g; shipdiff.z = shiplight.b; shipdiff.w = 0; // unused but could be viewscreen->alphascreen.a;
677 // ReSharper disable once CppJoinDeclarationAndAssignment
678 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("shiplight", &shipdiff));
679
680 // Reflection of our light
681 f_temp = sqrtf(bcllight.r * bcllight.r + bcllight.g * bcllight.g + bcllight.b * bcllight.b);
682 if (f_temp > 1.0f)
683 f_temp = 1.0f;
684 f_temp = (1.0f - f_temp) * 0.5f;
685
686 // Vessel illumination --------------------------------------------------------------------------
687
688
689
690 // Airglow colors the visible medium, not the light illuminating objects.
691 // Keep fog, the clear background and cloud-base average on this same RGB.
692 RiseMath::Color cloudFog=bcllight;
694 {
695 const auto p=-playerships[0].position;
696 const float sunCosine=RiseMath::Vec3Dot(&playerships[0].position,&Xsunlight)/RiseMath::Vec3Length(&playerships[0].position);
697 const auto column=CloudVolume::Boundaries({p.x,p.y,p.z},cloudParameters,viewscreen->cloudVolume.Seed());
698 // Clouds meter their visible airglow as well as scattered ambient.
699 // Keep the object/cockpit meter separate: airglow is not cabin lighting.
700 const auto optics=CloudNightVision::Evaluate(nightVisionActive,playerships[0].isSimulator,
701 {unassistedCloudLight.r,unassistedCloudLight.g,unassistedCloudLight.b},{.125f,.375f,.25f},
702 sunCosine,playerships[0].mslKm,column.base,column.top);
703 cloudFog=RiseMath::Color(optics.fog.x,optics.fog.y,optics.fog.z,1);
704 nightVisionCloudGain=optics.gain.clouds
705 ? RiseMath::Vector4(optics.gain.red,optics.gain.green,optics.gain.blue,1)
706 : RiseMath::Vector4(1,1,1,0);
707 }
708 // Find our alphascreen color (that is the windshield)
709 if (viewscreen->VolumeCloudsEnabled() || f_ACL <= 0.150f)
710 {
711 f_temp *= 1.0f - Clamp(sqrtf(fFogEndHorizon / 0.4f), 0, 1);
712 viewscreen->alphascreen.r = Clamp(cloudFog.r + f_temp * shiplight.r, 0, 1);
713 viewscreen->alphascreen.g = Clamp(cloudFog.g + f_temp * shiplight.g, 0, 1);
714 viewscreen->alphascreen.b = Clamp(cloudFog.b + f_temp * shiplight.b, 0, 1);
715 }
716
717
718 // Find our betascreen color (that is the full screen quad for flare)
719 // Reduce visibility by 1/2 when sun in view (flare)
721 if (glare > 0.0f)
722 {
723 f_temp = glare * Clamp(sqrtf(fFogEndHorizon / 0.4f), 0, 1);
724 betascreen = sunColorC * f_temp;
725 betascreen.a = betascreen.a * 0.5f;
726 }
727 else
728 {
730 }
731
732 // sunlightcolor vs. sunappearance
733 // normalized constants
734 const RiseMath::Color SUN_CLEAR_COLOR = RiseMath::Color(0xFFFFFFFF);
735 const RiseMath::Color SUN_HORIZON_COLOR = RiseMath::Color(0xFFFF7326);
736 // An eclipse masks the disk; it does not turn the surviving crescent orange.
737 RiseMath::ColorLerp(&sunAppearance, &SUN_HORIZON_COLOR, &SUN_CLEAR_COLOR, atmosphericSun);
738
739
740 // Fog calculation routines --------------------------------------------------------------
741
742 // Horizon and Zenith -------------------------------------------------------------------------
743 dwFogColorHorizon = cloudFog;
744
745
746
747
748 // Ambient light scattered by the atmosphere
749// scatter.r=r/714.0f; scatter.g=g/714.0f; scatter.b=b/714.0f; // Based on middle radius sunmap.bmp
750
751
752 cloudHorizonAngle = RiseMath::HalfPi - acosf(Clamp(cloudTopsRadiusC / (playerships[0].mslKm + radiusC), -1.f, 1.f));
753 cloudHorizonDistance = cloudTopsRadiusC / tanf(cloudHorizonAngle); // distance to horizon 1b or 2c
754 if (cloudHorizonDistance < 256.0f)
755 cloudHorizonDistance = 256.0f;
756
757
758 // here is where we will play with the visibility 10m to 400m in the clouds
759 if (viewscreen->alphascreen.a > 0 &&
761 {
763 {
764 // Cloud extinction is integrated to the actual scene surface by
765 // the volume pass. World fog contains only the clear-air atmosphere.
767 }
768 else
769 {
770 const float base = GetNormalizedPrecip(); // 0..1
771 const float gate = 0.25f + 0.75f * base;
772
773 const float turbVisMod = Clamp(viewscreen->turbEnergy * 0.25f, 0.0f, 0.25f) * gate;
774 const float densityWave = viewscreen->turbLow * turbVisMod;
775
776 cloudVisTarget1 = Clamp(base + densityWave, 0.0f, 1.0f);
777
778 // THEN smooth toward it
780 {
781 cloudVisSmooth1 += RiseMath::Max(viewscreen->UniverseRelativeSpeedKms, 0.001f) * fElapsedTime * 8.0f;
784 }
786 {
787 cloudVisSmooth1 -= RiseMath::Max(viewscreen->UniverseRelativeSpeedKms, 0.001f) * fElapsedTime * 8.0f;
790 }
791
792 // Legacy visibility ranges from 400 meters down to 10 meters.
794 }
795 }
796 else
798
799
800 if (alphascreenOverride == 1.0f)
801 {
802 if (playerships[0].reference != REF_INANOTHER || playerships[playerships[0].inarray].baydoor)
803 fFogEndHorizon = 0.400f;
804 else
805 fFogEndHorizon = 42.16f;
807 }
808 else if (alphascreenOverride == 0.0f)
809 {
810 fFogEndHorizon = 42.16f;
812 }
813
814
816 {
819 f_temp *= (elevation + 0.09f) / 0.09f; // Time of day adjustment
820 if (elevation <= -0.09f)
821 f_temp *= 0.01f; // A night floor must not restore atmosphere in space.
822
823 colorzenith.a = f_temp;
824 // for static stars, Iomere, sun blend
825 RiseMath::ColorLerp(&colorzenith, &colorzenith, &viewscreen->alphascreen,
827 dwFogFactorZenith = colorzenith;
828
829 colorzenith.a = 1.0f;
830 colorzenith.r *= dwFogFactorZenith.a;
831 colorzenith.g *= dwFogFactorZenith.a;
832 colorzenith.b *= dwFogFactorZenith.a;
833 // for skyring and Iomere and ambient darkness
834 dwFogColorZenith = colorzenith;
835 }
836 else
837 {
839 }
840
841 const auto fill = CloudVolume::VehicleAmbient({bcllight.r,bcllight.g,bcllight.b},
843 vehicleAmbient = RiseMath::Color(fill.x,fill.y,fill.z,1);
844 const auto cockpitFill = CockpitLighting::Ambient({bcllight.r,bcllight.g,bcllight.b},
846 cockpitAmbient = RiseMath::Color(cockpitFill.x,cockpitFill.y,cockpitFill.z,1);
847 const auto rawFill = CloudVolume::VehicleAmbient({unassistedCloudLight.r,unassistedCloudLight.g,unassistedCloudLight.b},
849 cockpitRawAmbient = RiseMath::Color(rawFill.x,rawFill.y,rawFill.z,1);
850
851 // End of fog calculations ----------------------------------------------------------------------
852
853 logger->AddToCallStack("weather::FrameMove END");
854}
855
857{
858 // comes in 0-6.282
859 winddir = prmWinddir;
860 if (smoothwinddir == -1.0f)
861 {
863 char msg[99];
864 sprintf_s(msg, 99, "Weather1 initialized smoothwinddir: %.1f", smoothwinddir);
865 logger->Log(msg);
866 }
867}
868
869void weather::SetTemperatureCelsius(float prmTemperature)
870{
871 temperature = prmTemperature;
872 if (smoothTemperature == -1.0f)
873 {
875 char msg[99];
876 sprintf_s(msg, 99, "Weather1 initialized smoothTemperature: %.1f", smoothTemperature);
877 logger->Log(msg);
878 }
879}
880
881void weather::SetWindspeedKms(float prmWindspeed)
882{
883 windspeed = prmWindspeed;
884 if (smoothwindspeed == -1.0f)
885 {
887 char msg[99];
888 sprintf_s(msg, 99, "Weather1 initialized smoothwindspeed: %.1f", smoothwindspeed);
889 logger->Log(msg);
890 }
891}
892
893void weather::SetPrecip(float prmPrecip)
894{
895 precip = prmPrecip;
896 if (smoothPrecip == -1.0f)
897 {
899 char msg[99];
900 sprintf_s(msg, 99, "Weather initialized smoothPrecipitation: %.1f", smoothPrecip);
901 logger->Log(msg);
902 }
903}
904
906{
907 // Local particle/glass test only; live weather and its smoother keep running.
908 precipOverride = value;
909}
910
917
919{
920 // Keep receiving live visibility while the local test override is active.
921 visibilityOverrideKm = value;
922 if (value == -1.0f)
924}
925
926void weather::SetVisibility(float prmVisibility)
927{
928 visibility = prmVisibility;
929 if (smoothVisibility == -1.0f)
930 {
932 char msg[99];
933 sprintf_s(msg, 99, "Weather initialized smoothVisibility: %.1f", smoothVisibility);
934 logger->Log(msg);
935 }
936}
937
938void weather::SetCloudSurfaceTargetKm(float prmCloudSurfaceTargetKm)
939{
940 cloudSurfaceTargetKm = prmCloudSurfaceTargetKm;
941 if (cloudSurfaceSmoothKm == -1.0f)
942 {
944 char msg[99];
945 sprintf_s(msg, 99, "Weather initialized cloudSurfaceSmoothKm: %.1f", cloudSurfaceSmoothKm);
946 logger->Log(msg);
947 }
948}
949
950void weather::SetCloudCeilingTargetKm(float prmCloudCeilingTargetKm)
951{
952 cloudCeilingTargetKm = prmCloudCeilingTargetKm;
953 if (cloudCeilingSmoothAglKm == -1.0f)
954 {
956 char msg[99];
957 sprintf_s(msg, 99, "Weather initialized cloudCeilingSmoothAglKm: %.1f", cloudCeilingSmoothAglKm);
958 logger->Log(msg);
959 }
960}
961
966
968{
969 RiseMath::Matrix rotation;
970 const auto axis=-viewscreen->posnorml;
974 wind*=GetWindspeedKms();
975 return {wind.x,wind.y,wind.z};
976}
977
979{
980 if(playerships[0].isSimulator || g_bAboveClouds || plotWeatherSuspended ||
982 {spatialFogWeather.Reset();return;}
983 const auto& header=plotWeather.Header();
984 const uint64_t revision=(uint64_t(header.requestToken)<<32)|header.revision;
985 if(spatialFogWeather.SourceRevision()==revision)return;
986 auto field=std::make_shared<SpatialFogWeather::Grid>();
987 field->cube=header.cube;field->u=header.tcp.u;field->v=header.tcp.v;field->revision=revision;
988 for(int y=0;y<64;++y)for(int x=0;x<64;++x)
989 {
990 const VECTOR2SHORT at(short(header.tcp.u+x-31),short(header.tcp.v+y-31));
991 const auto* sample=plotWeather.At(header.cube,at,header.requestToken);
992 if(sample && sample->HasVisibility())
993 field->cells[y*64+x]={sample->visibility*.001f,sample->precipitation*.1f};
994 }
995 spatialFogWeather.Accept(std::move(field),full);
996}
997
998void weather::AdvanceSpatialFog(float elapsed)
999{
1001 if(!spatialFogWeather.Ready())return;
1002 const auto wind=ObservedWindKms();
1003 const auto position=playerships[0].position;
1004 spatialFogWeather.Advance(elapsed,{position.x,position.y,position.z},{wind.x,wind.y,wind.z});
1005}
1006
1007// Independent weather delivery never changes the terrain grid.
1009{
1012 // A reconnect can reuse the server revision and request token before a
1013 // render frame sees the empty store. Invalidate the GPU generation now.
1014 spatialFogRendering=false;
1020 plotWeatherSuspended = false;
1024 weatherRequestQueued = true;
1025 weatherPending = true;
1026}
1027
1029{
1030 // Follow the existing >10 km / <9.5 km hysteresis, including simulator flight.
1031 if (g_bAboveClouds)
1032 {
1034 {
1035 plotWeatherSuspended = true;
1039 weatherRequestQueued = false;
1040 }
1041 return false;
1042 }
1044 {
1045 plotWeatherSuspended = false;
1046 // A new token rejects both pre-ascent packets and a server's unsolicited
1047 // descent full. Normal descent never arms a smoothing reset.
1048 RequestPlotWeather(false);
1049 }
1050 return true;
1051}
1052
1054{
1055 weatherRequestToken = static_cast<uint16_t>(weatherRequestToken + 1);
1056 weatherRequestQueued = true;
1058}
1059
1068
1069void weather::ReceivePlotWeather(const unsigned char* bytes, size_t length)
1070{
1071 SPlotWeatherHeader header;
1072 if (!PlotWeather::ParseHeader(bytes, length, header)) return;
1073 const bool belowClouds = UpdatePlotWeatherAltitude();
1074 if (!belowClouds) return; // no decoding/application or repair requests aloft
1075 const auto result = plotWeather.Accept(bytes, length, weatherRequestToken);
1076 if (result == PlotWeather::Result::NeedFull)
1077 RequestPlotWeather(false); // preserve smoothers during transport repair
1078 else if (result == PlotWeather::Result::Full || result == PlotWeather::Result::Row)
1079 {
1082 }
1083}
1084
1086{
1087 if (!UpdatePlotWeatherAltitude()) return;
1089 {
1090 SClientPacket packet{};
1092 packet.f_x = weatherRequestToken;
1093 packet.f_y = packet.f_z = packet.f_w = 0;
1094 viewscreen->gameclass->networking->SendToServer(&packet, sizeof packet, true, ORDERING_WEATHER);
1095 weatherRequestQueued = false;
1096 }
1097 const char cube = viewscreen->CalculateCube(playerships[0].position);
1098 double u, v;
1100 float surfaceMeters;
1101 if (!PlotWeather::Coordinates(playerships[0].position, cube, u, v)
1102 || !plotWeather.Interpolate(cube, u, v, weatherRequestToken, sample)
1103 || !viewscreen->ptrGrid->InterpolateElevation(cube, u, v, surfaceMeters)) return;
1104 SetCloudSurfaceTargetKm(surfaceMeters * .001f);
1105 SetCloudCeilingTargetKm(sample.ceilingMeters * .001f);
1106 SetVisibility(sample.visibilityMeters * .001f);
1107 SetPrecip(sample.precipitation);
1108 // Weather1 supplies altitude-specific wind and temperature. Grid wind remains surface data;
1109 // turbulence samples these grids independently.
1110 if (weatherPending)
1111 {
1113 weatherPending = false;
1114 weatherDiagnosticUntil = GetTickCount64() + 30000;
1116 }
1117}
1118
1119
1121{
1123 || plotWeather.Header().requestToken != weatherRequestToken) return false;
1124 const char cube = viewscreen->CalculateCube(playerships[0].position);
1125 const auto tcp = viewscreen->CalculateCGC(playerships[0].position,cube);
1126 if (!plotWeather.At(cube,tcp,weatherRequestToken)) return false;
1127 const auto& header = plotWeather.Header();
1128 const auto terrainRevision = viewscreen->ptrGrid->ElevationRevision();
1129 if (lightningWeatherRevision == header.revision && lightningTerrainRevision == terrainRevision) return true;
1130 std::vector<GridLightning::Cell> cells;
1131 cells.reserve(4096);
1132 for (int q=0;q<64;++q) for (int r=0;r<64;++r)
1133 {
1134 const VECTOR2SHORT source(header.tcp.u+q-31,header.tcp.v+r-31);
1135 const auto* sample = plotWeather.At(header.cube,source,weatherRequestToken);
1136 if (!sample || !sample->HasVisibility() || sample->ceiling<=0) continue;
1137 short elevation;
1138 if (!viewscreen->ptrGrid->TryElevation(header.cube,source.u,source.v,elevation)) continue;
1139 const float surface=elevation*.001f, base=surface+sample->ceiling*.001f;
1140 if (base>=cloudTopsMslC) continue; // no exposed below-deck channel
1141 char rotation;
1142 const auto canonical=viewscreen->CalculateWrap(source.u,source.v,header.cube,&rotation);
1143 if (canonical.u==30000 || canonical.v==30000) continue;
1144 const auto normal=viewscreen->CalculatePlanar(canonical.u,canonical.v);
1145 if (RiseMath::Vec3LengthSq(&normal)<.5f) continue;
1146 const float dominant=(std::max)({fabsf(normal.x),fabsf(normal.y),fabsf(normal.z)});
1148 cell.u=canonical.u; cell.v=canonical.v;
1149 cell.ground=normal*(radiusC+surface);
1150 cell.cloud=normal*(radiusC+base);
1151 cell.precipitation=sample->precipitation*.1f;
1152 cell.area=dominant*dominant*dominant; // cube-projection area Jacobian
1153 cells.push_back(cell);
1154 }
1155 gridLightning.SetCells(std::move(cells));
1156 lightningWeatherRevision=header.revision;
1157 lightningTerrainRevision=terrainRevision;
1158 return true;
1159}
1160
1162{
1163 if (playerships[0].isSimulator || playerships[0].reference==REF_WINDOWLESS
1164 || playerships[0].mslKm>=cloudTopsMslC) return false;
1165 if (!RefreshLightningGrid())
1166 {
1167 logger->Log("BOLT: waiting for a current weather grid.");
1168 return false;
1169 }
1170 RiseMath::Matrix inverse;
1171 if (!RiseMath::MatrixInverse(&inverse,nullptr,&viewscreen->matrixLook)) return false;
1172 // Rendering uses negated planet coordinates. Camera -Z is therefore +Z
1173 // in the terrain coordinate system; include the external/head camera offset.
1174 const auto eye=playerships[0].position-RiseMath::Vector3(inverse._41,inverse._42,inverse._43);
1176 RiseMath::Vec3Normalize(&up,&eye);
1177 auto forward=RiseMath::Vector3(inverse._31,inverse._32,inverse._33);
1178 forward-=up*RiseMath::Vec3Dot(&forward,&up);
1179 if (RiseMath::Vec3LengthSq(&forward)<1e-6f)
1180 {
1181 forward=RiseMath::Vector3(-inverse._21,-inverse._22,-inverse._23);
1182 forward-=up*RiseMath::Vec3Dot(&forward,&up);
1183 }
1184 RiseMath::Vec3Normalize(&forward,&forward);
1185 auto normal=eye+forward; // one kilometre horizontally ahead, before terrain projection
1186 RiseMath::Vec3Normalize(&normal,&normal);
1187 const char cube=viewscreen->CalculateCube(normal);
1188 double u,v;float surfaceMeters;
1189 if (!PlotWeather::Coordinates(normal,cube,u,v)
1190 || !viewscreen->ptrGrid->InterpolateElevation(cube,u,v,surfaceMeters))
1191 {
1192 logger->Log("BOLT: waiting for terrain 1 km ahead of the camera.");
1193 return false;
1194 }
1195 float ceilingKm=GetCloudCeilingKm();
1197 {
1199 if (!plotWeather.Interpolate(cube,u,v,weatherRequestToken,sample)) return false;
1200 ceilingKm=sample.ceilingMeters*.001f;
1201 }
1202 const float surfaceKm=surfaceMeters*.001f;
1203 if (!std::isfinite(ceilingKm) || ceilingKm<=0 || surfaceKm+ceilingKm>=cloudTopsMslC) return false;
1204 const auto ground=normal*(radiusC+surfaceKm),cloud=normal*(radiusC+surfaceKm+ceilingKm);
1205 const float distance=GridLightning::Distance(ground,playerships[0].position);
1206 // Exact sub-cell placement is local, like RAIN/VIS. A grid broadcast would
1207 // snap it to a plot corner and its echo could replace this visible strike.
1208 const int seed=rand(),chains=rand()%(LightningTiming::MaxChainedBolts+1);
1209 viewscreen->TriggerBCLLightningAt(ground,cloud,distance,seed,chains,true);
1210 logger->Log("BOLT: local connected lightning ending at ground 1 km ahead of the camera.");
1211 return true;
1212}
1213
1214void weather::ReceiveGridLightning(short u, short v, int seed, int chainedBolts)
1215{
1216 if (playerships[0].isSimulator || playerships[0].mslKm>=cloudTopsMslC || !RefreshLightningGrid()) return;
1217 const auto* cell=gridLightning.Find(u,v);
1218 if (!cell) return;
1219 const float distance=GridLightning::Distance(cell->ground,playerships[0].position);
1220 if (distance>=GridLightning::RadiusKm) return;
1221 gridLightning.Observe(cell->ground); // include other clients' strikes in local cooldowns
1222 viewscreen->TriggerBCLLightningAt(cell->ground,cell->cloud,distance,seed,chainedBolts);
1223}
1224
1226{
1227 if (playerships[0].isSimulator || playerships[0].mslKm>=cloudTopsMslC || !RefreshLightningGrid())
1228 {
1230 return;
1231 }
1234 snowBlend,GetTurbulence(),event))
1235 {
1236 SClientPacket packet{};
1237 packet.type=42; packet.f_x=event.cell.u; packet.f_y=event.cell.v;
1238 packet.f_z=float(event.chains); packet.f_w=float(event.seed);
1239 viewscreen->gameclass->networking->SendToServer(&packet,sizeof packet,true);
1240 }
1241}
1242
1248
1250{
1251 // The observer fade reaches zero at 9.5 km, before the 10 km suspension.
1252 // Descent must receive a fresh token before a new field can appear.
1253 if(playerships[0].isSimulator || !viewscreen->VolumeCloudsEnabled() ||
1255 {ResetCloudBaseWeather();return;}
1256 const auto& header=plotWeather.Header();
1257 const char cube=viewscreen->CalculateCube(playerships[0].position);
1258 const auto at=viewscreen->CalculateCGC(playerships[0].position,cube);
1259 const bool valid=!weatherPending && plotWeather.Ready() &&
1260 header.requestToken==weatherRequestToken && plotWeather.At(cube,at,weatherRequestToken);
1261 if(!valid)
1262 {
1264 }
1265 else
1266 {
1267 const auto terrainRevision=viewscreen->ptrGrid->ElevationRevision();
1268 if(!cloudBaseWeather.Current() || cloudBaseWeatherRevision!=header.revision ||
1269 cloudBaseRequestToken!=header.requestToken || cloudBaseTerrainRevision!=terrainRevision)
1270 {
1271 auto field=std::make_shared<CloudBaseWeather::Grid>();
1272 field->cube=header.cube;field->u=header.tcp.u;field->v=header.tcp.v;
1273 for(int y=0;y<64;++y)for(int x=0;x<64;++x)
1274 {
1275 const VECTOR2SHORT point(short(header.tcp.u+x-31),short(header.tcp.v+y-31));
1276 const auto* sample=plotWeather.At(header.cube,point,weatherRequestToken);
1277 short elevation;
1278 if(sample && sample->HasVisibility() && viewscreen->ptrGrid->TryElevation(header.cube,point.u,point.v,elevation))
1279 {
1280 // Preserve UpdateLocalWeather's existing normal ceiling
1281 // envelope; administrative BCL overrides use their old path.
1282 field->cells[y*64+x]={(std::min)(8.5f,(elevation+sample->ceiling)*.001f),
1283 sample->turbulence/255.f,1,0};
1284 }
1285 }
1286 field->Bounds();cloudBaseWeather.Target(std::move(field));
1287 cloudBaseWeatherRevision=header.revision;cloudBaseRequestToken=header.requestToken;
1288 cloudBaseTerrainRevision=terrainRevision;
1289 }
1290 }
1291 cloudBaseWeather.Advance(elapsed);
1294}
1295
1297{
1298 const auto& header=plotWeather.Header();
1299 const auto terrainRevision=viewscreen->ptrGrid->ElevationRevision();
1300 const bool valid=plotWeather.Ready() && header.requestToken==weatherRequestToken;
1301 if (snowTerrainRevision!=terrainRevision || (valid &&
1302 (snowWeatherRevision!=header.revision || snowRequestToken!=header.requestToken)))
1303 {
1305 if (valid) for(int q=0;q<64;++q) for(int r=0;r<64;++r) {
1306 const VECTOR2SHORT p(header.tcp.u+q-31,header.tcp.v+r-31);
1307 const auto* sample=plotWeather.At(header.cube,p,weatherRequestToken);
1308 if(!sample || !sample->HasVisibility())continue;
1309 char rotation;
1310 const auto canonical=viewscreen->CalculateWrap(p.u,p.v,header.cube,&rotation);
1311 if(canonical.u==30000 || canonical.v==30000)continue;
1312 terrainSnow.Target(canonical,*sample);
1313 }
1314 // Preserve loaded terrain just beyond a newly centered weather footprint.
1315 for(const auto& column:gridarray)for(const auto& cell:column)
1316 if(cell.elevationAvailable)terrainSnow.Retain(cell.tcp);
1317 terrainSnow.End();
1318 snowTerrainRevision=terrainRevision;
1319 if(valid){snowWeatherRevision=header.revision;snowRequestToken=header.requestToken;}
1320 }
1321 terrainSnow.Advance(elapsed);
1322}
1323
1325{
1326 if(u<0 || u>=64 || v<0 || v>=64) return {0,0,0,0};
1327 const auto& cell=gridarray[u][v];
1328 if(!cell.elevationAvailable)return {0,0,0,0};
1329 const auto* surface=terrainSnow.At(cell.tcp);
1330 // Polar coverage is visual only: never turn it into physical snow/water.
1331 const float latitude=RiseMath::ToDegree(atan2f(cell.position.z,
1332 sqrtf(cell.position.x*cell.position.x+cell.position.y*cell.position.y)));
1333 return TerrainSnow::Tint(surface?*surface:TerrainSnow::Surface{},latitude,orbitSunLatitude);
1334}
1335
1336// End independent weather source.
1337
1351
1353{
1354 if (!playerships[0].isSimulator && smoothwindspeed >= 0)
1355 return smoothwindspeed;
1357 return 0.0f;
1358}
1359
1364
1366{
1367 // Keep the held deck observation for descent; it is not aircraft rain aloft.
1368 if (g_bAboveClouds) return 2.f;
1369 if (!playerships[0].isSimulator && smoothPrecip >= 2)
1370 return smoothPrecip;
1372 return 2.0f;
1373}
1374
1375void weather::PrepareRainCurtains(bool exteriorView)
1376{
1378 double localU,localV;float localSurface;
1379 const char localCube=viewscreen->CalculateCube(playerships[0].position);
1383 PlotWeather::Coordinates(playerships[0].position,localCube,localU,localV) &&
1385 viewscreen->ptrGrid->InterpolateElevation(localCube,localU,localV,localSurface);
1387 if(!spatialFogRendering){renderer->SetRainGrid(nullptr);return;}
1388 const auto& header=plotWeather.Header();
1389 const uint64_t revision=spatialFogWeather.Generation();
1390 const auto terrainRevision=viewscreen->ptrGrid->ElevationRevision();
1391 if(rainTerrainRevision==terrainRevision && renderer->HasRainGrid(revision,header.cube,header.tcp.u,header.tcp.v))return;
1392 auto grid=std::make_unique<Rendering::CloudRenderer11::RainGrid>();
1393 grid->cells.fill({0,0,42.16f,2});
1394 grid->cube=header.cube;grid->u=header.tcp.u;grid->v=header.tcp.v;grid->revision=revision;
1395 for(int q=0;q<64;++q)for(int row=0;row<64;++row)
1396 {
1397 const VECTOR2SHORT at(short(header.tcp.u+q-31),short(header.tcp.v+row-31));
1398 const auto* sample=plotWeather.At(header.cube,at,header.requestToken);
1399 short elevation;
1400 if(sample && sample->HasVisibility() && viewscreen->ptrGrid->TryElevation(header.cube,at.u,at.v,elevation))
1401 {
1402 const auto fog=spatialFogWeather.Sample(SpatialFogWeather::Direction(header.cube,at.u,at.v));
1403 grid->cells[row*64+q]={elevation*.001f,(elevation+sample->ceiling)*.001f,
1404 fog.visibility,fog.precipitation};
1405 }
1406 }
1407 renderer->SetRainGrid(grid.get());
1408 rainTerrainRevision=terrainRevision;
1409}
1410
1412{
1413 // An explicit test range stays exact at every altitude, independently of BCL.
1414 if (visibilityOverrideKm >= 0.f)
1415 return visibilityOverrideKm;
1420 smoothVisibility>=0 ? smoothVisibility : 42.16f,
1422 if (!playerships[0].isSimulator && smoothVisibility >= 0)
1423 return smoothVisibility;
1425 return 42.16f; // 168.64f / powf(GetTurbidity(), 2.0f) ... at 2
1426}
1427
1429{
1430 if (!playerships[0].isSimulator && smoothwinddir >= 0) // radians 0-6.282
1431 return smoothwinddir;
1433 return 0.0f;
1434}
1435
1437{
1438 // Preserve Rise's existing atmospheric envelope, independently of the
1439 // 10/9.5 km local-grid suspension. Re-entry samples the current position.
1440 if (playerships[0].isSimulator || !std::isfinite(playerships[0].mslKm) || playerships[0].mslKm >= 63.f)
1441 return 0.f;
1442 const auto position = playerships[0].position;
1443 const float lengthSquared = RiseMath::Vec3LengthSq(&position);
1444 if (!std::isfinite(lengthSquared) || lengthSquared <= 0.f) return 0.f;
1445 // The turbulence source boundary is 9.5 km MSL in both directions.
1446 // Keep it independent of the 10/9.5 km visual/local-grid hysteresis.
1447 if (playerships[0].mslKm < 9.5f)
1448 {
1449 if (plotWeatherSuspended) return 0.f;
1450 const char cube = viewscreen->CalculateCube(position);
1451 double u, v;
1453 // Turbulence needs no terrain elevation or camera position.
1454 if (PlotWeather::Coordinates(position, cube, u, v)
1455 && plotWeather.Interpolate(cube, u, v, weatherRequestToken, sample))
1456 return sample.turbulence;
1457 // An unavailable local observation is not a license to substitute the
1458 // coarse planetary field. Resume when the current local grid arrives.
1459 return 0.f;
1460 }
1461 // Above 9.5 km the global feed supplies the server turbulenceScalar,
1462 // including flight through the 10-22 km convective cloud envelope.
1463 // Flight dynamics already smooth gust energy; do not use the render fade.
1464 const auto map = viewscreen->gameclass->networking->cloudWeather.Latest();
1465 float u, v;
1466 CloudWeather::UV(-position.x, -position.y, -position.z, u, v);
1467 return CloudWeather::Sample(map, u, v); // zero until a complete global map is available
1468}
1469
1471{
1472 if (playerships[0].isSimulator)
1473 return 20.0f; // @todo override with GUI values
1474 if (playerships[0].reference < REF_INANOTHER)
1475 return smoothTemperature;
1476 if (playerships[0].reference == REF_INANOTHER)
1477 return 20.0f; // @todo should be the interior temp of the parent
1478 if (playerships[0].reference >= REF_DOCKENUMCPOC && !playerships[0].docked)
1479 return smoothTemperature;
1480 return 20.0f; // interior of docks, buildings, you name it!
1481}
1482
1484{
1485 if (!playerships[0].isSimulator)
1488 return playerships[0].mslKm - f_AGL + 1.8f;
1489}
1490
1492{
1494}
1495
1497{
1498 return (GetPrecip() - 2.0f) / 14.0f;
1499}
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
float Lerp(float val1, float val2, float lerp)
constexpr auto Clamp(T1 val, T2 min, T3 max)
@ ORDERING_WEATHER
Definition ServerTypes.h:19
@ NightVision
@ REF_ACLMODE
Definition ServerTypes.h:44
@ REF_DOCKENUMCPOC
Definition ServerTypes.h:53
@ REF_INANOTHER
Definition ServerTypes.h:45
@ REF_APNMODE
Definition ServerTypes.h:42
@ REF_ONGROUND
Definition ServerTypes.h:43
@ REF_WINDOWLESS
Definition ServerTypes.h:50
@ SOUND_CLIMBING10K
Definition Sound.h:184
@ SOUND_DESCENT
Definition Sound.h:186
float DebugPrecip
Definition Bus.h:552
float DebugViz
Definition Bus.h:552
float LatitudeRad
Definition Bus.h:313
float DebugCeiling
Definition Bus.h:552
float DebugFloat7
Definition Bus.h:545
float DebugFloat1
Definition Bus.h:539
std::vector< Command > commandStream
Definition Bus.h:442
void Target(GridPtr next)
void Advance(double elapsed)
void UpdateLightning(const CloudVolume::Parameters &value, double elapsed, const CloudVolume::Point &observer={})
void SetLightningEnabled(bool value)
CloudWeather::Frame WeatherFrame()
bool SetLightningDiagnostic(bool enabled)
Rendering::CloudRenderer11 * Effect()
void UpdateWeather(const CloudWeather::MapPtr &value, double elapsed)
std::unique_ptr< Bus > bus
Definition GameClass.h:108
std::unique_ptr< Sound > sound
Definition GameClass.h:104
std::unique_ptr< Networking > networking
Definition GameClass.h:103
std::unique_ptr< Graphics > graphics
Definition GameClass.h:105
float displayWidth
Definition GameClass.h:131
Rendering::RenderMaterial * g_pEffect
Definition Graphics.h:30
void SetCells(std::vector< Cell > next)
void Observe(const Vector3 &ground)
void Seed(uint32_t seed)
const Cell * Find(short u, short v) const
bool Update(double elapsed, const Vector3 &observer, int players, float snow, float turbulence, Event &event)
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
@ Warn
Definition Logger.h:26
@ Error
Definition Logger.h:28
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
CloudWeather::Receiver cloudWeather
Definition Networking.h:90
Result Accept(const unsigned char *p, size_t length, uint16_t expectedToken)
bool Interpolate(unsigned cube, double u, double v, uint16_t token, LocalSample &result) const
const SRenderWeather * At(unsigned cube, VECTOR2SHORT tcp, uint16_t token) const
const SPlotWeatherHeader & Header() const
void SetRainGrid(const RainGrid *grid)
HRESULT SetVector(const char *name, const RiseMath::Vector4 *value)
bool outside
Definition Camera.h:17
void PlayCabinAnnouncement(SOUNDS sound_enum)
Definition Sound.cpp:3456
void Advance(double elapsed, Point physicalPosition, Point physicalWindKms)
void Accept(GridPtr next, bool full)
uint64_t SourceRevision() const
Cell Sample(Point renderPosition) const
void Retain(VECTOR2SHORT p)
Definition TerrainSnow.h:29
const Surface * At(VECTOR2SHORT p) const
Definition TerrainSnow.h:52
void Target(VECTOR2SHORT p, const SRenderWeather &sample)
Definition TerrainSnow.h:30
void Advance(float elapsed)
Definition TerrainSnow.h:39
float turbLow
Definition Viewscreen.h:97
Rendering::ProceduralLightning11 proceduralLightning
Definition Viewscreen.h:397
RiseMath::Vector3 position
Definition Viewscreen.h:382
CloudVolumeRenderer cloudVolume
Definition Viewscreen.h:396
bool VolumeCloudsEnabled() const
Definition Viewscreen.h:404
GameClass * gameclass
Definition Viewscreen.h:439
RiseMath::Vector3 compassnorth
Definition Viewscreen.h:107
bool InventoryItemEffectsEnabled() const
Definition Viewscreen.h:169
float nightVisionOverexposure
Definition Viewscreen.h:366
bool m_bDeviceSupportsVizQuery
Definition Viewscreen.h:349
RiseMath::Matrix matrixLook
Definition Viewscreen.h:346
RiseMath::Vector3 posnorml
Definition Viewscreen.h:383
std::unique_ptr< grid > ptrGrid
Definition Viewscreen.h:426
bool IsRepositionSettling() const
Definition Viewscreen.h:152
Rendering::Light sunlight
Definition Viewscreen.h:328
float UniverseRelativeSpeedKms
Definition Viewscreen.h:126
float turbEnergy
Definition Viewscreen.h:98
VECTOR2SHORT CalculateCGC(RiseMath::Vector3 position, char cube) const
RiseMath::Color alphascreen
Definition Viewscreen.h:364
VECTOR2SHORT CalculateWrap(short u, short v, char cube, char *rotate) const
RiseMath::Vector3 CalculatePlanar(short u, short v)
void TriggerBCLLightningAt(const RiseMath::Vector3 &ground, const RiseMath::Vector3 &cloud, float distanceKm, int seed, int chainedBolts, bool testStrike=false) const
float onlinePlayersInVicinity
Definition Viewscreen.h:100
RiseMath::Vector3 forwardVector
Definition Viewscreen.h:363
char CalculateCube(RiseMath::Vector3 position) const
float nightVisionOverexposureHold
Definition Viewscreen.h:367
Logger * logger
Definition Viewscreen.h:440
SCamera * camera
Definition Viewscreen.h:137
float ProbeBoundSphere(RiseMath::Vector3 *position, const RiseMath::Vector3 *Xsunlight) const
Definition grid.h:14
uint64_t ElevationRevision() const
Definition grid.h:54
bool InterpolateElevation(char face, double u, double v, float &meters) const
Definition grid.cpp:167
bool wholeGridPending
Definition grid.h:40
char cube
Definition grid.h:45
bool dataReady
Definition grid.h:36
bool TryElevation(char face, short u, short v, short &meters) const
Definition grid.cpp:132
VECTOR2SHORT tcp
Definition grid.h:44
RiseMath::Color cockpitRawAmbient
Definition weather.h:192
float cloudCeilingOverrideKm
Definition weather.h:75
float GetPrecip() const
Definition weather.cpp:1365
void UpdateLightningSpawns(float elapsed)
Definition weather.cpp:1225
RiseMath::Color dwFogFactorZenith
Definition weather.h:194
RiseMath::Color vehicleAmbient
Definition weather.h:188
float smoothVisibility
Definition weather.h:64
float smoothTemperature
Definition weather.h:71
void ReceiveGridLightning(short u, short v, int seed, int chainedBolts)
Definition weather.cpp:1214
float alphascreenOverride
Definition weather.h:224
void SetCloudCeilingTargetKm(float prmCloudCeilingTargetKm)
Definition weather.cpp:950
uint64_t lightningTerrainRevision
Definition weather.h:104
uint32_t lightningWeatherRevision
Definition weather.h:103
float cloudSurfaceTargetKm
Definition weather.h:77
CloudBaseWeather::Store cloudBaseWeather
Definition weather.h:91
CloudVolume::Point ObservedWindKms() const
Definition weather.cpp:967
uint64_t cloudBaseTerrainRevision
Definition weather.h:94
float cloudHorizonAngle
Definition weather.h:196
float GetTurbulence() const
Definition weather.cpp:1436
bool RefreshLightningGrid()
Definition weather.cpp:1120
void SetCloudSurfaceTargetKm(float prmCloudSurfaceTargetKm)
Definition weather.cpp:938
RiseMath::Color solarHorizon
Definition weather.h:199
float cloudCeilingSmoothAglKm
Definition weather.h:74
float GetRainPrecip() const
Definition weather.cpp:1360
Logger * logger
Definition weather.h:46
RiseMath::Color dwFogColorZenith
Definition weather.h:193
weather(Viewscreen *ptr)
Definition weather.cpp:11
void UpdateTerrainSnow(float elapsed)
Definition weather.cpp:1296
void SetPrecip(float prmPrecip)
Definition weather.cpp:893
float daylightOverride
Definition weather.h:223
float shadow
Definition weather.h:213
bool hullIonization
Definition weather.h:52
float smoothPrecip
Definition weather.h:60
float GetWindspeedKms() const
Definition weather.cpp:1352
void SetTemperatureCelsius(float prmTemperature)
Definition weather.cpp:869
float shearRate
Definition weather.h:201
static float SunAttenuation()
Definition weather.cpp:22
RiseMath::Vector4 TerrainSnowTint(int u, int v) const
Definition weather.cpp:1324
float temperature
Definition weather.h:70
void FrameMove(float fElapsedTime)
Definition weather.cpp:32
float winddir
Definition weather.h:67
uint16_t cloudBaseRequestToken
Definition weather.h:93
void ForceSmoothValues()
Definition weather.cpp:1338
void RequestPlotWeather(bool reset)
Definition weather.cpp:1053
RiseMath::Color cockpitAmbient
Definition weather.h:190
float orbitSunLatitude
Definition weather.h:117
void ResetCloudBaseWeather()
Definition weather.cpp:1243
char msg[199]
Definition weather.h:49
float cloudHorizonDistance
Definition weather.h:196
uint16_t snowRequestToken
Definition weather.h:99
TerrainSnow::Store terrainSnow
Definition weather.h:97
short r
Definition weather.h:50
NightVisionGain::Response cockpitVision
Definition weather.h:189
bool weatherPending
Definition weather.h:82
float GetNormalizedPrecip()
Definition weather.cpp:1496
void QueuePlotWeatherReset()
Definition weather.cpp:1060
GridLightning::System gridLightning
Definition weather.h:102
RiseMath::Color sunAppearance
Definition weather.h:121
void SetWindDirectionRadians(float prmWinddir)
Definition weather.cpp:856
float GetWindDirectionRadians() const
Definition weather.cpp:1428
RiseMath::Color betascreen
Definition weather.h:200
float GetCloudCeilingKm() const
Definition weather.cpp:1491
uint64_t snowTerrainRevision
Definition weather.h:100
bool resetLocalCloudWeather
Definition weather.h:111
float windspeed
Definition weather.h:55
float visibility
Definition weather.h:63
void PrepareRainCurtains(bool exteriorView)
Definition weather.cpp:1375
float cloudPocket
Definition weather.h:218
void SetCloudCeilingOverrideKm(float value)
Definition weather.cpp:911
float precipOverride
Definition weather.h:61
void SetWindspeedKms(float prmWindspeed)
Definition weather.cpp:881
bool TriggerForwardLightning()
Definition weather.cpp:1161
float elevation
Definition weather.h:197
float cloudVisSmooth1
Definition weather.h:81
bool plotWeatherSuspended
Definition weather.h:83
DWORD m_dwSunViz
Definition weather.h:204
RiseMath::Color cockpitRawCloudLight
Definition weather.h:191
RiseMath::Vector4 nightVisionCloudGain
Definition weather.h:116
RiseMath::Color colorhorizon
Definition weather.h:198
float snowBlend
Definition weather.h:202
ULONGLONG weatherDiagnosticUntil
Definition weather.h:112
CloudVolume::Point cloudSurfaceWind
Definition weather.h:221
float cloudRainDensity
Definition weather.h:220
uint16_t weatherRequestToken
Definition weather.h:85
ULONGLONG weatherNextDiagnostic
Definition weather.h:112
float cloudCeilingTargetKm
Definition weather.h:73
float cloudThickness
Definition weather.h:215
bool weatherRequestQueued
Definition weather.h:82
uint32_t snowWeatherRevision
Definition weather.h:98
float smoothwinddir
Definition weather.h:68
Viewscreen * viewscreen
Definition weather.h:45
void ReceivePlotWeather(const unsigned char *bytes, size_t length)
Definition weather.cpp:1069
void UpdateSpatialFogSnapshot(bool full)
Definition weather.cpp:978
float visibilityOverrideKm
Definition weather.h:65
CloudVolume::Parameters cloudParameters
Definition weather.h:216
SpatialFogWeather::Store spatialFogWeather
Definition weather.h:87
short s
Definition weather.h:50
float cloudVisTarget1
Definition weather.h:80
float cloudSurfaceSmoothKm
Definition weather.h:78
void SetVisibility(float prmVisibility)
Definition weather.cpp:926
void SetPrecipOverride(float value)
Definition weather.cpp:905
void SetVisibilityOverrideKm(float value)
Definition weather.cpp:918
RiseMath::Color SampleColorGradient(float step, const ColorStop(&stops)[N])
Definition weather.h:124
float precip
Definition weather.h:59
float GetCloudCeilingMslKm() const
Definition weather.cpp:1483
void UpdateCloudBaseWeather(float elapsed)
Definition weather.cpp:1249
float solarVisibility
Definition weather.h:214
void ResetTurbulence()
Definition weather.cpp:962
uint32_t cloudBaseWeatherRevision
Definition weather.h:92
float cloudTurbulenceBlend
Definition weather.h:219
RiseMath::Color dwFogColorHorizon
Definition weather.h:195
short t
Definition weather.h:50
void AdvanceSpatialFog(float elapsed)
Definition weather.cpp:998
void ResetPlotWeatherConnection()
Definition weather.cpp:1008
float GetVisibilityKm() const
Definition weather.cpp:1411
float GetTemperatureCelsius() const
Definition weather.cpp:1470
float lightningAfterimageAmbient
Definition weather.h:185
float cloudDensity
Definition weather.h:217
void UpdatePlotWeatherConditions()
Definition weather.cpp:1085
float smoothwindspeed
Definition weather.h:56
bool UpdatePlotWeatherAltitude()
Definition weather.cpp:1028
bool spatialFogRendering
Definition weather.h:84
uint64_t rainTerrainRevision
Definition weather.h:104
float fFogEndHorizon
Definition weather.h:207
PlotWeather::Store plotWeather
Definition weather.h:86
unsigned char ourplanetC
Definition globals.cpp:25
float f_ACL
Definition globals.cpp:11
float f_AGL
Definition globals.cpp:9
FIREWORKS fireworks[fireworksC]
Definition globals.cpp:118
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
float f_BCL
Definition globals.cpp:12
s_universe_object allobjects[maxstarC]
Definition globals.cpp:108
Scockpit ourcockpit
Definition globals.cpp:114
bool g_bAboveClouds
Definition globals.cpp:16
LIGHTNINGBELOW lightningbelow
Definition globals.cpp:116
s_polygon_object polyobjects[maxpolyC]
Definition globals.cpp:106
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
unsigned char ourstarC
Definition globals.cpp:24
#define firework1C
Definition globals.h:60
#define firework3C
Definition globals.h:62
#define ScaleHeightC
Definition globals.h:98
#define radiusC
Definition globals.h:87
#define cloudTopsRadiusC
Definition globals.h:112
#define cloudTopsMslC
Definition globals.h:110
#define fireworksC
Definition globals.h:769
#define cloudBufferMslC
Definition globals.h:111
#define firework2C
Definition globals.h:61
#define sunColorC
Definition globals.h:116
float SolarAngularRadius(float billboardScale, float billboardDistance)
Sphere Configure(bool simulator, Point center, float radius, float solarRadius)
float Visibility(const Sphere &body, Point point, Point towardSun)
float AltitudeWeight(float altitude, float top)
Lighting Evaluate(bool active, bool simulator, CloudVolume::Point scattered, CloudVolume::Point airglow, float sunCosine, float altitude, float base, float top)
float Smooth(float x)
Definition CloudVolume.h:51
Point Add(Point a, Point b)
Definition CloudVolume.h:95
float AtmosphereWeight(float altitude, float scaleHeight)
Definition CloudVolume.h:65
void UpdateLocalWeather(Parameters &params, Point &deckWind, bool belowDeck, float base, float activity, Point observedWind, double elapsed, bool reset=false)
Point VehicleAmbient(Point cloudLight, Point skyLight, float altitudeAboveTop)
Definition CloudVolume.h:84
constexpr float ShiplightScatterDistanceKm
Definition CloudVolume.h:70
constexpr float ClearVisibilityKm
bool SelectOrganicMode(Parameters &params, bool matchingRendererReady, bool simulator)
Definition CloudVolume.h:42
float Transmittance(Point from, Point to, const Parameters &params, uint32_t seed=DefaultSeed)
float DiffuseSunTransmission(Point p, Point towardSun, const Parameters &params, uint32_t seed=DefaultSeed)
float ShiplightScatterWeight(float altitude, float deckTop, float scaleHeight, float visibilityKm, float localCloudOpacity)
Definition CloudVolume.h:71
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
Medium SampleMedium(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float AtmosphericVisibility(float surfaceVisibility, float altitude, float surfaceAltitude, float clearAltitude)
float SunGlareStrength(bool volumeEnabled, float altitudeAboveTop, float visibleSun, float transmission)
float RainDensity(const Medium &medium)
float ScreenOpacity(bool volumeEnabled, float cloudOpacity, float overrideOpacity)
Point ScatteredSunlight(Point incident, float sunCosine, float transmission)
float Sample(const MapPtr &map, float u, float v)
void UV(float x, float y, float z, float &u, float &v)
CloudVolume::Point Ambient(CloudVolume::Point cloudLight, CloudVolume::Point skyLight, float altitudeAboveTop, const NightVisionGain::Response &vision)
constexpr float RadiusKm
float Distance(const Vector3 &a, const Vector3 &b)
constexpr int MaxChainedBolts
float Radiance(float pulse)
void Update(bool active, float flashStimulus, float ambientLuminance, float elapsedSeconds, float &exposure, float &holdSeconds)
Response Calculate(bool active, bool simulator, float luminance)
constexpr unsigned RequestType
bool ParseHeader(const unsigned char *p, size_t length, SPlotWeatherHeader &result)
bool Coordinates(const RiseMath::Vector3 &position, unsigned cube, double &u, double &v)
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
constexpr float Pi
Definition ClientMath.h:12
Color * ColorLerp(Color *out, const Color *a, const Color *b, float t)
Definition ClientMath.h:173
float Vec3LengthSq(const Vector3 *a)
Definition ClientMath.h:94
Vector3 * Vec3Subtract(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:97
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:107
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Definition ClientMath.h:118
constexpr float Tau
Definition ClientMath.h:12
Matrix * MatrixRotationAxis(Matrix *out, const Vector3 *axis, float angle)
Definition ClientMath.h:129
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
auto ToDegree(T value)
Definition ClientMath.h:14
constexpr auto Max(A first, B second)
Definition ClientMath.h:16
constexpr float HalfPi
Definition ClientMath.h:12
Point Direction(int cube, double u, double v)
RiseMath::Vector4 Tint(const Surface &surface, float latitude, float sunLatitude)
Definition TerrainSnow.h:12
float Target(float overrideValue, float weatherTarget)
void Apply(float value, float weatherTarget, float &overrideValue, float &smoothValue)
CelestialEclipse::Sphere eclipse
Definition CloudVolume.h:37
CloudWeather::Frame weather
Definition CloudVolume.h:35
CloudBaseWeather::Frame localBase
Definition CloudVolume.h:36
std::string name
Definition Command.h:11
RiseMath::Color color
Definition globals.h:775
RiseMath::Vector3 position
Definition globals.h:776
float intensity
Definition globals.h:763
void Update(double elapsed)
RiseMath::Vector3 Direction
RiseMath::Color Diffuse
unsigned char type
int inventoryItemInUseSubType
Definition globals.h:700
float power
Definition globals.h:599
float adrenolinBPM
Definition globals.h:741
int inventoryItemInUseType
Definition globals.h:699
unsigned long sequencing
Definition globals.h:352
RiseMath::Color diffuse
Definition globals.h:351
RiseMath::Vector3 barycentric
Definition globals.h:500
RiseMath::Vector3 position
Definition globals.h:511
unsigned long compare
Definition globals.h:514
RiseMath::Vector3 velocity
Definition globals.h:500
unsigned char inarray
Definition globals.h:509
float baydoorextent
Definition globals.h:539
std::vector< s_light_effect > effects
Definition globals.h:361