1#include "../Viewscreen/NightVisionExposure.h"
2#include "../Viewscreen/NightVisionGain.h"
3#include "../Viewscreen/CloudVolume.h"
4#include "../Viewscreen/CockpitLighting.h"
5#include <cmath>
6#include <cstdlib>
7#include <iostream>
8
9static void Check(bool condition, const char* message)
10{
11 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
12}
13
14static bool Near(float left, float right)
15{
16 return std::fabs(left - right) < 0.0001f;
17}
18
19#include "CloudNightVisionTests.h"
20
21int main()
22{
23 TestCloudNightVision();
24
25
29 "display optics fade toward daylight without a threshold pop");
32 Check(assistedCabin.x>redCabin.
x && assistedCabin.x<=1 && assistedCabin.y==0 && assistedCabin.z==0,
33 "NVG enhances existing red cabin illumination without inventing other light channels");
36 {
38 Check(local.x==redCabin.
x && local.y==0 && local.z==0,
"local light resets for equipment/camera, simulator and daylight");
40 }
42 Check(unpowered.x==0 && unpowered.y==0 && unpowered.z==0,"unpowered cabin cannot acquire a synthetic light source");
44 Check(dimCabin.x>0 && dimCabin.x<assistedCabin.x,"cabin power dimming still reduces the assisted signal");
49 Check(below.x==cloud.
x && below.y==cloud.
y && below.z==cloud.
z,
"below-deck cockpit light is not amplified twice");
51 Check(above.x>.2f && above.y>.3f && above.z>.4f,"night sky lights cockpit surfaces above the deck");
53 Check(above.y>bare.y*100,"above-deck cockpit does not fall back to unassisted sky light");
54 for(float height:{-10.f,-.5f,0.f,.25f,.5f,1.f,20.f,100.f,1.f,0.f,-.5f,-10.f})
55 {
57 Check(light.y>=above.y && light.y<=below.y,"ascent/descent blends continuously between enhanced light sources");
60 Check(off.x==normal.x && off.y==normal.y && off.z==normal.z,"unequipped/external view uses baseline sky fill");
62 Check(simulator.x==normal.x && simulator.y==normal.y && simulator.z==normal.z,"simulator does not acquire enhanced sky fill");
64 Check(day.x==normal.x && day.y==normal.y && day.z==normal.z,"daylight cockpit stays unchanged");
66 Check(resumed.x==light.x && resumed.y==light.y && resumed.z==light.z,"camera/equipment/simulator round trip restores cockpit light immediately");
67 }
69 Check(zero.x==0 && zero.y==0 && zero.z==0,"orbital darkness does not create a new light source");
71 Check(clipped.x==1 && clipped.y==1 && clipped.z==1,"surface fill is bounded before texture modulation");
74 Check(std::abs(boundaryA.y-boundaryB.y)<.001f,"cloud-top crossing does not introduce a lighting step");
75 std::cout << "PASS: cockpit NVG above/below deck, round trips, daylight, zero light, bounded fill and simulator baseline.\n";
76
77
78
80 for (float sun : {.02f,.05f,.10f,.20f,1.f})
81 {
82 float start=0;
83 for (float altitude : {.5f,1.2f,2.6f,5.f,11.f,.5f})
84 {
86 {std::sqrt(1-sun*sun),sun,0},clouds);
87 const float incident=std::exp(-.5f*std::exp(-clouds.
top/7.5f));
90 const float amplified=(std::min)(1.f,light*response.green);
91 if (sun<=.20f && altitude<10) Check(amplified>.85f,"NVG low-sun cloud/ground brightness remains readable");
92 if (sun==1) Check(response.red==1 && response.green==1 && response.blue==1 && !response.clouds,"daylight gain is identity");
93 if (altitude==.5f && start==0) start=amplified;
94 else if (altitude==.5f) Check(amplified==start,"return below deck restores the same gain without re-equipping");
95 }
96 }
97 for (float luma : {0.f,1e-7f,.001f,.0025f,.01f,.04f,.1f,.3f,.35f,1.f})
98 {
100 Check(std::isfinite(response.green) && response.green<=990.001f,"gain is finite at zero and subthreshold signals");
101 if (luma<1e-6f) Check(luma*response.green<.001f,"absent light is not replaced with a brightness floor");
103 Check(response.red==1 && response.green==1 && response.blue==1 && !response.clouds,"unequipped/external camera clears enhanced gain");
105 const float blend=std::clamp((.35f-luma)/.30f,0.f,1.f);
106 const float target=(std::min)(24.f,.9f/(std::max)(luma,.01f));
107 const float original=1.f+((std::max)(1.f,
target)-1.f)*blend;
108 Check(!response.clouds &&
Near(response.green,original*(1.f+.10f*blend)),
"simulator entry preserves original gain and suppresses enhanced clouds");
110 if (luma==.0025f) Check(resumed.green>response.green*10,"simulator exit recomputes real-flight gain");
111 }
112 std::cout << "PASS: NVG low-sun climb/descent, signal floor, daylight, equipment/camera and simulator transitions.\n";
113 for (int hz : {15, 30, 60, 144})
114 {
115 const float dt = 1.0f / hz;
116 float exposure = 0.0f, hold = 0.0f;
118 Check(
Near(exposure, 1.0f) &&
Near(hold, 0.65f),
"nighttime lightning still produces a strong flash");
119
120
121
122 for (int frame = 0; frame < hz * 5; ++frame)
124 Check(exposure == 0.0f && hold == 0.0f, "cloud-top exit recovers without switching off NVG");
125 for (int frame = 0; frame < hz * 60; ++frame)
127 Check(exposure == 0.0f && hold == 0.0f, "no phantom exposure during prolonged flight above clouds");
128
130 for (int frame = 0; frame < hz * 5; ++frame)
132 Check(
Near(exposure, 0.175f),
"continuous weaker flashes cannot latch an earlier full whiteout");
133
135 for (int frame = 0; frame < hz * 5; ++frame)
137 Check(
Near(exposure, 0.15f),
"daylight flashes cannot preserve nighttime saturation");
138 for (int frame = 0; frame < hz; ++frame)
140 Check(exposure == 0.0f && hold == 0.0f, "daytime flash clears within a second");
141
143 for (int frame = 0; frame < hz; ++frame)
145 Check(exposure > 0.8f && exposure < 0.95f, "nighttime recovery retains the gradual effect");
147 Check(
Near(exposure, 1.0f) &&
Near(hold, 0.65f),
"a new strong strike can retrigger saturation");
148
150 Check(exposure == 0.0f && hold == 0.0f, "external camera or unequipping NVG immediately clears state");
152 const bool equipped=true, simulator=true;
154 Check(exposure == 0.0f && hold == 0.0f, "simulator entry clears an active real-flight afterimage even while equipped");
156 Check(exposure == 0.0f && hold == 0.0f, "simulator exit cannot replay the cleared afterimage");
158 Check(exposure == 0.0f && hold == 0.0f, "subthreshold flashes do not accumulate");
159
162 Check(
Near(exposure, 1.0f) &&
Near(hold, 0.65f),
"zero elapsed time does not advance recovery");
164 Check(exposure == 0.0f && hold == 0.0f, "long frames consume both hold and fade time");
165 }
166 std::cout << "PASS: NVG flash recovery, cloud-top input cessation, weaker flashes, daylight sensitivity, and reset at 15/30/60/144 Hz.\n";
167}
Point VehicleAmbient(Point cloudLight, Point skyLight, float altitudeAboveTop)
float DiffuseSunTransmission(Point p, Point towardSun, const Parameters ¶ms, uint32_t seed=DefaultSeed)
Point ScatteredSunlight(Point incident, float sunCosine, float transmission)
float DisplayStrength(const NightVisionGain::Response &vision)
CloudVolume::Point Ambient(CloudVolume::Point cloudLight, CloudVolume::Point skyLight, float altitudeAboveTop, const NightVisionGain::Response &vision)
CloudVolume::Point LocalLight(CloudVolume::Point light, const NightVisionGain::Response &vision)
void Update(bool active, float flashStimulus, float ambientLuminance, float elapsedSeconds, float &exposure, float &holdSeconds)
Response Calculate(bool active, bool simulator, float luminance)
bool Near(const Body &b, const Triangle &t, double extra)