1#include "NativeUiTest11.h"
2#include "../Viewscreen/CockpitLighting.h"
3#include "NightVisionDisplay11Tests.h"
4#include "NightVisionStars11Tests.h"
5#include <iostream>
6
8using Microsoft::WRL::ComPtr;
9namespace {
10unsigned checks=0;
11void Check(bool ok,const char* message) { ++checks; if(!ok)throw std::runtime_error(message); }
12float Energy(const std::vector<DWORD>& pixels) {
13 double sum=0; for(auto p:pixels)sum+=((p>>16)&255)+((p>>8)&255)+(p&255);
14 return float(sum/(pixels.size()*3));
15}
16}
17
18int main() try
19{
20 NativeUiTest11 fixture(64,64,false,false);
21 auto& device=fixture.device;auto& draws=device.Draws();
22 std::cout<<fixture.host.Device().Status()<<'\n';
23 struct Vertex {float x,y,z,nx,ny,nz,u,v;};
24 const Vertex vertices[]={{-1,1,.5f,0,0,1,0,0},{1,1,.5f,0,0,1,1,0},{-1,-1,.5f,0,0,1,0,1},
25 {-1,-1,.5f,0,0,1,0,1},{1,1,.5f,0,0,1,1,0},{1,-1,.5f,0,0,1,1,1}};
26 Geometry11 geometry;NativeUiTest11::HR(geometry.
Create(device.Native(),
sizeof(vertices),
false));
27 void* memory=
nullptr;NativeUiTest11::HR(geometry.
Lock(0,
sizeof(vertices),&memory));
28 memcpy(memory,vertices,
sizeof(vertices));NativeUiTest11::HR(geometry.
Unlock());
30 const auto texture=[&](const std::array<DWORD,4>& pixels) {
31 D3D11_TEXTURE2D_DESC desc{};desc.Width=4;desc.Height=desc.MipLevels=desc.ArraySize=desc.SampleDesc.Count=1;
32 desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
33 D3D11_SUBRESOURCE_DATA data{pixels.data(),16,16};
34 ComPtr<ID3D11Texture2D> image;ComPtr<ID3D11ShaderResourceView> view;
35 NativeUiTest11::HR(device.Native()->CreateTexture2D(&desc,&data,&image));
36 NativeUiTest11::HR(device.Native()->CreateShaderResourceView(image.Get(),nullptr,&view));return view;
37 };
38
39 const auto screen=texture({0xff000000,0xff20c0f0,0xffe08030,0xffa0a0a0});
40 const auto paint=texture({0xff303030,0xff404040,0xff505050,0xff606060});
41 const auto labels=texture({0xff000000,0xff000000,0xff000000,0xffffffff});
43 draws.BindScene();draws.Material(-1);draws.Fixed()=
FixedState11{};
45 state.lights[0].kind=1;state.lights[0].ambient={fill.
x,fill.
y,fill.
z,1};
48 state.textureFactor={lamp.x,lamp.y,lamp.z,1};
49 if(vision.clouds && !monitor)state.nightVisionSurface={vision.red,vision.green,vision.blue,1};
50
51
57 state.stages[1].texture=monitor ? screen : paint;
59 if(litLabels) {
62 state.stages[2].texture=labels;
63 }
64 for(auto& stage:state.stages)stage.sampler.Filter=D3D11_FILTER_MIN_MAG_MIP_POINT;
65 draws.Pipeline().raster.CullMode=D3D11_CULL_NONE;draws.Pipeline().depth.DepthEnable=FALSE;
66 draws.Pipeline().depth.StencilEnable=FALSE;draws.Pipeline().blend.RenderTarget[0].BlendEnable=FALSE;
67 device.Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),std::array<float,4>{}.data());
69 };
74 for(bool dome:{false,true}) for(float height:{-10.f,-.5f,0.f,.5f,1.f,20.f,100.f,20.f,1.f,0.f,-10.f}) {
75
76
78 const auto on=off;
79 const auto baseline=pixels(off,false,false,dome),assisted=pixels(on,false,false,dome,gain);
80 Check(Energy(assisted)>Energy(baseline)+2,"NVG brightens cockpit surfaces above and below deck with cabin lights on or off");
81 Check(pixels(off,true,false,dome)==pixels(on,true,false,dome,gain),"surface-light gain does not multiply separately rendered instrument pixels");
82 const auto marked=pixels(on,false,true,dome,gain);
83 for(unsigned y=4;y<60;++y) {
84 Check((marked[y*64+56]&0xffffff)==0xffffff,"emissive label remains white");
85 Check((marked[y*64+8]&255)<128,"painted panel stays dark enough to distinguish illuminated labels");
86 }
87 Check(baseline==pixels(off,false,false,dome),"removing goggles restores original cockpit pixels");
88 if(!dome) for(unsigned x:{8u,24u,40u,56u}) {
89 const auto p=assisted[32*64+x];
90 Check(((p>>16)&255)>8*(std::max)((p>>8)&255,p&255),
91 "red cabin light keeps a red cast on panels and monitor frames through ascent and descent");
92 }
93 Check(((assisted[32*64+56]>>16)&255)>((assisted[32*64+8]>>16)&255)+10,
94 "NVG preserves painted surface contrast rather than replacing it with a flat tint");
95 }
97 for(bool dome:{false,true}) {
98 Check(Energy(pixels(dark,false,false,dome,gain))>Energy(pixels(dark,false,false,dome))+2,
99 "zero atmospheric light still enhances reflected cabin illumination in orbit");
100 Check(pixels(dark,true,false,dome,gain)==pixels(dark,true,false,dome),"orbital cabin-light gain does not multiply separately rendered instrument pixels");
101 Check(pixels(dark,false,true,dome,gain)!=pixels(dark,false,true,dome),"labels remain separate while their orbital panel brightens");
102 }
103
104
105 const auto oldGray=pixels(enhanced,false,false,false,{},255.f/64);
106 const auto red=pixels(rawCloud,false,false,false,gain);
107 Check(((oldGray[32*64+40]>>8)&255)>50,"regression fixture reproduces the old neutral washout");
108 Check(((red[32*64+40]>>8)&255)<5,"mixed-light exposure removes the neutral washout");
109 std::cout<<"BCL panel RGB: old "<<((oldGray[32*64+40]>>16)&255)<<','<<((oldGray[32*64+40]>>8)&255)<<','<<(oldGray[32*64+40]&255)
110 <<"; repaired "<<((red[32*64+40]>>16)&255)<<','<<((red[32*64+40]>>8)&255)<<','<<(red[32*64+40]&255)<<'\n';
111 for(bool dome:{false,true}) {
114 Check(pixels(rawCloud,false,true,dome,reset)==pixels(rawCloud,false,true,dome),
115 "surface response clears for equipment/camera, simulator and daylight");
116 Check(Energy(pixels({0,0,0},false,false,dome,gain,0))==0,"unpowered cockpit in darkness gains no artificial light");
117 float previous=-1;
118 for(float power:{0.f,.000001f,.0001f,.01f,.1f,1.f}) {
119 const auto value=Energy(pixels({0,0,0},false,false,dome,gain,power));
120 Check(value>=previous,"dimming cannot brighten the assisted cabin");previous=value;
121 }
122 }
123 const auto unlit=pixels(rawCloud,false,false,false,gain,0);
124 Check(Energy(unlit)>Energy(pixels(rawCloud,false,false,false,{},0))+10,
125 "without cabin lamps, NVG still enhances faint outside fill");
126 Check(((unlit[32*64+40]>>16)&255)<(unlit[32*64+40]&255),"no synthetic red tint when the red lamp is off");
127
130 Check(pixels(edgeA,false,false,false,gain)==pixels(edgeB,false,false,false,gain),"cloud-top boundary has no visible step");
131 checks+=RunNightVisionDisplay11Tests(fixture);
132 checks+=RunNightVisionStars11Tests(fixture);
133 std::cout<<"PASS: "<<checks<<" native cockpit NVG surface, monitor, label, display optics, stars and round-trip checks.\n";
134 return 0;
135}
136catch(const std::exception& error) {std::cerr<<"FAIL: "<<error.what()<<'\n';return 1;}
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)
Point Scale(Point p, float s)
Point VehicleAmbient(Point cloudLight, Point skyLight, float altitudeAboveTop)
CloudVolume::Point Ambient(CloudVolume::Point cloudLight, CloudVolume::Point skyLight, float altitudeAboveTop, const NightVisionGain::Response &vision)
Response Calculate(bool active, bool simulator, float luminance)