1#include "../Rendering/CloudOrbitResolution11.h"
2
3
4
5
6static void TestOrganicNightExterior(Device11& gpu,CloudRenderer11&
renderer)
7{
8 Scene scene(gpu.Device(),4);Pipeline pipeline(gpu.Device(),4);
9 XMFLOAT4X4 view,projection;
10 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,0,0),XMVectorSet(0,0,1,0)));
11 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(.02f,float(Width)/Height,.001f,10000));
12 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
13 for(uint8_t convection:{uint8_t(0),uint8_t(127),uint8_t(255)})
14 {
15 auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({32,16,std::vector<uint8_t>(32*16,convection)});
17 HR(
renderer.PrepareResources(gpu.Context()),
"night exterior weather upload");
renderer.UpdateWeather(map,60);
18 for(float altitude:{117.f,1000.f,3000.f})for(bool nvg:{false,true})
19 {
21 const XMFLOAT4 gain=nvg ? XMFLOAT4(18.193232f,23.544182f,25.684563f,1) : XMFLOAT4(1,1,1,0);
22 for(bool glow:{false,true})
23 {
24 renderer.ResetCloudHistory();scene.Clear(gpu.Context());
25 HR(
renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
26 {0,cloud.radius+altitude,0},cloud,{.9797959f,.2f,0},
27 {0,0,0,1},{0,0,0,1},glow ? XMFLOAT4(.5f,.5f,.5f,1) : XMFLOAT4(0,0,0,1),
28 {},{.4f,.45f,.5f,57},gain),"shadowed orbital haze");
29 const auto pixels=pipeline.Pixels(gpu,scene,4);float maximum=0;
30 for(const auto& pixel:pixels)for(unsigned c=0;c<3;++c)
31 {
32 Check(std::isfinite(pixel.color[c]),"finite orbital night radiance");
33 maximum=(std::max)(maximum,pixel.color[c]);
34 }
35 if(!glow)Check(maximum==0,"unlit orbital haze must not invent light or terrain relief");
36 else if(nvg)Check(maximum>0,"real airglow remains visible through NVG");
37 }
38 }
39 }
40 DebugMessages(gpu);
41 std::cout<<"PASS: orbital night haze and NVG emission at 117/1000/3000 km\n";
42}
43
44
45
46
47static void TestOrganicLightingHandoff(Device11& gpu,CloudRenderer11&
renderer)
48{
49 Scene scene(gpu.Device(),4);Pipeline pipeline(gpu.Device(),4);
50 XMFLOAT4X4 view,projection;
51 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-.5f,-1,0),XMVectorSet(0,1,0,0)));
52 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1,float(Width)/Height,.001f,10000));
53 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
54 for(uint8_t convection:{uint8_t(0),uint8_t(127),uint8_t(255)})
55 {
56 auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({32,16,std::vector<uint8_t>(32*16,convection)});
58 HR(
renderer.PrepareResources(gpu.Context()),
"handoff weather upload");
renderer.UpdateWeather(map,60);
59 for(unsigned lighting=0;lighting<3;++lighting)for(float seam:{9.25f,9.5f,22.65f,22.85f,37.f,52.f})
60 {
62 std::vector<Sample> before;
63 for(float offset:{-.001f,.001f,-.001f})
64 {
65 renderer.ResetCloudHistory();scene.Clear(gpu.Context());
66
67
68 if(seam==9.25f)
69 {
70 HR(
renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
71 {0,cloud.radius+10.5f,0},cloud,{0,-1,0},{1,1,1,1},{.02f,.02f,.02f,1}),
72 "arm descending deck search");
73 scene.Clear(gpu.Context());
74 }
75 HR(
renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
76 {0,cloud.radius+seam+offset,0},cloud,lighting ? XMFLOAT3(0,1,0) : XMFLOAT3(.6f,-.8f,0),
77 {1,1,1,1},{.02f,.02f,.02f,1},{.125f,.375f,.25f,1},{},{},
78
79 lighting==2 ? XMFLOAT4(18.193232f,23.544182f,25.684563f,1) : XMFLOAT4(1,1,1,0)),"organic lighting handoff");
80 const auto now=pipeline.Pixels(gpu,scene,4);
81 if(!before.empty())
82 {
83 double difference=0,brightness=0;
84 for(size_t i=0;i<now.size();++i)for(unsigned c=0;c<3;++c)
85 {
86 Check(std::isfinite(now[i].color[c]),"finite upper lighting color");
87 difference+=std::abs(now[i].color[c]-before[i].color[c]);brightness+=now[i].color[c];
88 }
89 const double mean=difference/(now.size()*3);
90 std::cout<<"Lighting handoff weather="<<unsigned(convection)<<" mode="<<lighting<<" altitude="<<seam
91 <<" direction="<<(offset>0 ? "ascent" : "descent")<<" mean delta="<<mean<<'\n';
92 Check(mean<.02,"upper lighting transition must not pop across two meters");
93 if(!lighting)Check(brightness/(now.size()*3)>.05,"daylight handoff fixture must show clouds");
94 }
95 before=now;
96 }
97 }
98 }
99 DebugMessages(gpu);
100 std::cout<<"PASS: deck-search and upper lighting handoffs in daylight/night/NVG and quiet/moderate/strong convection\n";
101 TestOrganicNightExterior(gpu,
renderer);
102}
103
104
105static void TestOrganicTransitions(Device11& gpu,CloudRenderer11&
renderer,
float diagnosticAltitude=-1)
106{
107 Scene scene(gpu.Device(),4);
108 XMFLOAT4X4 view,projection;
109 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,-1,0),XMVectorSet(0,1,0,0)));
110 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1,float(Width)/Height,.001f,10000));
111 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
113 constexpr float flightScale=.5f,topScale=.25f,orbitScale=.5f;
116 const auto deckRays=unsigned(3440*deckScale)*unsigned(1351*deckScale);
117 Check(deckRays>103000 && deckRays<=105000,"ultrawide deck search has bounded ray work");
121 "invalid deck dimensions use the safe original grid");
123 const auto rays=[](float width,float height) {
125 return double(unsigned(width*scale))*unsigned(height*scale);
126 };
127 const double wideRays=rays(3440,1331),matchedRays=rays(3344,1882);
128 Check(wideRays>285000 && wideRays<=290000 && matchedRays>390000 && matchedRays<=395000,
129 "ultrawide orbit bounds ray work while larger targets retain the quarter-scale floor");
130 Check(
CloudOrbitResolution11(3440,1351)==.25f,
"ultrawide continuous-sheet rendering fits the supported quarter grid");
132 const double distantRays=double(unsigned(3440*distantScale))*unsigned(1351*distantScale);
133 Check(distantRays>355000 && distantRays<=360000,"distant orbit has bounded ray work");
135 const double globeRays=double(unsigned(3440*globeScale))*unsigned(1351*globeScale);
136 Check(globeRays>675000 && globeRays<=680000,"globe orbit has bounded denser sampling");
139 Check(!
CloudGlobeOrbit11(std::numeric_limits<float>::quiet_NaN(),
true),
"invalid altitude cannot retain globe sampling");
144 Check(!
CloudDistantOrbit11(std::numeric_limits<float>::quiet_NaN(),
true),
"invalid altitude cannot retain distant sampling");
146 Check(
renderer.OrganicReady(),
"complete matching organic renderer is available");
148 const auto render=[&](float altitude,float expected) {
149 std::cout<<
"Organic transition: altitude="<<altitude<<
" km organic="<<cloud.
organic<<
" base="<<cloud.
base<<
" km\n";
150 const auto frameStarted=GetTickCount64();
151 scene.Clear(gpu.Context());
152 HR(
renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
153 {0,cloud.radius+altitude,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1}),"organic quality transition");
154 Check(
renderer.Pass().ResolutionScale()==expected,
"organic orbit/re-entry quality hysteresis");
156 ? CloudPass11::OrganicPath::Top : CloudPass11::OrganicPath::Flight;
157 Check(
renderer.Pass().SelectedOrganicPath()==path,
"matching specialized field/march/composite selection");
158 Check(
renderer.Parameters().ZeroOrUnset(
"riseCloudRefinedSearch")
159 == !(path==CloudPass11::OrganicPath::Flight && expected==topScale),
160 "refined search and matching ray budget are selected together");
161
162
163 D3D11_QUERY_DESC description{D3D11_QUERY_EVENT,0};ComPtr<ID3D11Query> completion;
164 HR(gpu.Device()->CreateQuery(&description,&completion),"transition completion query");
165 gpu.Context()->End(completion.Get());gpu.Context()->Flush();
166 const auto started=GetTickCount64();
168 while((completed=gpu.Context()->GetData(completion.Get(),nullptr,0,D3D11_ASYNC_GETDATA_DONOTFLUSH))==S_FALSE)
169 {
170 HR(gpu.RemovalReason(),"transition device removal");
171 Check(GetTickCount64()-started<60000,"transition GPU completion timed out");
172 Sleep(1);
173 }
174 if(FAILED(completed))std::cerr<<"Transition device removal reason: 0x"<<std::hex<<unsigned(gpu.RemovalReason())<<std::dec<<'\n';
175 HR(completed,"transition GPU completion");DebugMessages(gpu);
176 std::cout<<"Transition draw and completion: "<<GetTickCount64()-frameStarted<<" ms wall time\n";
177 };
179 if(diagnosticAltitude>=0)
180 {
181 render(diagnosticAltitude,diagnosticAltitude>37 ? orbitScale : diagnosticAltitude>9.5f ? topScale : flightScale);
182 renderer.ReleaseSizeDependent();DebugMessages(gpu);
183 std::cout<<"PASS: single organic diagnostic draw completed on the GPU\n";
184 return;
185 }
186 for(const auto test:std::array<XMFLOAT2,23>{{{.1f,flightScale},{9,flightScale},{9.49f,flightScale},
187 {9.51f,topScale},{9.4f,topScale},{9.251f,topScale},{9.249f,flightScale},{9.4f,flightScale},
188 {9.51f,topScale},{10.3f,topScale},{10.64f,topScale},{10.66f,topScale},{18,topScale},{18.1f,topScale},
189 {17.8f,topScale},{17.49f,topScale},{18.1f,topScale},{22.64f,topScale},
190 {22.66f,topScale},{22.64f,topScale},{17.49f,topScale},{10.64f,topScale},{9,flightScale}}})render(test.x,test.y);
191 render(10.5f,topScale);
renderer.ResetCloudHistory();render(9.4f,flightScale);
192 for(const auto test:std::array<XMFLOAT2,13>{{{18,topScale},{31,topScale},{36,topScale},{38,orbitScale},{500,orbitScale},
193 {1000,orbitScale},{3000,orbitScale},{1000,orbitScale},{500,orbitScale},
194 {117,orbitScale},{34,orbitScale},{31,topScale},{36,topScale}}})render(test.x,test.y);
195 render(38,orbitScale);
196 renderer.ResetCloudHistory();render(35,topScale);
197 render(117,orbitScale);
199 renderer.ResetCloudHistory();render(117,flightScale);
200
201
202 cloud.
organic=
true;render(10.5f,topScale);cloud.
organic=
false;render(10.5f,flightScale);
205 renderer.ResetCloudHistory();render(117,orbitScale);
207 renderer.ResetCloudHistory();render(117,flightScale);
209 renderer.ResetCloudHistory();render(117,orbitScale);
210
211
212
213 auto localBase=std::make_shared<CloudBaseWeather::Grid>();
215 for(
auto& cell:localBase->cells)cell={cloud.
base,.5f,1,0};localBase->Bounds();
216 cloud.
localBase={localBase,1};render(117,flightScale);
217 render(10.5f,flightScale);
219 render(117,orbitScale);
221 cloud.
base=9.5f;render(117,flightScale);
222 renderer.ReleaseSizeDependent();DebugMessages(gpu);
223 std::cout<<"PASS: organic ascent/coast/orbit/re-entry hysteresis, reset, disable/re-enable and high-ceiling fallback\n";
224}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
bool Active(const Frame &frame)
float Weight(const Parameters ¶ms)
constexpr float MaxTopRiseKm
bool SelectOrganicMode(Parameters ¶ms, bool matchingRendererReady, bool simulator)
float CloudOrbitResolution11(float width, float height, bool distant=false, bool globe=false)
bool CloudGlobeOrbit11(float altitudeKm, bool wasGlobe)
bool CloudDistantOrbit11(float altitudeKm, bool wasDistant)
float CloudRefinedFlightResolution11(float width, float height)
CloudWeather::Frame weather
CloudBaseWeather::Frame localBase