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

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

1#include "NativeUiTest11.h"
2#include "../Rendering/FogBeams11.h"
3#include "../Rendering/CloudRenderer11.h"
4#include "../Viewscreen/LandingLights.h"
5#include <chrono>
6#include <fstream>
7#include <iomanip>
8#include <iostream>
9#include <d3dcompiler.h>
10using namespace Rendering;
11using namespace DirectX;
12using Microsoft::WRL::ComPtr;
13namespace
14{
15 unsigned checks=0;
16 ID3D11Device* diagnosticDevice=nullptr;
17 void FogHR(int line,HRESULT result)
18 {if(FAILED(result))throw std::runtime_error("fog test line "+std::to_string(line)+" HRESULT="+std::to_string(result)+" removal="+std::to_string(diagnosticDevice ? diagnosticDevice->GetDeviceRemovedReason() : S_OK));}
19 void Check(bool value,const char* message){++checks;if(!value)throw std::runtime_error(message);}
20 using Clock=std::chrono::steady_clock;
21 double Milliseconds(Clock::time_point a,Clock::time_point b){return std::chrono::duration<double,std::milli>(b-a).count();}
22 double Percentile(std::vector<double> values,double p){std::sort(values.begin(),values.end());return values[size_t(p*(values.size()-1))];}
23 double Energy(const std::vector<DWORD>& pixels){double sum=0;for(auto p:pixels)sum+=(p>>8)&255;return sum/pixels.size();}
24 std::vector<DWORD> ResolvedPixels(RenderDevice& d)
25 {
26 D3D11_TEXTURE2D_DESC desc{};d.Owner().SceneColor()->GetDesc(&desc);
27 ComPtr<ID3D11Texture2D> resolved,staging;
28 desc.SampleDesc={1,0};desc.BindFlags=desc.MiscFlags=0;FogHR(__LINE__,d.Native()->CreateTexture2D(&desc,nullptr,&resolved));
29 if(d.Owner().Depth().Description().SampleDesc.Count>1)d.Context()->ResolveSubresource(resolved.Get(),0,d.Owner().SceneColor(),0,desc.Format);
30 else d.Context()->CopyResource(resolved.Get(),d.Owner().SceneColor());
31 desc.Usage=D3D11_USAGE_STAGING;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;
32 FogHR(__LINE__,d.Native()->CreateTexture2D(&desc,nullptr,&staging));d.Context()->CopyResource(staging.Get(),resolved.Get());
33 D3D11_MAPPED_SUBRESOURCE map{};FogHR(__LINE__,d.Context()->Map(staging.Get(),0,D3D11_MAP_READ,0,&map));
34 std::vector<DWORD> result(size_t(desc.Width)*desc.Height);
35 for(UINT y=0;y<desc.Height;++y)memcpy(result.data()+size_t(y)*desc.Width,static_cast<const BYTE*>(map.pData)+size_t(y)*map.RowPitch,desc.Width*4);
36 d.Context()->Unmap(staging.Get(),0);return result;
37 }
38 struct LegacyVertex {float x,y,z;DWORD diffuse;XMFLOAT2 uv;};
39 class Legacy
40 {
41 ComPtr<RenderBuffer> vertices;
42 public:
43 explicit Legacy(RenderDevice& d){FogHR(__LINE__,d.CreateVertexBuffer(LandingLights::FogVertexCount*sizeof(LegacyVertex),0,
44 VertexFormat::XYZ|VertexFormat::DIFFUSE|VertexFormat::TEX1,ResourcePool::Managed,&vertices,nullptr));}
45 void Draw(RenderDevice& d,const XMFLOAT4X4& view,const XMFLOAT4X4& projection,const std::vector<FogBeams11::Light>& lights,
46 const CloudVolume::Parameters* clouds=nullptr)
47 {
48 auto set=[&](DWORD key,DWORD value){FogHR(__LINE__,d.SetRenderState(key,value));};
49 set(RenderState::LIGHTING,false);set(RenderState::FOGENABLE,false);set(RenderState::ZENABLE,true);
50 set(RenderState::ZWRITEENABLE,false);set(RenderState::ZFUNC,Compare::LESSEQUAL);
51 set(RenderState::ALPHABLENDENABLE,true);set(RenderState::SRCBLEND,Blend::SRCALPHA);set(RenderState::DESTBLEND,Blend::ONE);
52 set(RenderState::CULLMODE,Cull::NONE);set(RenderState::STENCILENABLE,false);
53 FogHR(__LINE__,d.SetTexture(0,nullptr));FogHR(__LINE__,d.SetFVF(VertexFormat::XYZ|VertexFormat::DIFFUSE|VertexFormat::TEX1));
54 FogHR(__LINE__,d.SetStreamSource(0,vertices.Get(),0,sizeof(LegacyVertex)));
55 const RiseMath::Matrix legacyView(view),legacyProjection(projection);
56 FogHR(__LINE__,d.SetTransform(TransformSlot::VIEW,&legacyView));FogHR(__LINE__,d.SetTransform(TransformSlot::PROJECTION,&legacyProjection));
57 for(auto light:lights)
58 {
59 if(light.color.w<=0)continue;
60 if(clouds)
61 {
62 const CloudVolume::Point source{light.position.x,clouds->radius+.05f+light.position.y,light.position.z};
63 const auto end=CloudVolume::Add(source,{light.direction.x*light.profile.rangeKm,light.direction.y*light.profile.rangeKm,light.direction.z*light.profile.rangeKm});
64 light.color.w*=CloudVolume::Transmittance(source,end,*clouds);
65 }
66 LandingLights::Light source;source.profile=light.profile;source.extinctionPerKm=light.extinctionPerKm;
67 const auto up=XMLoadFloat3(&light.up),direction=XMLoadFloat3(&light.direction),right=XMVector3Cross(direction,up);
68 XMFLOAT4X4 world;XMStoreFloat4x4(&world,XMMatrixIdentity());
69 XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&world._11),right);
70 XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&world._21),up);
71 XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&world._31),XMVectorNegate(direction));
72 world._41=light.position.x;world._42=light.position.y;world._43=light.position.z;
73 const RiseMath::Matrix legacyWorld(world);FogHR(__LINE__,d.SetTransform(TransformSlot::WORLD,&legacyWorld));
74 set(RenderState::TEXTUREFACTOR,RiseMath::Color(light.color.x,light.color.y,light.color.z,light.color.w));
75 FogHR(__LINE__,d.SetTextureStageState(0,TextureState::COLOROP,TextureOperation::SELECTARG1));
76 FogHR(__LINE__,d.SetTextureStageState(0,TextureState::COLORARG1,TextureArgument::TFACTOR));
77 FogHR(__LINE__,d.SetTextureStageState(0,TextureState::ALPHAOP,TextureOperation::MODULATE));
78 FogHR(__LINE__,d.SetTextureStageState(0,TextureState::ALPHAARG1,TextureArgument::TFACTOR));
79 FogHR(__LINE__,d.SetTextureStageState(0,TextureState::ALPHAARG2,TextureArgument::DIFFUSE));
80 for(bool spill:{false,true})
81 {
82 LegacyVertex* data=nullptr;FogHR(__LINE__,vertices->Lock(0,0,reinterpret_cast<void**>(&data),0));
83 LandingLights::FogMesh(source,data,spill);FogHR(__LINE__,vertices->Unlock());
84 FogHR(__LINE__,d.DrawPrimitive(Primitive::TriangleList,0,LandingLights::FogVertexCount/3));
85 }
86 }
87 }
88 };
89 FogBeams11::Light Road(float x=0)
90 {
91 FogBeams11::Light light;light.position={x,-.002f,-.003f};light.profile=LandingLights::RoadLow;
92 light.extinctionPerKm=3.912f/.5f;light.color={1,1,.8f,.9f};return light;
93 }
94 FogBeams11::Light Crossing()
95 {
96 FogBeams11::Light light;light.position={-.04f,-.008f,-.08f};light.direction={1,0,0};
98 light.extinctionPerKm=3.912f/.5f;light.color={1,1,.8f,.9f};return light;
99 }
100 // Independent dense integration over the entire finite light sphere. It
101 // deliberately does not use the shader's cone intersection or importance map.
102 double Reference(FogBeams11::Light light,XMFLOAT3 ray,float limit)
103 {
104 LandingLights::Light lamp;lamp.origin=light.position;lamp.direction=light.direction;lamp.up=light.up;
105 lamp.profile=light.profile;lamp.extinctionPerKm=light.extinctionPerKm;
106 const double end=(std::min)(double(limit),double(XMVectorGetX(XMVector3Length(XMLoadFloat3(&light.position))))+light.profile.rangeKm);
107 const double step=end/60000;double result=0;
108 for(unsigned i=0;i<60000;++i)
109 {
110 const double t=step*(i+.5);RiseMath::Vector3 delta(float(ray.x*t-light.position.x),float(ray.y*t-light.position.y),float(ray.z*t-light.position.z));
111 const float distance=RiseMath::Vec3Length(&delta);if(distance<1e-8f)continue;
112 const double cosine=(-ray.x*delta.x-ray.y*delta.y-ray.z*delta.z)/distance;
113 const double phase=(1-.55*.55)/std::pow(1-.55*cosine,2)*.25;
114 // Fog receives the authored inverse-square incident light before
115 // any surface-display clamp. Compute it independently of the GPU
116 // beamDistance helper and the capped legacy surface-light helper.
117 const float axial=RiseMath::Vec3Dot(&delta,&lamp.direction);
118 if(axial<=0)continue;
119 RiseMath::Vector3 right;RiseMath::Vec3Cross(&right,&lamp.direction,&lamp.up);
120 const double spot=LandingLights::Angular(lamp.profile,RiseMath::Vec3Dot(&delta,&right)/axial,
121 RiseMath::Vec3Dot(&delta,&lamp.up)/axial,axial);
122 const double irradiance=LandingLights::IlluminanceLux(lamp.profile,distance)/20;
123 result+=spot*irradiance*std::exp(-light.extinctionPerKm*(t+distance))*light.extinctionPerKm*step*phase*light.color.y*light.color.w;
124 }
125 return result*255;
126 }
127 struct Timing{double cpu50,cpu95,gpu50,gpu95;};
128 void Cover(RenderDevice& d,const D3D11_RECT& rectangle,unsigned stencilValue,UINT sampleMask=UINT_MAX,bool writeDepth=true)
129 {
130 const char source[]="float4 V(uint id:SV_VertexID):SV_Position{return float4(id==2?3:-1,id==1?3:-1,0,1);} float4 P():SV_Target{return 0;}";
131 ComPtr<ID3DBlob> vs,ps;FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"V","vs_5_0",0,0,&vs,nullptr));
132 FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"P","ps_5_0",0,0,&ps,nullptr));
133 Program11 cover;FogHR(__LINE__,cover.Create(d.Native(),vs->GetBufferPointer(),vs->GetBufferSize(),ps->GetBufferPointer(),ps->GetBufferSize()));
134 D3D11_DEPTH_STENCIL_DESC ds{};ds.DepthEnable=writeDepth;ds.DepthWriteMask=writeDepth ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;ds.DepthFunc=D3D11_COMPARISON_ALWAYS;
135 ds.StencilEnable=stencilValue!=0;ds.StencilWriteMask=255;
136 ds.FrontFace={D3D11_STENCIL_OP_REPLACE,D3D11_STENCIL_OP_REPLACE,D3D11_STENCIL_OP_REPLACE,D3D11_COMPARISON_ALWAYS};ds.BackFace=ds.FrontFace;
137 ComPtr<ID3D11DepthStencilState> write;FogHR(__LINE__,d.Native()->CreateDepthStencilState(&ds,&write));
138 D3D11_RASTERIZER_DESC rs{};rs.FillMode=D3D11_FILL_SOLID;rs.CullMode=D3D11_CULL_NONE;rs.MultisampleEnable=rs.DepthClipEnable=rs.ScissorEnable=TRUE;
139 ComPtr<ID3D11RasterizerState> raster;FogHR(__LINE__,d.Native()->CreateRasterizerState(&rs,&raster));
140 auto* context=d.Context();auto* target=d.Owner().SceneTarget();context->OMSetRenderTargets(1,&target,d.Owner().Depth().WriteView());
141 context->RSSetState(raster.Get());context->RSSetScissorRects(1,&rectangle);const auto viewport=d.Draws().Viewport();context->RSSetViewports(1,&viewport);
142 context->OMSetBlendState(nullptr,nullptr,sampleMask);context->OMSetDepthStencilState(write.Get(),stencilValue);
143 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);Parameters11 empty;
144 FogHR(__LINE__,cover.Bind(context,empty));context->Draw(3,0);
145 }
146 // Perspective ground has affine hardware depth but rapidly varying axial
147 // distance near the horizon. A constant-depth fixture cannot expose stripes
148 // caused by rejecting its neighboring reduced-resolution samples.
149 void Ground(RenderDevice& d,const XMFLOAT4X4& projection,float heightKm,float bank=0)
150 {
151 const char source[]="cbuffer Ground {float4 ground,groundProjection;} float4 V(uint id:SV_VertexID):SV_Position{return float4(id==2?3:-1,id==1?3:-1,0,1);} "
152 "struct O {float4 color:SV_Target;float depth:SV_Depth;}; O P(float4 p:SV_Position){O o;o.color=0;float inverseZ=dot(p.xy-ground.zw,ground.xy);o.depth=inverseZ>0 ? saturate(-groundProjection.x+groundProjection.y*inverseZ) : 1;return o;}";
153 ComPtr<ID3DBlob> vs,ps;FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"V","vs_5_0",0,0,&vs,nullptr));
154 FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"P","ps_5_0",0,0,&ps,nullptr));
155 Program11 ground;FogHR(__LINE__,ground.Create(d.Native(),vs->GetBufferPointer(),vs->GetBufferSize(),ps->GetBufferPointer(),ps->GetBufferSize()));
156 D3D11_DEPTH_STENCIL_DESC ds{};ds.DepthEnable=TRUE;ds.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;ds.DepthFunc=D3D11_COMPARISON_ALWAYS;
157 ComPtr<ID3D11DepthStencilState> write;FogHR(__LINE__,d.Native()->CreateDepthStencilState(&ds,&write));
158 D3D11_RASTERIZER_DESC rs{};rs.FillMode=D3D11_FILL_SOLID;rs.CullMode=D3D11_CULL_NONE;rs.MultisampleEnable=rs.DepthClipEnable=TRUE;
159 ComPtr<ID3D11RasterizerState> raster;FogHR(__LINE__,d.Native()->CreateRasterizerState(&rs,&raster));
160 auto* context=d.Context();auto* target=d.Owner().SceneTarget();const auto viewport=d.Draws().Viewport();
161 context->OMSetRenderTargets(1,&target,d.Owner().Depth().WriteView());context->RSSetViewports(1,&viewport);context->RSSetState(raster.Get());
162 context->OMSetDepthStencilState(write.Get(),0);context->OMSetBlendState(nullptr,nullptr,UINT_MAX);
163 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);Parameters11 parameters;
164 parameters.Set("ground",XMFLOAT4(-2*std::sin(bank)/(heightKm*viewport.Width*projection._11),
165 2*std::cos(bank)/(heightKm*viewport.Height*projection._22),viewport.Width*.5f,viewport.Height*.5f));
166 parameters.Set("groundProjection",XMFLOAT4(projection._33,projection._43,0,0));
167 FogHR(__LINE__,ground.Bind(context,parameters));context->Draw(3,0);
168 }
169 template<class Draw> Timing Measure(RenderDevice& device,Draw draw)
170 {
171 ComPtr<ID3D11Query> disjoint,begin,end;D3D11_QUERY_DESC desc{D3D11_QUERY_TIMESTAMP_DISJOINT,0};
172 FogHR(__LINE__,device.Native()->CreateQuery(&desc,&disjoint));desc.Query=D3D11_QUERY_TIMESTAMP;
173 FogHR(__LINE__,device.Native()->CreateQuery(&desc,&begin));FogHR(__LINE__,device.Native()->CreateQuery(&desc,&end));
174 auto* context=device.Context();std::vector<double> cpu,gpu;
175 for(unsigned frame=0;frame<360;++frame)
176 {
177 const float black[4]{0,0,0,1};context->ClearRenderTargetView(device.Owner().SceneTarget(),black);
178 context->Begin(disjoint.Get());context->End(begin.Get());auto a=Clock::now();draw();auto b=Clock::now();
179 context->End(end.Get());context->End(disjoint.Get());context->Flush();
180 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT frequency{};UINT64 first=0,last=0;
181 auto wait=[&](ID3D11Query* q,void* data,UINT size){const auto deadline=GetTickCount64()+10000;
182 HRESULT hr;while((hr=context->GetData(q,data,size,0))==S_FALSE){if(GetTickCount64()>=deadline)throw std::runtime_error("GPU query timeout");Sleep(0);}FogHR(__LINE__,hr);};
183 wait(disjoint.Get(),&frequency,sizeof(frequency));wait(begin.Get(),&first,sizeof(first));wait(end.Get(),&last,sizeof(last));
184 if(frame>=60 && !frequency.Disjoint){cpu.push_back(Milliseconds(a,b));gpu.push_back(1000.*double(last-first)/frequency.Frequency);}
185 }
186 Check(cpu.size()>=290,"valid timestamp samples");return {Percentile(cpu,.5),Percentile(cpu,.95),Percentile(gpu,.5),Percentile(gpu,.95)};
187 }
188}
189int main(int argc,char** argv)
190{
191 try
192 {
193 std::filesystem::path outputDirectory;
194 bool benchmark=false,candidateBenchmark=false,groundBenchmark=false;for(int i=1;i<argc;++i)
195 if(std::string(argv[i])=="--benchmark")benchmark=true;
196 else if(std::string(argv[i])=="--candidate-benchmark")benchmark=candidateBenchmark=true;
197 else if(std::string(argv[i])=="--ground-benchmark")benchmark=candidateBenchmark=groundBenchmark=true;
198 else if(std::string(argv[i])=="--output" && i+1<argc)outputDirectory=argv[++i];
199 else throw std::runtime_error("unknown argument");
200 const auto lowOutput=outputDirectory.empty() ? std::filesystem::path("outputs/fog-lowres-20261022") : outputDirectory;
201 const auto groundOutput=outputDirectory.empty() ? std::filesystem::path("outputs/fog-ground-bands-20261022") : outputDirectory;
202 const auto legacyOutput=outputDirectory.empty() ? std::filesystem::path("Output/fog-beams") : outputDirectory;
203 for(const auto& directory:{lowOutput,groundOutput,legacyOutput})std::filesystem::create_directories(directory);
204 NativeUiTest11 fixture(960,540,false,!benchmark);auto& d=fixture.device;auto* context=d.Context();diagnosticDevice=d.Native();
205 std::wcout<<fixture.host.Device().Adapter().Description<<'\n';
206 FogBeams11 fog;FogHR(__LINE__,fog.Initialize(d.Native()));fog.SetResolutionDivisor(1);Legacy legacy(d);
207 XMFLOAT4X4 view,projection;XMStoreFloat4x4(&view,XMMatrixIdentity());
208 auto matrices=[&](){auto vp=d.Draws().Viewport();XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(XM_PIDIV4,vp.Width/vp.Height,.0001f,10));};matrices();
209 auto render=[&](const std::vector<FogBeams11::Light>& lights,float depth=1,unsigned stencil=0) {
210 static unsigned frame=0;std::cout<<"Fog frame "<<++frame<<" lights="<<lights.size()<<" depth="<<depth<<" stencil="<<stencil<<std::endl;
211 const float black[4]{0,0,0,1};context->ClearRenderTargetView(d.Owner().SceneTarget(),black);
212 context->ClearDepthStencilView(d.Owner().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,depth,UINT8(stencil));
213 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,lights));return ResolvedPixels(d);
214 };
215 auto road=Road();auto crossing=Crossing();
216 auto pixels=render({road});Check(Energy(pixels)>0,"road beam is visible in fog");fixture.Save(legacyOutput/"road-new.png");
217 const auto canonical=pixels;view._41=123;view._42=-456;view._43=789;
218 Check(render({road})==canonical,"camera-relative beam survives large camera translation without swimming");XMStoreFloat4x4(&view,XMMatrixIdentity());
219 for(unsigned y=0;y<270;++y)for(unsigned x=0;x<960;++x)Check(((pixels[y*960+x]>>8)&255)==0,"upper low-beam cutoff leaves sky unlit");
220 pixels=render({crossing});Check(Energy(pixels)>0,"side-on crossing beam is visible");fixture.Save(legacyOutput/"crossing-new.png");
221 auto facing=crossing;facing.position={0,0,-.06f};facing.direction={0,0,1};
222 render({facing});fixture.Save(legacyOutput/"facing-new.png");
223 render({});legacy.Draw(d,view,projection,{facing});fixture.Save(legacyOutput/"facing-old.png");
224 pixels=render({crossing});
225 for(auto sample:{XMFLOAT2(360,335),XMFLOAT2(480,335),XMFLOAT2(600,335),XMFLOAT2(420,340)})
226 {
227 const unsigned x=unsigned(sample.x),y=unsigned(sample.y);
228 XMFLOAT3 ray;XMStoreFloat3(&ray,XMVector3Normalize(XMVectorSet((2*(x+.5f)/960-1)/projection._11,(1-2*(y+.5f)/540)/projection._22,-1,0)));
229 const double expected=Reference(crossing,ray,10),actual=(pixels[y*960+x]>>8)&255;
230 std::cout<<"Reference pixel "<<x<<','<<y<<": GPU="<<actual<<", CPU="<<expected<<'\n';
231 Check(std::abs(actual-expected)<(std::max)(2.,expected*.12),"fog radiance matches independent dense integration");
232 }
233 // 50 m visibility and a source 10 m to the side expose an early
234 // incident-light clamp: its legacy 80 lux cap suppresses the authored
235 // 625,000 cd lamp by ~78x at that source distance. Dim only this test's
236 // emitter so the independent comparison fits the UNORM readback.
237 auto dense=Crossing();dense.position={-.01f,0,-.02f};dense.extinctionPerKm=3.912f/.05f;dense.color={.1f,.1f,.08f,1};
238 pixels=render({dense});
239 const unsigned denseX=480,denseY=270;XMFLOAT3 denseRay;
240 XMStoreFloat3(&denseRay,XMVector3Normalize(XMVectorSet((2*(denseX+.5f)/960-1)/projection._11,(1-2*(denseY+.5f)/540)/projection._22,-1,0)));
241 const double denseExpected=Reference(dense,denseRay,10),denseActual=(pixels[denseY*960+denseX]>>8)&255;
242 std::cout<<"50 m visibility, near aircraft lamp: GPU="<<denseActual<<", photometric integral="<<denseExpected<<std::endl;
243 Check(denseExpected>4 && denseExpected<220,"dense-fog photometric fixture stays measurable without display saturation");
244 Check(std::abs(denseActual-denseExpected)<(std::max)(2.,denseExpected*.12),"dense near-source fog retains authored candela before scattering");
245 fixture.Save(lowOutput/"dense-side-reference.png");
246 fog.SetResolutionDivisor(0);pixels=render({dense});fixture.Save(lowOutput/"dense-side-automatic.png");
247 Check(std::abs(double((pixels[denseY*960+denseX]>>8)&255)-denseExpected)<(std::max)(2.,denseExpected*.15),"reduced dense-fog beam retains near-source photometric brightness");
249 pixels=render({crossing});const double visible=Energy(pixels);
250 Check(Energy(render({crossing},0))==0,"foreground depth blocks the entire beam");
251 Check(Energy(render({crossing},1,3))==0,"cockpit stencil blocks beam scattering");
252 crossing.color.w=0;Check(Energy(render({crossing}))==0,"off lamp contributes no fog");crossing=Crossing();
253 crossing.extinctionPerKm=0;Check(Energy(render({crossing}))==0,"clear air contributes no fog");crossing=Crossing();
254 crossing.position={10,0,-.08f};render({crossing});Check(fog.LastDraws()==0,"offscreen nonintersecting beam is culled");crossing=Crossing();
255 auto blocked=crossing;blocked.position={0,0,.04f};blocked.direction={0,0,1};Check(Energy(render({blocked}))==0,"beam aimed away cannot illuminate the view");
256 auto thick=crossing;thick.extinctionPerKm=3.912f/.025f;Check(Energy(render({thick}))<visible,"dense mist reduces distant beam throw");
257 render({});legacy.Draw(d,view,projection,{Road(-.0006f),Road(.0006f)});fixture.Save(legacyOutput/"road-old.png");
258 render({});legacy.Draw(d,view,projection,{Crossing()});fixture.Save(legacyOutput/"crossing-old.png");
259 fog.Reset();FogHR(__LINE__,fog.Initialize(d.Native()));Check(Energy(render({Road()}))>0,"resource reinitialization retains fog rendering");
260 // Exercise the production owner too: this lamp is below the cloud
261 // envelope and must survive cloud-light culling as a separate fog lamp.
262 CloudRenderer11 clouds;
263 {
264 const DWORD priorSize=GetEnvironmentVariableA("RISE_FOG_BEAMS",nullptr,0);
265 std::vector<char> prior(priorSize);
266 if(priorSize)Check(GetEnvironmentVariableA("RISE_FOG_BEAMS",prior.data(),priorSize)>0,"read inherited fog startup override");
267 struct RestoreSetting
268 {
269 const char* value;
270 ~RestoreSetting(){SetEnvironmentVariableA("RISE_FOG_BEAMS",value);}
271 } restore{prior.empty() ? nullptr : prior.data()};
272 for(const char* setting:{static_cast<const char*>(nullptr),"0","1"})
273 {
274 Check(SetEnvironmentVariableA("RISE_FOG_BEAMS",setting)!=0,"set fog startup override");
275 clouds.Reset();FogHR(__LINE__,clouds.Initialize(d.Native()));
276 Check(clouds.FogBeamsEnabled()==(!setting || setting[0]!='0'),"fog startup defaults on and respects explicit off/on overrides");
277 }
278 }
279 Check(clouds.FogBeamsEnabled(),"packaged production fog shaders initialize");
280 CloudVolume::Parameters layer;layer.base=1;layer.top=10;
281 const XMFLOAT3 planetEye(0,layer.radius+.05f,0);
282 auto production=Crossing();CloudRenderer11::Headlight spot;
283 spot.position={production.position.x,planetEye.y+production.position.y,production.position.z};
284 spot.direction=production.direction;spot.up=production.up;spot.color=production.color;spot.rangeKm=production.profile.rangeKm;
285 spot.profile=production.profile;spot.extinctionPerKm=production.extinctionPerKm;clouds.SetHeadlights({spot});
286 const auto cloudFrame=[&]() {
287 render({});FogHR(__LINE__,clouds.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,
288 planetEye,layer,{0,1,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}));return Energy(ResolvedPixels(d));
289 };
290 clouds.SetFogBeamsEnabled(false);Check(cloudFrame()==0,"A/B off keeps a clear cloud frame black");
291 clouds.SetFogBeamsEnabled(true);Check(cloudFrame()>0,"production fog lights survive cloud-envelope culling");
292 // Cloud optical depth must reduce the same fog contribution, even with
293 // a source which has no direct line to the camera.
294 layer.base=-.8f;layer.top=3;spot.color={0,0,0,0};clouds.SetHeadlights({spot});clouds.SetFogBeamsEnabled(false);const double cloudBackground=cloudFrame();
295 auto attenuation=clouds.Parameters();attenuation.Texture("headlightDepth",clouds.Pass().HeadlightDepth());
296 production.cloudIndex=0;
297 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,{production},&attenuation));
298 const double cloudyFog=Energy(ResolvedPixels(d))-cloudBackground;
299 std::cout<<"Fog energy: clear="<<visible<<", cloud contribution="<<cloudyFog<<", background="<<cloudBackground<<'\n';
300 Check(cloudyFog>=0 && cloudyFog<visible,"cloud source/view extinction reduces fog scattering");
301 // The default reduced path must retain reference brightness, exact
302 // cutoff/occlusion, and the inclusive lamp cap before timing it.
303 production.cloudIndex=-1;
304 for(unsigned divisor:{4u,8u})for(const auto& lamp:{Road(),Crossing(),facing})
305 {
306 fog.SetResolutionDivisor(1);const auto full=render({lamp});
307 fog.SetResolutionDivisor(divisor);const auto low=render({lamp});
308 double error=0;for(size_t i=0;i<full.size();++i)error+=std::abs(int((full[i]>>8)&255)-int((low[i]>>8)&255));
309 error/=full.size();
310 std::cout<<"Divisor "<<divisor<<", reduced energy="<<Energy(low)<<", reference="<<Energy(full)<<", mean green error="<<error<<'\n';
311 Check(Energy(low)>0,"reduced beam remains visible");
312 Check(std::abs(Energy(low)-Energy(full))<(std::max)(.005,Energy(full)*.05),"reduced mean brightness stays within five percent of reference");
313 Check(error<(std::max)(.15,Energy(full)*.2),"reduced radiance agrees with full-resolution reference");
314 // Depth zero is the near plane, not the camera. An oncoming beam
315 // can scatter in that short foreground segment; compare to the
316 // clipped reference instead of relying on its old dim quantization.
317 fog.SetResolutionDivisor(1);const double foreground=Energy(render({lamp},0));
318 fog.SetResolutionDivisor(divisor);const double reducedForeground=Energy(render({lamp},0));
319 Check(std::abs(reducedForeground-foreground)<.02,"reduced near-plane fog matches the depth-clipped reference");
320 Check(reducedForeground<Energy(full)*.02,"foreground depth removes the distant fog contribution");
321 Check(Energy(render({lamp},1,3))==0,"reduced cockpit stencil blocks the beam");
322 }
323 pixels=render({Road()});for(unsigned y=0;y<270;++y)for(unsigned x=0;x<960;++x)
324 Check(((pixels[y*960+x]>>8)&255)==0,"reduced reconstruction preserves the exact road sky cutoff");
325 std::vector<FogBeams11::Light> capped(8,Crossing());const auto eightPixels=render(capped);capped.push_back(facing);
326 Check(render(capped)==eightPixels,"eight total lamps is a hard cap including player lights");
328 render({facing});fixture.Save(lowOutput/"facing-quarter.png");
329 render({Crossing()});fixture.Save(lowOutput/"crossing-quarter.png");
330 render({Road(-.0006f),Road(.0006f)});fixture.Save(lowOutput/"road-quarter.png");
331 for(unsigned mask:{0u,3u})
332 {
333 render({});Cover(d,{480,0,484,540},mask);
334 // The depth fixture uses a beam wholly behind its near occluder.
335 // Cockpit stencil must exclude even an oncoming foreground glow.
336 const auto occlusionLamp=mask ? facing : Crossing();
337 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,{occlusionLamp}));
338 pixels=ResolvedPixels(d);Check(Energy(pixels)>0,"beam survives beside a thin foreground edge");
339 for(unsigned y=0;y<540;++y)for(unsigned x=480;x<484;++x)
340 Check((pixels[y*960+x]&0xffffff)==0,"reconstruction cannot leak through a thin depth/stencil edge");
341 fixture.Save(lowOutput/(mask ? "stencil-edge-quarter.png" : "depth-edge-quarter.png"));
342 }
343 fixture.Resize(963,543);matrices();Check(Energy(render({facing}))>0,"odd viewport size rounds reduced targets up safely");
344 fog.ReleaseTargets();Check(Energy(render({facing}))>0,"resized target release recreates valid scattering layers");
345 fixture.Resize(960,540);matrices();
346 auto dimFacing=facing;dimFacing.color={.04f,.04f,.032f,.9f};
347 const std::vector<FogBeams11::Light> mixed{Road(-.0006f),Road(.0006f),Crossing(),dimFacing};
348 fog.SetResolutionDivisor(1);const auto mixedReference=render(mixed);
349 for(unsigned divisor:{4u,8u,0u})
350 {
351 fog.SetResolutionDivisor(divisor);const auto low=render(mixed);
352 double error=0;for(size_t i=0;i<low.size();++i)error+=std::abs(int((low[i]>>8)&255)-int((mixedReference[i]>>8)&255));
353 error/=low.size();std::cout<<"Mixed lamp divisor="<<divisor<<", mean error="<<error<<'\n';
354 Check(error<(std::max)(.15,Energy(mixedReference)*.2),"shared buffer preserves overlapping road and aircraft lamps");
355 }
356 render({});const D3D11_VIEWPORT offsetViewport{9,7,941,523,0,1};
357 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),offsetViewport,view,projection,{facing}));
358 pixels=ResolvedPixels(d);Check(Energy(pixels)>0,"offset viewport reconstructs a visible beam");
359 for(unsigned y=0;y<540;++y)for(unsigned x=0;x<960;++x)if(x<9 || x>=950 || y<7 || y>=530)
360 Check((pixels[y*960+x]&0xffffff)==0,"offset viewport leaves pixels outside its rectangle untouched");
361 fog.SetResolutionDivisor(8);render({facing});fixture.Save(lowOutput/"facing-eighth.png");
362 // The cloud density implementation must also work through the reduced
363 // target, including the production organic shader variant.
364 for(bool organic:{false,true})
365 {
366 FogHR(__LINE__,fog.ConfigureOrganic(organic));render({});
367 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,{production},&attenuation));
368 Check(Energy(ResolvedPixels(d))<visible,"reduced cloud extinction suppresses the distant beam");
369 }
370 FogHR(__LINE__,fog.ConfigureOrganic(false));
371 for(unsigned divisor:{1u,4u,8u})for(unsigned samples:{2u,4u,8u})if(fixture.host.Device().SupportsSamples(samples))
372 {
373 fog.SetResolutionDivisor(divisor);
374 FogHR(__LINE__,fixture.host.SetSamples(samples));d.Reset();matrices();
375 auto sampleLamp=Crossing();sampleLamp.color={8,8,6.4f,.9f};
376 const double full=Energy(render({sampleLamp}));Check(full>0,"MSAA fog is visible");
377 Check(Energy(render({sampleLamp},1,3))==0,"MSAA cockpit samples remain unlit");
378 render({});
379 const char source[]="float4 V(uint id:SV_VertexID):SV_Position{return float4(id==2?3:-1,id==1?3:-1,0,1);} float4 P():SV_Target{return 0;}";
380 ComPtr<ID3DBlob> vs,ps;FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"V","vs_5_0",0,0,&vs,nullptr));
381 FogHR(__LINE__,D3DCompile(source,sizeof(source)-1,nullptr,nullptr,nullptr,"P","ps_5_0",0,0,&ps,nullptr));
382 Program11 cover;FogHR(__LINE__,cover.Create(d.Native(),vs->GetBufferPointer(),vs->GetBufferSize(),ps->GetBufferPointer(),ps->GetBufferSize()));
383 D3D11_DEPTH_STENCIL_DESC ds{};ds.DepthEnable=TRUE;ds.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;ds.DepthFunc=D3D11_COMPARISON_ALWAYS;
384 ComPtr<ID3D11DepthStencilState> write;FogHR(__LINE__,d.Native()->CreateDepthStencilState(&ds,&write));
385 D3D11_RASTERIZER_DESC rs{};rs.FillMode=D3D11_FILL_SOLID;rs.CullMode=D3D11_CULL_NONE;rs.MultisampleEnable=rs.DepthClipEnable=TRUE;
386 ComPtr<ID3D11RasterizerState> raster;FogHR(__LINE__,d.Native()->CreateRasterizerState(&rs,&raster));
387 auto* target=d.Owner().SceneTarget();context->OMSetRenderTargets(1,&target,d.Owner().Depth().WriteView());
388 context->RSSetState(raster.Get());const auto viewport=d.Draws().Viewport();context->RSSetViewports(1,&viewport);
389 context->OMSetBlendState(nullptr,nullptr,1);context->OMSetDepthStencilState(write.Get(),0);
390 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);Parameters11 empty;
391 FogHR(__LINE__,cover.Bind(context,empty));context->Draw(3,0);
392 FogHR(__LINE__,fog.Render(context,target,d.Owner().Depth(),viewport,view,projection,{sampleLamp}));
393 const double partial=Energy(ResolvedPixels(d)),expected=full*(samples-1)/samples;
394 std::cout<<"divisor "<<divisor<<", "<<samples<<"x MSAA: full="<<full<<", one sample occluded="<<partial<<", expected="<<expected<<'\n';
395 Check(std::abs(partial-expected)<full*.03,"mixed MSAA depth clips covered samples without expanding the silhouette");
396 render({});Cover(d,{0,0,960,540},3,1,false);
397 FogHR(__LINE__,fog.Render(context,target,d.Owner().Depth(),viewport,view,projection,{sampleLamp}));
398 const double stencilPartial=Energy(ResolvedPixels(d));
399 std::cout<<"divisor "<<divisor<<", "<<samples<<"x mixed stencil: "<<stencilPartial<<", expected="<<expected<<'\n';
400 Check(std::abs(stencilPartial-expected)<full*.03,"hardware stencil masks individual MSAA samples at uniform depth");
401 }
402 FogHR(__LINE__,fixture.host.SetSamples(1));d.Reset();matrices();
403 fixture.Resize(3840,2160);matrices();
404 fog.SetResolutionDivisor(1);const auto reference4k=render(mixed);
405 fog.SetResolutionDivisor(0);const auto budget4k=render(mixed);
406 double error4k=0;for(size_t i=0;i<reference4k.size();++i)
407 error4k+=std::abs(int((reference4k[i]>>8)&255)-int((budget4k[i]>>8)&255));
408 error4k/=reference4k.size();std::cout<<"4K automatic mixed lamp mean error="<<error4k<<'\n';
409 Check(error4k<(std::max)(.15,Energy(reference4k)*.2),"4K automatic shared buffer agrees with the reference");
410 fixture.Save(lowOutput/"mixed-budget-4k.png");
411 for(unsigned samples:{1u,4u})if(fixture.host.Device().SupportsSamples(samples))
412 for(unsigned width:{3440u,3840u})for(float bank:{0.f,.23f})
413 {
414 const unsigned height=width==3440 ? 1380 : 2160;
415 FogHR(__LINE__,fixture.host.SetSamples(samples));fixture.Resize(width,height);matrices();
416 const auto capture=(groundOutput/("ground-"+std::to_string(width)+"-"+std::to_string(samples)+"x-"+(bank ? "tilted" : "level"))).string();
417 auto oncoming=Road();oncoming.position={0,-.002f,-.08f};oncoming.direction={0,0,1};oncoming.profile=LandingLights::CarHigh;
418 const std::vector<FogBeams11::Light> groundLights{Road(-.0006f),Road(.0006f),oncoming};
419 const D3D11_RECT cockpit{LONG(width/2),0,LONG(width/2+3),LONG(height)};
420 const auto groundFrame=[&](unsigned divisor,bool mask=false) {
421 render({});Ground(d,projection,.0035f,bank);if(mask)Cover(d,cockpit,3,UINT_MAX,false);fog.SetResolutionDivisor(divisor);
422 FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,groundLights));
423 return ResolvedPixels(d);
424 };
425 const auto full=groundFrame(1);fixture.Save(capture+"-reference.png");
426 const auto low=groundFrame(0);fixture.Save(capture+"-automatic.png");
427 size_t lit=0,missing=0;double error=0;
428 for(size_t i=0;i<full.size();++i)
429 {
430 const int a=(full[i]>>8)&255,b=(low[i]>>8)&255;error+=std::abs(a-b);
431 if(a>=2){++lit;if(b==0)++missing;}
432 }
433 std::cout<<"Ground "<<width<<' '<<samples<<"x, bank="<<bank<<": reference="<<Energy(full)<<", reduced="<<Energy(low)<<", missing="<<missing<<'/'<<lit<<", error="<<error/full.size()<<std::endl;
434 Check(lit>1000,"perspective ground fixture contains visible headlight fog");
435 Check(missing==0,"perspective ground fog has no missing scanlines or horizon seam");
436 Check(std::abs(Energy(low)-Energy(full))<Energy(full)*.05,"perspective ground fog brightness stays within five percent of reference");
437 const auto masked=groundFrame(0,true);
438 for(unsigned y=0;y<height;++y)for(LONG x=cockpit.left;x<cockpit.right;++x)
439 Check((masked[size_t(y)*width+x]&0xffffff)==0,"tilted perspective reconstruction preserves thin cockpit silhouettes");
440 }
441 if(!benchmark)fixture.DebugClean();
442 if(benchmark)
443 {
444 std::ofstream csv((groundBenchmark ? groundOutput : lowOutput)/"benchmark.csv");csv<<"width,height,samples,trial,case,renderer,lights,cpu_median_ms,cpu_p95_ms,gpu_median_ms,gpu_p95_ms\n";
445 for(unsigned samples:{1u,4u})for(unsigned width:{3840u})
446 {
447 const unsigned height=2160;
448 FogHR(__LINE__,fixture.host.SetSamples(samples));fixture.Resize(width,height);matrices();
449 std::vector<std::pair<std::string,std::vector<FogBeams11::Light>>> cases{{"off",{}},{"road-pair",{Road(-.0006f),Road(.0006f)}},{"crossing-aircraft",{Crossing()}}};
450 std::vector<FogBeams11::Light> six;for(int i=0;i<6;++i)six.push_back(Road((i-2.5f)*.0015f));cases.push_back({"six-road",six});
451 std::vector<FogBeams11::Light> eight;for(int i=0;i<8;++i)eight.push_back(Road((i-3.5f)*.0015f));cases.push_back({"eight-road",eight});
452 cases.push_back({"cloud-crossing",{production}});
453 std::vector<FogBeams11::Light> cloudEight(8,production);for(auto& lamp:cloudEight)lamp.cloudIndex=0;
454 cases.push_back({"six-cloud-crossing",std::vector<FogBeams11::Light>(cloudEight.begin(),cloudEight.begin()+6)});
455 cases.push_back({"eight-cloud-crossing",cloudEight});
456 cases.push_back({"eight-organic-cloud-crossing",cloudEight});
457 cases.push_back({"six-organic-cloud-crossing",std::vector<FogBeams11::Light>(cloudEight.begin(),cloudEight.begin()+6)});
458 if(groundBenchmark)
459 {
460 std::vector<FogBeams11::Light> groundLights;
461 for(int i=0;i<8;++i){auto lamp=Road((i-3.5f)*.0015f);lamp.position.z=-.08f;lamp.direction={0,0,1};lamp.profile=LandingLights::CarHigh;groundLights.push_back(lamp);}
462 cases.push_back({"six-ground-oncoming",std::vector<FogBeams11::Light>(groundLights.begin(),groundLights.begin()+6)});
463 cases.push_back({"eight-ground-oncoming",groundLights});
464 auto mist=Crossing();mist.position={-.01f,0,-.02f};mist.extinctionPerKm=3.912f/.05f;
465 cases.push_back({"six-dense-fog",std::vector<FogBeams11::Light>(6,mist)});
466 cases.push_back({"eight-dense-fog",std::vector<FogBeams11::Light>(8,mist)});
467 }
468 for(unsigned trial=0;trial<3;++trial)for(const auto& scenario:cases)for(unsigned order=0;order<5;++order)
469 {
470 const unsigned mode=(trial+order)%5;const bool shader=mode!=0;
471 if(candidateBenchmark && mode!=4)continue;
472 // The opaque organic stress scene only needs candidate
473 // timings; avoid minutes per trial on unused baselines.
474 if(scenario.first.find("organic")!=std::string::npos && mode<3)continue;
475 const unsigned divisor=candidateBenchmark ? 0 : mode==4 ? 8 : mode==3 ? 4 : mode==2 ? 2 : 1;fog.SetResolutionDivisor(divisor);render({});
476 if(scenario.first.find("ground-oncoming")!=std::string::npos)Ground(d,projection,.0035f,.23f);
477 const bool cloudy=scenario.first.find("cloud-crossing")!=std::string::npos;
478 FogHR(__LINE__,fog.ConfigureOrganic(scenario.first.find("organic")!=std::string::npos));
479 const auto timing=Measure(d,[&](){if(shader)FogHR(__LINE__,fog.Render(context,d.Owner().SceneTarget(),d.Owner().Depth(),d.Draws().Viewport(),view,projection,scenario.second,cloudy ? &attenuation : nullptr));
480 else legacy.Draw(d,view,projection,scenario.second,cloudy ? &layer : nullptr);});
481 const char* name=candidateBenchmark ? "budget" : mode==0 ? "mesh" : mode==1 ? "full" : mode==2 ? "half" : mode==3 ? "quarter" : "eighth";
482 csv<<std::setprecision(7)<<width<<','<<height<<','<<samples<<','<<trial<<','<<scenario.first<<','<<name<<','<<scenario.second.size()<<','
483 <<timing.cpu50<<','<<timing.cpu95<<','<<timing.gpu50<<','<<timing.gpu95<<'\n';csv.flush();
484 std::cout<<width<<' '<<samples<<"x "<<scenario.first<<' '<<name<<" CPU "<<timing.cpu50<<", GPU "<<timing.gpu50<<" ms\n"<<std::flush;
485 }
486 }
487 }
488 std::cout<<"PASS: "<<checks<<" fog scattering checks\n";return 0;
489 }
490 catch(const std::exception& error){std::cerr<<"FAIL: "<<error.what()<<'\n';return 1;}
491}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
Reference
Definition ServerTypes.h:40
ID3D11Texture2D * SceneColor() const
Definition Device11.h:69
ID3D11RenderTargetView * SceneTarget() const
Definition Device11.h:68
const SceneDepth11 & Depth() const
Definition Device11.h:70
const D3D11_VIEWPORT & Viewport() const
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &directory={})
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, const std::vector< Light > &lights, const Parameters11 *clouds=nullptr)
unsigned LastDraws() const
Definition FogBeams11.h:40
void SetResolutionDivisor(unsigned value)
Definition FogBeams11.h:43
HRESULT ConfigureOrganic(bool enabled)
Definition FogBeams11.h:30
void Set(const std::string &name, const void *data, size_t bytes)
Definition Program11.cpp:45
HRESULT Create(ID3D11Device *device, const void *vertexCode, size_t vertexSize, const void *pixelCode, size_t pixelSize, const D3D11_INPUT_ELEMENT_DESC *elements=nullptr, UINT elementCount=0, UINT bgraColorMask=0)
HRESULT Bind(ID3D11DeviceContext *context, const Parameters11 &parameters)
HRESULT DrawPrimitive(Primitive type, UINT first, UINT count)
DrawContext11 & Draws()
HRESULT SetStreamSource(UINT stream, RenderBuffer *buffer, UINT offset, UINT stride)
ID3D11DeviceContext * Context()
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT SetFVF(DWORD value)
HRESULT SetTransform(DWORD slot, const RiseMath::Matrix *value)
HRESULT CreateVertexBuffer(UINT bytes, DWORD usage, DWORD format, ResourcePool pool, RenderBuffer **result, void *shared)
HRESULT SetTextureStageState(DWORD stage, DWORD state, DWORD value)
HRESULT SetTexture(DWORD stage, RenderTexture *texture)
const D3D11_TEXTURE2D_DESC & Description() const
Definition Device11.h:22
ID3D11DepthStencilView * WriteView() const
Definition Device11.h:18
Point Add(Point a, Point b)
Definition CloudVolume.h:95
float Transmittance(Point from, Point to, const Parameters &params, uint32_t seed=DefaultSeed)
Definition DDS.h:24
constexpr Profile AircraftLanding
Definition BeamProfile.h:38
float IlluminanceLux(const Profile &profile, float distanceKm)
Definition BeamProfile.h:81
constexpr unsigned FogVertexCount
constexpr Profile RoadLow
Definition BeamProfile.h:35
constexpr Profile CarHigh
Definition BeamProfile.h:36
float Angular(const Profile &profile, float horizontalSlope, float verticalSlope, float axialDistanceKm)
Definition BeamProfile.h:66
void FogMesh(const Light &light, Vertex *output, bool spill)
Kinematic Ground(Vec r, double spin, double time)
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
Vector3 * Vec3Cross(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:105
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
HRESULT Draw(Rendering::RenderDevice *device, Rendering::RenderTexture *texture, Rendering::RenderBuffer *vertices, const RiseMath::Matrix &world, UINT segments, Rendering::RenderMaterial *volumeEffect=nullptr, float physicalScale=1)
RiseMath::Vector3 origin
RiseMath::Vector3 up
RiseMath::Vector3 direction
LandingLights::Profile profile
Definition FogBeams11.h:24
DirectX::XMFLOAT4 color
Definition FogBeams11.h:23