Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CloudNightVisionTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1#pragma once
2#include "../Viewscreen/CloudNightVision.h"
3#include <vector>
4
5static void TestCloudNightVision()
6{
7 using namespace CloudVolume;
8 const Point glow{.125f,.375f,.25f};
9 // Regression: even a faint green source previously became (1,1,1).
10 const auto darkGain=NightVisionGain::Calculate(true,false,.0025f);
11 const Point raw{.005f,.015f,.010f};
12 const auto bright=CloudNightVision::Amplify(raw,darkGain);
13 Check(bright.y>.99f && bright.x<bright.y*.3f && bright.z<bright.y*.8f,
14 "strong gain retains a bright green signal instead of clipping it white");
15 Check(Near(bright.x/bright.y,raw.x*darkGain.red/(raw.y*darkGain.green)),
16 "highlight compression preserves the gained red/green ratio");
17 Check(Near(bright.z/bright.y,raw.z*darkGain.blue/(raw.y*darkGain.green)),
18 "highlight compression preserves the gained blue/green ratio");
19 const auto stronger=CloudNightVision::Amplify(Scale(raw,2),darkGain);
20 Check(stronger.y>bright.y && stronger.y<1,"bright detail remains monotonic through the shoulder");
21 const auto black=CloudNightVision::Amplify({0,0,0},darkGain);
22 Check(black.x==0 && black.y==0 && black.z==0,"cloud optics create no light from zero input");
23 for(float luma:{.001f,.0025f,.01f,.1f,.3499f,.35f,1.f})
24 for(float level:{0.f,.0001f,.01f,.5f,.9f,.99f,1.f})
25 {
26 const auto gain=NightVisionGain::Calculate(true,false,luma);
27 const auto result=CloudNightVision::Amplify(Scale(glow,level),gain);
28 Check(result.x>=0 && result.y>=0 && result.z>=0 && result.x<=1 && result.y<=1 && result.z<=1,
29 "cloud exposure is bounded and finite across daylight fade");
30 }
31 Parameters cloud;cloud.base=1.8f;
32 const float incident=std::exp(-.5f*std::exp(-cloud.top/7.5f));
33 const Point sunlight{incident*240.f/255,incident*245.f/255,incident};
34 for(float sun:{-.2f,0.f,.02f,.2f,.6f})
35 {
36 std::vector<CloudNightVision::Lighting> climb;
37 for(int step=0;step<=160;++step)
38 {
39 const float altitude=.5f+step*.075f;
40 const Point point{0,cloud.radius+altitude,0};
41 const float transmission=DiffuseSunTransmission(point,{std::sqrt(1-sun*sun),sun,0},cloud);
42 const auto scattered=ScatteredSunlight(sunlight,(std::max)(sun,.05f),transmission);
43 const auto column=Boundaries(point,cloud);
44 const auto on=CloudNightVision::Evaluate(true,false,scattered,glow,sun,altitude,column.base,column.top);
45 const auto off=CloudNightVision::Evaluate(false,false,scattered,glow,sun,altitude,column.base,column.top);
46 const auto baseline=WithAirglow(scattered,glow,sun,altitude,column.base,column.top);
47 Check(off.fog.x==baseline.x && off.fog.y==baseline.y && off.fog.z==baseline.z,
48 "disabled cloud optics preserve the original atmosphere");
49 if(sun<=0 && altitude<=10.f)
50 {
52 "colored clouds retain strong brightness enhancement throughout the deck");
53 Check(Near(on.fog.x/on.fog.y,baseline.x*on.gain.red/(baseline.y*on.gain.green)) &&
54 Near(on.fog.z/on.fog.y,baseline.z*on.gain.blue/(baseline.y*on.gain.green)),
55 "night cloud mixture preserves source color ratios through the climb");
56 }
57 if(!climb.empty())
58 Check(std::abs(on.fog.y-climb.back().fog.y)<.12f,
59 "dense altitude sweep has no exposure step at the nominal cloud top");
60 climb.push_back(on);
61 }
62 for(int step=160;step>=0;--step)
63 {
64 const float altitude=.5f+step*.075f;
65 const Point point{0,cloud.radius+altitude,0};
66 const auto scattered=ScatteredSunlight(sunlight,(std::max)(sun,.05f),
67 DiffuseSunTransmission(point,{std::sqrt(1-sun*sun),sun,0},cloud));
68 const auto column=Boundaries(point,cloud);
69 const auto returned=CloudNightVision::Evaluate(true,false,scattered,glow,sun,altitude,column.base,column.top);
70 const auto first=climb[step];
71 Check(returned.fog.x==first.fog.x && returned.fog.y==first.fog.y && returned.fog.z==first.fog.z,
72 "descent exactly restores each climb exposure without equipment cycling");
73 }
74 }
75 for(const auto reset:{NightVisionGain::Calculate(false,false,.0025f),
76 NightVisionGain::Calculate(true,true,.0025f),NightVisionGain::Calculate(true,false,1)})
77 {
78 const auto restored=CloudNightVision::Amplify(raw,reset);
79 Check(restored.x==raw.x && restored.y==raw.y && restored.z==raw.z,
80 "camera/equipment, simulator and daylight restore baseline cloud color");
81 }
82 std::cout<<"PASS: airglow-aware cloud exposure, hue/brightness, 161-point climb/descent, daylight and reset.\n";
83}
CloudVolume::Point Amplify(CloudVolume::Point light, const NightVisionGain::Response &gain)
float Luminance(CloudVolume::Point light)
Lighting Evaluate(bool active, bool simulator, CloudVolume::Point scattered, CloudVolume::Point airglow, float sunCosine, float altitude, float base, float top)
Point Scale(Point p, float s)
Definition CloudVolume.h:93
float DiffuseSunTransmission(Point p, Point towardSun, const Parameters &params, uint32_t seed=DefaultSeed)
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
Point ScatteredSunlight(Point incident, float sunCosine, float transmission)
Point WithAirglow(Point scattered, Point airglow, float sunCosine, float altitude, float base, float top)
Response Calculate(bool active, bool simulator, float luminance)
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141