Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/LocalLightning11Tests.cpp

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

1#include "NativeUiTest11.h"
2#include "../Viewscreen/LocalLightning.h"
3#include "../Viewscreen/NightVisionExposure.h"
4#include "../Rendering/ShaderBytecode11.h"
5#include "../Rendering/CloudRenderer11.h"
6#include <array>
7#include <chrono>
8#include <iostream>
9using namespace Rendering;
10using namespace DirectX;
11using Microsoft::WRL::ComPtr;
12namespace
13{
14 unsigned checks=0;
15 void Check(bool value,const char* message){++checks;if(!value)throw std::runtime_error(message);}
16 struct Vertex {XMFLOAT3 position,normal;DWORD diffuse,specular;XMFLOAT2 uv,logo;};
17 double Energy(const std::vector<DWORD>& pixels)
18 {double sum=0;for(auto p:pixels)sum+=(p&255)+((p>>8)&255)+((p>>16)&255);return sum/pixels.size()/3;}
19 template<class Draw> double CloudGpuTime(RenderDevice& device,Draw draw,unsigned drawCount=20)
20 {
21 ComPtr<ID3D11Query> disjoint,start,end;
22 D3D11_QUERY_DESC query{D3D11_QUERY_TIMESTAMP_DISJOINT,0};NativeUiTest11::HR(device.Native()->CreateQuery(&query,&disjoint));
23 query.Query=D3D11_QUERY_TIMESTAMP;NativeUiTest11::HR(device.Native()->CreateQuery(&query,&start));NativeUiTest11::HR(device.Native()->CreateQuery(&query,&end));
24 auto* context=device.Context();draw();
25 context->Begin(disjoint.Get());context->End(start.Get());
26 for(unsigned i=0;i<drawCount;++i)draw();
27 context->End(end.Get());context->End(disjoint.Get());context->Flush();
28 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT frequency{};UINT64 a=0,b=0;
29 while(context->GetData(disjoint.Get(),&frequency,sizeof(frequency),0)==S_FALSE)Sleep(1);
30 while(context->GetData(start.Get(),&a,sizeof(a),0)==S_FALSE)Sleep(1);
31 while(context->GetData(end.Get(),&b,sizeof(b),0)==S_FALSE)Sleep(1);
32 Check(!frequency.Disjoint,"GPU timestamps are valid");return 1000.*double(b-a)/frequency.Frequency/drawCount;
33 }
34}
35#include "CockpitLightning11Fixture.h"
36int main(int argc,char** argv)
37{
38 try
39 {
40 bool benchmark=false,warp=false;
41 std::string reference;
42 for(int i=1;i<argc;++i)
43 if(std::string(argv[i])=="--benchmark")benchmark=true;
44 else if(std::string(argv[i])=="--warp")warp=true;
45 else if(std::string(argv[i])=="--reference" && i+1<argc)reference=argv[++i];
46 else throw std::runtime_error("unknown argument");
47 // Keep linearity comparisons below display clipping, then separately
48 // exercise a real peak pulse on dark paint and in fog/clouds.
49 const auto make=[](float z=1,float strength=.2f,float visibility=0,bool enabled=true,bool separateFog=false) {
50 return LocalLightning::Build({0,3000,z},{0,3003,z},{0,3000,0},{0,0,0},
51 {.8f,.9f,1,1},strength/LocalLightning::PeakRadiance,visibility,enabled,separateFog);
52 };
53 const auto peak=LocalLightning::Build({0,3000,1},{0,3003,1},{0,3000,0},{0,0,0},{.8f,.9f,1,1},1,0,true);
54 Check(peak.color.w>1 && peak.color.w==LocalLightning::Radiance(1),"return-stroke radiance survives the normalized animation pulse");
55 Check(LocalLightning::Radiance(-1)==0 && LocalLightning::Radiance(2)==peak.color.w,"pulse input stays bounded without clipping light energy to one");
56 Check(LocalLightning::BoltVisibility(.8f,8,20)==1,"bright channel reaches display white through moderate haze");
57 Check(LocalLightning::BoltVisibility(.8f,100,10)<.001f && LocalLightning::BoltVisibility(0,0,20)==0,
58 "emissive bolt still fades with optical distance and vanishes at pulse end");
59 float exposure=0,hold=0;
60 NightVisionExposure::Update(true,LocalLightning::Radiance(.5f)*.1f,.02f,.016f,exposure,hold);
61 Check(exposure==1,"night vision responds to incident radiance instead of the unscaled animation pulse");
62 NightVisionExposure::Update(true,0,.02f,4,exposure,hold);
63 Check(exposure==0 && hold==0,"night vision recovers after an intense return stroke");
64 Check(make().ground.z==1 && make().top.y==3,"strike converts to the same physical frame as scene geometry");
65 Check(make(1,1,.75f,true,true).eye.w==1/.75f && make(1,1,.75f,true,true).up.w==1,
66 "separate fog retains the real source-to-surface extinction");
67 Check(make(1,1,10,false).color.w==0 && make(1,0).color.w==0,"disabled/simulator/finished pulses clear their shader state");
68 const auto translated=LocalLightning::Build({100,3000,1},{100,3003,1},{100,3000,0},{2,0,0},{1,1,1,1},.5f,10,true);
69 Check(translated.ground.z==1 && translated.ground.x==0 && translated.eye.x==2 && translated.eye.w==.1f,
70 "observer translation and camera offset do not change strike location");
71 NativeUiTest11 fixture(256,256,warp,!benchmark);
72 std::cout<<fixture.host.Device().Status()<<'\n';
73 CockpitLightningChecks(fixture,benchmark);
74 auto& device=fixture.device;auto& draws=device.Draws();auto& values=draws.Materials().Values();
75 const auto bindStrike=[&](const LocalLightning::Frame& frame) {
76 values.Set("StrikeGround",frame.ground);values.Set("StrikeTop",frame.top);values.Set("StrikeColor",frame.color);
77 values.Set("StrikeEye",frame.eye);values.Set("StrikeUp",frame.up);
78 };
79 XMFLOAT4X4 projection;XMStoreFloat4x4(&projection,XMMatrixScaling(10,10,1)*XMMatrixTranslation(0,0,.5f));
80 values.Set("matWorldViewProj",projection);values.Set("ambient",XMFLOAT4(0,0,0,100000));
81 values.Set("Tangent",XMFLOAT4(1,1,1,0));values.Set("Sunlight",XMFLOAT4(0,0,0,0));
82 values.Set("Radiosity",XMFLOAT4(0,0,-1,0));values.Set("WeapPos",XMFLOAT4(0,0,0,0));
83 values.Set("shiplight",XMFLOAT4(0,0,0,0));values.Set("clouduv",XMFLOAT4(0,0,0,0));
84 values.Set("volumeFog",XMFLOAT4(0,0,0,0));values.Set("LandingLightCount",0);values.Set("ShipSurfaceLightCount",0);
85 values.Set("TerrainDetail",XMFLOAT4(0,0,0,0));values.Set("CityOverlayEnabled",0);
86 std::array<ComPtr<ID3D11ShaderResourceView>,3> textures;
87 for(unsigned i=0;i<3;++i)
88 {
89 D3D11_TEXTURE2D_DESC td{};td.Width=td.Height=td.MipLevels=td.ArraySize=td.SampleDesc.Count=1;
90 td.Format=DXGI_FORMAT_R8G8B8A8_UNORM;td.BindFlags=D3D11_BIND_SHADER_RESOURCE;
91 DWORD pixel=i==2 ? 0xff202020 : i ? 0xff000000 : 0xffffffff;D3D11_SUBRESOURCE_DATA data{&pixel,4,4};
92 ComPtr<ID3D11Texture2D> texture;NativeUiTest11::HR(device.Native()->CreateTexture2D(&td,&data,&texture));
93 NativeUiTest11::HR(device.Native()->CreateShaderResourceView(texture.Get(),nullptr,&textures[i]));
94 }
95 for(const char* name:{"ColorMap","ColorMap2","CloudMap","ColorMap3","ColorMap4"})values.Texture(name,textures[0].Get());
96 values.Texture("AlphaMap",textures[1].Get());
97 D3D11_TEXTURE3D_DESC volumeDesc{};volumeDesc.Width=volumeDesc.Height=volumeDesc.Depth=volumeDesc.MipLevels=1;
98 volumeDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;volumeDesc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
99 DWORD volumePixel=0;D3D11_SUBRESOURCE_DATA volumeData{&volumePixel,4,4};
100 ComPtr<ID3D11Texture3D> volume;ComPtr<ID3D11ShaderResourceView> volumeView;
101 NativeUiTest11::HR(device.Native()->CreateTexture3D(&volumeDesc,&volumeData,&volume));
102 NativeUiTest11::HR(device.Native()->CreateShaderResourceView(volume.Get(),nullptr,&volumeView));
103 values.Texture("ColorMap3Volume",volumeView.Get());
104 Geometry11 mesh;NativeUiTest11::HR(mesh.Create(device.Native(),6*sizeof(Vertex),false));
105 VertexLayout11 layout;layout.stride=sizeof(Vertex);layout.normal=12;layout.diffuse=24;layout.specular=28;layout.uv[0]=32;layout.uv[1]=40;
106 std::array<Program11,12> old;
107 if(!reference.empty())for(unsigned pass:{0u,1u,2u,3u,4u,5u,11u})
108 {
109 const auto vs=ReadShaderBytecode11(reference+"/CustomUI-VS"+std::to_string(pass)+"-1.cso");
110 const auto ps=ReadShaderBytecode11(reference+"/CustomUI-PS"+std::to_string(pass)+"-1.cso");
111 NativeUiTest11::HR(old[pass].Create(device.Native(),vs.data(),vs.size(),ps.data(),ps.size()));
112 }
113 const auto draw=[&](unsigned pass,const LocalLightning::Frame& strike,float z=5,float normal=-1,unsigned albedo=0,bool baseline=false) {
114 bindStrike(strike);
115 XMFLOAT4X4 world;XMStoreFloat4x4(&world,XMMatrixTranslation(0,0,z));values.Set("matWorld",world);
116 values.Set("Features",XMFLOAT4(pass==4 || pass==5 ? 1.f : 0.f,0,pass==5 ? 1.f : 0.f,0));
117 values.Texture("ColorMap",textures[albedo].Get());
118 const Vertex vertices[]={
119 {{-.1f,.1f,0},{0,0,normal},0xffffffff,0,{0,0},{0,0}},{{.1f,.1f,0},{0,0,normal},0xffffffff,0,{1,0},{0,0}},
120 {{-.1f,-.1f,0},{0,0,normal},0xffffffff,0,{0,1},{0,0}},{{-.1f,-.1f,0},{0,0,normal},0xffffffff,0,{0,1},{0,0}},
121 {{.1f,.1f,0},{0,0,normal},0xffffffff,0,{1,0},{0,0}},{{.1f,-.1f,0},{0,0,normal},0xffffffff,0,{1,1},{0,0}}};
122 void* dest=nullptr;NativeUiTest11::HR(mesh.Lock(0,sizeof(vertices),&dest));memcpy(dest,vertices,sizeof(vertices));NativeUiTest11::HR(mesh.Unlock());
123 draws.BindScene();device.Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),std::array<float,4>{}.data());
124 draws.Pipeline().raster.CullMode=D3D11_CULL_NONE;draws.Pipeline().depth.DepthEnable=FALSE;
125 draws.Pipeline().blend.RenderTarget[0].BlendEnable=FALSE;
126 auto actualLayout=layout;
127 if(pass>=2)actualLayout.diffuse=actualLayout.specular=VertexLayout11::Absent;
128 if(pass==2 || pass==3)actualLayout.normal=VertexLayout11::Absent;
129 draws.Material(pass);
130 if(FAILED(draws.Draw(mesh,actualLayout,Primitive11::Triangles,0,2)))
131 throw std::runtime_error("material "+std::to_string(pass)+": "+draws.Materials().Status());
132 if(baseline)
133 {
134 ComPtr<ID3D11InputLayout> input;device.Context()->IAGetInputLayout(&input);
135 NativeUiTest11::HR(old[pass].Bind(device.Context(),values));device.Context()->IASetInputLayout(input.Get());
136 device.Context()->Draw(6,0);
137 }
138 };
139 const auto pixels=[&](unsigned pass,const LocalLightning::Frame& strike,float z=5,float normal=-1,unsigned albedo=0,bool baseline=false) {
140 draw(pass,strike,z,normal,albedo,baseline);return fixture.Pixels();
141 };
142 std::filesystem::create_directories("outputs/local-lightning");
143 for(unsigned pass:{0u,1u,2u,3u,4u,5u,11u})
144 {
145 const auto off=pixels(pass,{});
146 if(!reference.empty())Check(off==pixels(pass,{},5,-1,false,true),"inactive lightning preserves every baseline pixel");
147 const double front=Energy(pixels(pass,make()));
148 fixture.Save("outputs/local-lightning/front-"+std::to_string(pass)+".png");
149 const double back=Energy(pixels(pass,make(9)));
150 fixture.Save("outputs/local-lightning/back-"+std::to_string(pass)+".png");
151 Check(front>back*3 && back>1,"strike-facing surfaces receive the peak; reverse faces retain weak cloud fill");
152 if(pass==2 || pass==3)Check(std::abs(front-Energy(pixels(4,make())))<1,
153 "small derivative normals match authored hull normals at the same pose");
154 Check(Energy(pixels(pass,make(100)))<.1,"distant strikes do not change global ambient");
155 const double half=Energy(pixels(pass,make(1,.1f)));
156 Check(std::abs(half/front-.5)<.025,"light follows the same pulse/intensity linearly");
157 Check(off==pixels(pass,{}),"ending the flash removes all direct, fill and fog contributions");
158 const double clearSurface=Energy(pixels(pass,make(1,.2f,42,true,true),.2f,1));
159 const double denseSurface=Energy(pixels(pass,make(1,.2f,.75f,true,true),.2f,1));
160 Check(denseSurface<clearSurface*.4,
161 "750 m fog attenuates both direct and cloud-bounce surface light");
162 if(pass>=2 && pass<=5)
163 Check(Energy(pixels(pass,make(1,1,.75f,true,true),5,-1,1))==0,
164 "spatial fog suppresses material scattering without disabling surface extinction");
165 if(pass==4 || pass==5)Check(Energy(pixels(pass,make(),5,1))<front/3,"hull normals reject direct light on reverse faces");
166 auto high=make();high.ground.y-=100;high.top.y-=100;
167 Check(Energy(pixels(pass,high))<.1,"local strike cannot illuminate orbital surfaces through the cloud deck");
168 std::cout<<"PASS material "<<pass<<": facing="<<front<<", reverse="<<back<<", half="<<half<<'\n';
169 }
170 for(unsigned pass:{2u,3u,4u,5u})
171 {
172 const double facing=Energy(pixels(pass,peak,5,-1,2));
173 auto reverse=peak;reverse.ground.z=reverse.top.z=9;
174 const double fill=Energy(pixels(pass,reverse,5,-1,2));
175 Check(facing>240 && facing>fill*3 && fill>15,"peak lights dark paint intensely while preserving weaker reverse-face cloud fill");
176 auto distant=peak;distant.ground.z=distant.top.z=100;
177 Check(Energy(pixels(pass,distant,5,-1,2))<.1,"full-power strike does not globally illuminate distant dark paint");
178 auto haze=peak;haze.eye.w=.05f;haze.ground.z=haze.top.z=4;
179 Check(Energy(pixels(pass,haze,10,-1,1))>80,"peak radiance also drives visible atmospheric scattering");
180 }
181 for(unsigned pass:{2u,3u,4u,5u})
182 {
183 const double fog=Energy(pixels(pass,make(4,1,20),10,-1,true));
184 const double foreground=Energy(pixels(pass,make(4,1,20),.01f,-1,true));
185 Check(fog>2 && foreground<.1,"fog integrates the visible path and stops at foreground geometry");
186 Check(Energy(pixels(pass,make(4,1,0),10,-1,true))==0,"no fog scattering in vacuum");
187 auto away=make(4,1,20);away.ground.x=away.top.x=100;
188 Check(Energy(pixels(pass,away,10,-1,true))<fog*.1,"fog glow stays around the bolt bearing");
189 std::cout<<"PASS fog "<<pass<<": visible="<<fog<<", foreground="<<foreground<<'\n';
190 }
191 if(benchmark)
192 {
193 fixture.Resize(1920,1080);
194 ComPtr<ID3D11Query> disjoint,start,end;
195 D3D11_QUERY_DESC q{D3D11_QUERY_TIMESTAMP_DISJOINT,0};NativeUiTest11::HR(device.Native()->CreateQuery(&q,&disjoint));
196 q.Query=D3D11_QUERY_TIMESTAMP;NativeUiTest11::HR(device.Native()->CreateQuery(&q,&start));NativeUiTest11::HR(device.Native()->CreateQuery(&q,&end));
197 const auto time=[&](unsigned pass,const LocalLightning::Frame& frame,bool baseline) {
198 draw(pass,frame,5,-1,false,baseline);
199 auto* context=device.Context();for(int i=0;i<20;++i)context->Draw(6,0);
200 context->Begin(disjoint.Get());context->End(start.Get());
201 for(int i=0;i<200;++i)context->Draw(6,0);
202 context->End(end.Get());context->End(disjoint.Get());context->Flush();
203 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT frequency{};UINT64 a=0,b=0;
204 while(context->GetData(disjoint.Get(),&frequency,sizeof(frequency),0)==S_FALSE)Sleep(1);
205 while(context->GetData(start.Get(),&a,sizeof(a),0)==S_FALSE)Sleep(1);
206 while(context->GetData(end.Get(),&b,sizeof(b),0)==S_FALSE)Sleep(1);
207 Check(!frequency.Disjoint,"GPU timestamps are valid");return 1000.*double(b-a)/frequency.Frequency/200;
208 };
209 for(unsigned pass:{2u,3u,4u,5u})
210 {
211 std::array<double,5> before{},off{},on{};
212 for(unsigned i=0;i<5;++i)
213 {
214 if(!reference.empty())before[i]=time(pass,{},true);
215 off[i]=time(pass,{},false);on[i]=time(pass,make(1,.2f,20),false);
216 }
217 std::sort(before.begin(),before.end());std::sort(off.begin(),off.end());std::sort(on.begin(),on.end());
218 std::cout<<"GPU 1920x1080 pass "<<pass<<" median ms: baseline="<<before[2]<<", inactive="<<off[2]<<", flash="<<on[2]<<'\n';
219 }
220 auto begin=std::chrono::steady_clock::now();float sum=0;
221 for(unsigned i=0;i<1000000;++i)
222 {
223 const float x=float(i%100)*.01f;
224 const auto frame=LocalLightning::Build({x,3000,1},{x,3003,1},{0,3000,0},{x,0,0},
225 {.8f,.9f,1,1},.2f,20+x,true);
226 sum+=frame.up.y+frame.up.x+frame.top.x+frame.eye.w;
227 }
228 const auto ns=std::chrono::duration<double,std::nano>(std::chrono::steady_clock::now()-begin).count()/1000000;
229 std::cout<<"CPU strike setup ns="<<ns<<" checksum="<<sum<<'\n';
230 }
231 // Exercise the production volume pass with the same local channel.
232 fixture.Resize(256,256);
233 CloudRenderer11 clouds;NativeUiTest11::HR(clouds.Initialize(device.Native()));
234 CloudVolume::Parameters cloud;cloud.base=3;cloud.activity=1;
235 XMFLOAT4X4 view,cloudProjection;
236 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,1,0,0),XMVectorSet(0,0,1,0)));
237 XMStoreFloat4x4(&cloudProjection,XMMatrixPerspectiveFovRH(1.2f,1,.001f,100));
238 D3D11_VIEWPORT viewport{0,0,256,256,0,1};
239 const auto drawCloud=[&](CloudRenderer11& renderer,float offset,float brightness,bool enabled,UINT stencil,float depth) {
240 device.Context()->ClearState();
241 device.Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),std::array<float,4>{}.data());
242 device.Context()->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,depth,UINT8(stencil));
243 renderer.SetLightningEnabled(enabled);
244 renderer.SetLocalLightning({offset,cloud.radius+3,0},{brightness*.8f,brightness*.9f,brightness,1},12,{offset,cloud.radius,0});
245 if(FAILED(renderer.Render(device.Context(),fixture.host.Device().SceneTarget(),fixture.host.Device().Depth(),viewport,
246 view,cloudProjection,{0,cloud.radius+.5f,0},cloud,{0,1,0},{0,0,0,1},{0,0,0,1},{0,0,0,1},{0,0,0,30})))
247 throw std::runtime_error("cloud draw: "+renderer.InitializationStatus());
248 };
249 const auto renderCloud=[&](float offset,float brightness,bool enabled,UINT stencil=0,float depth=1) {
250 drawCloud(clouds,offset,brightness,enabled,stencil,depth);
251 return fixture.Pixels();
252 };
253 const auto calm=renderCloud(0,0,true);
254 const double litCloud=Energy(renderCloud(0,.5f,true));
255 fixture.Save("outputs/local-lightning/cloud-near.png");
256 const double farCloud=Energy(renderCloud(100,.5f,true));
257 Check(litCloud>Energy(calm)+5 && farCloud<litCloud*.1,"cloud illumination stays at the same bolt endpoint");
258 Check(renderCloud(0,0,true)==calm && renderCloud(0,.5f,false)==calm,"cloud pulse reset and simulator disable clear both volume light and fog");
259 Check(Energy(renderCloud(0,.5f,true,3))==0,"lightning cloud/fog preserves cockpit stencil");
260 Check(Energy(renderCloud(0,.5f,true,0,0))==0,"lightning cloud/fog preserves foreground depth");
261 std::cout<<"PASS clouds: nearby="<<litCloud<<", distant="<<farCloud<<'\n';
262 // Ground observer looking at a bolt 12 km away through 6 km haze.
263 // The cloud around its upper end is beyond the ordinary fog cutoff.
264 const auto drawSky=[&](CloudRenderer11& renderer,float offset,float brightness,UINT stencil=0,float depth=1) {
265 device.Context()->ClearState();
266 device.Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),std::array<float,4>{}.data());
267 device.Context()->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,depth,UINT8(stencil));
268 XMFLOAT4X4 skyView;
269 XMStoreFloat4x4(&skyView,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,2.95f,-12,0),XMVectorSet(0,1,0,0)));
270 renderer.SetLightningEnabled(true);
271 renderer.SetLocalLightning({offset,cloud.radius+3,-12},{brightness*.8f,brightness*.9f,brightness,1},12,{offset,cloud.radius,-12});
272 NativeUiTest11::HR(renderer.Render(device.Context(),fixture.host.Device().SceneTarget(),fixture.host.Device().Depth(),viewport,
273 skyView,cloudProjection,{0,cloud.radius+.05f,0},cloud,{0,1,0},{0,0,0,1},{0,0,0,1},{0,0,0,1},{0,0,0,6}));
274 };
275 const auto skyPixels=[&](float offset,float brightness,UINT stencil=0,float depth=1) {
276 drawSky(clouds,offset,brightness,stencil,depth);return fixture.Pixels();
277 };
278 const auto darkSky=skyPixels(0,0);
279 const auto brightSky=skyPixels(0,.5f);
280 fixture.Save("outputs/local-lightning/sky-glow.png");
281 const auto skyPatch=[](const std::vector<DWORD>& pixels,unsigned x,unsigned y) {
282 double sum=0;
283 for(unsigned row=y-8;row<y+8;++row)for(unsigned column=x-8;column<x+8;++column)
284 {const auto p=pixels[row*256+column];sum+=(p&255)+((p>>8)&255)+((p>>16)&255);}
285 return sum/(16*16*3);
286 };
287 const double upperGlow=skyPatch(brightSky,128,96);
288 Check(upperGlow>20 && skyPatch(brightSky,96,112)>20 && skyPatch(brightSky,160,112)>20,
289 "cloud glow surrounds the upper bolt on both sides beyond the fog cutoff");
290 Check(Energy(skyPixels(100,.5f))<Energy(brightSky)*.1,"sky glow follows the strike position without global ambient brightening");
291 Check(skyPixels(0,0)==darkSky,"sky glow ends exactly with the pulse");
292 Check(Energy(skyPixels(0,.5f,3))==0 && Energy(skyPixels(0,.5f,0,0))==0,
293 "sky glow respects cockpit stencil and foreground depth");
294 if(!reference.empty())
295 {
296 CloudRenderer11 baseline;NativeUiTest11::HR(baseline.Initialize(device.Native(),reference));
297 drawSky(baseline,0,.5f);
298 const auto original=fixture.Pixels();fixture.Save("outputs/local-lightning/sky-before.png");
299 Check(upperGlow>skyPatch(original,128,96)+20,"emissive sky glow survives haze that erased it previously");
300 drawSky(baseline,0,0);
301 Check(fixture.Pixels()==darkSky,"inactive sky remains pixel-identical to the previous renderer");
302 std::cout<<"PASS sky upper glow: before="<<skyPatch(original,128,96)<<", after="<<upperGlow<<'\n';
303 }
304 if(benchmark && !reference.empty())
305 {
306 clouds.ReleaseSizeDependent();fixture.Resize(1920,1080);viewport.Width=1920;viewport.Height=1080;
307 CloudRenderer11 baseline;
308 if(FAILED(baseline.Initialize(device.Native(),reference)))throw std::runtime_error("cloud reference: "+baseline.InitializationStatus());
309 std::array<double,5> before{},off{},on{},skyBefore{},skyAfter{};
310 for(unsigned i=0;i<5;++i)
311 {
312 before[i]=CloudGpuTime(device,[&]{drawCloud(baseline,0,.5f,true,0,1);});
313 off[i]=CloudGpuTime(device,[&]{drawCloud(clouds,0,0,true,0,1);});
314 on[i]=CloudGpuTime(device,[&]{drawCloud(clouds,0,.5f,true,0,1);});
315 skyBefore[i]=CloudGpuTime(device,[&]{drawSky(baseline,0,.5f);});
316 skyAfter[i]=CloudGpuTime(device,[&]{drawSky(clouds,0,.5f);});
317 }
318 std::sort(before.begin(),before.end());std::sort(off.begin(),off.end());std::sort(on.begin(),on.end());
319 std::cout<<"GPU 1920x1080 clouds median ms: original flash="<<before[2]<<", inactive="<<off[2]<<", flash="<<on[2]<<'\n';
320 std::sort(skyBefore.begin(),skyBefore.end());std::sort(skyAfter.begin(),skyAfter.end());
321 std::cout<<"GPU 1920x1080 hazy sky median ms: before="<<skyBefore[2]<<", after="<<skyAfter[2]<<'\n';
322 }
323 if(!benchmark)fixture.DebugClean();
324 std::cout<<"PASS: "<<checks<<" local lightning checks\n";return 0;
325 }
326 catch(const std::exception& e){std::cerr<<"FAIL: "<<e.what()<<'\n';return 1;}
327}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
const std::string & InitializationStatus() const
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
Materials11 & Materials()
HRESULT Create(ID3D11Device *device, UINT bytes, bool dynamic, bool index=false, bool indices32=false)
HRESULT Lock(UINT offset, UINT size, void **destination, bool readOnly=false, bool discard=false)
Parameters11 & Values()
Definition Materials11.h:14
DrawContext11 & Draws()
ID3D11DeviceContext * Context()
Definition DDS.h:24
Sources Create(int count, Kind kind, float sideArmKm, float forwardKm)
Definition EngineAudio.h:55
float BoltVisibility(float pulse, float distanceKm, float visibilityKm)
Frame Build(const RiseMath::Vector3 &ground, const RiseMath::Vector3 &top, const RiseMath::Vector3 &origin, const RiseMath::Vector3 &camera, const RiseMath::Color &color, float brightness, float visibilityKm, bool enabled, bool separateFog=false)
constexpr float PeakRadiance
float Radiance(float pulse)
void Update(bool active, float flashStimulus, float ambientLuminance, float elapsedSeconds, float &exposure, float &holdSeconds)
std::vector< char > ReadShaderBytecode11(const std::filesystem::path &path, HMODULE resourceModule=nullptr)
void Bind(Rendering::RenderDevice &device, Rendering::RenderTexture *texture)
RiseMath::Vector4 up
static constexpr UINT Absent
Definition Geometry11.h:13