1
2
3void TestCloudSearch(Device11& gpu,CloudRenderer11&
renderer)
4{
5 const char probeSource[]=R"(
6#include "CloudVolume.hlsl"
7float4 CheckSearch(float4 pixel:SV_Position):SV_Target
8{
9 float3 direction=ray(float2((pixel.x+.5)/160,(pixel.y+.5)/120));
10 float2 span=interval(direction);
11 float stop=5+pixel.x*.7;
12 if(min(span.y,stop)<=span.x)return float4(0,0,0,1);
13 float a=firstCloud(direction,float2(span.x,min(span.y,stop)));
14 float b=firstCloud(direction,float2(span.x,min(span.y,stop+.01)));
15 bool lost=a>=0 && (b<0 || abs(b-a)>.005 || a>stop || b>stop+.01);
16 return float4(lost ? 1 : 0,a>=0 ? 1 : 0,0,1);
17}
18)";
19 const D3D_SHADER_MACRO macros[]={{"RISE_SCENE_SAMPLES","1"},{nullptr,nullptr}};
20 ComPtr<ID3DBlob> code,errors;
21 const auto hr=D3DCompile(probeSource,strlen(probeSource),"Rendering/Shaders/CloudSearchProbe.hlsl",
22 macros,D3D_COMPILE_STANDARD_FILE_INCLUDE,"CheckSearch","ps_5_0",
23 D3DCOMPILE_ENABLE_STRICTNESS|D3DCOMPILE_WARNINGS_ARE_ERRORS|D3DCOMPILE_PACK_MATRIX_ROW_MAJOR|D3DCOMPILE_OPTIMIZATION_LEVEL3,
24 0,&code,&errors);
25 if(errors)std::cerr<<static_cast<const char*>(errors->GetBufferPointer());HR(hr,"compile cloud search probe");
26 auto vertex=Compile("Fullscreen","vs_5_0",1);Program11 probe;
27 HR(probe.Create(gpu.Device(),vertex->GetBufferPointer(),vertex->GetBufferSize(),code->GetBufferPointer(),code->GetBufferSize()),"cloud search probe");
28 Pipeline pipeline(gpu.Device(),1);Scene scene(gpu.Device(),1);
29 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
30 XMFLOAT4X4 view,projection;
31 const float latitude=-18.221f*3.14159265f/180,longitude=-40.781f*3.14159265f/180;
32 const XMVECTOR radial=XMVectorSet(-sin(longitude)*cos(latitude),cos(longitude)*cos(latitude),sin(latitude),0);
33 const XMVECTOR west=XMVectorSet(cos(longitude),sin(longitude),0,0);
34 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorAdd(west,XMVectorScale(radial,.025f)),radial));
35 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(.35f,3440.f/1351,.001f,384));
36 XMFLOAT3 eye;XMStoreFloat3(&eye,XMVectorScale(radial,2939.6f+2.074463f));
37 unsigned lost=0,hits=0;
38 auto* context=gpu.Context();
39 for(unsigned offset=0;offset<12;++offset)
40 {
42 cloud.
noiseOffset={float(offset)*.13f,float(offset)*.27f,-float(offset)*.31f};
43 scene.Clear(context);
44 HR(
renderer.Render(context,scene.target.Get(),scene.depth,viewport,view,projection,eye,cloud,
45 {0,-1,0},{0,0,0,0},{.3f,.3f,.3f,1}),"cloud search setup");
46 auto parameters=
renderer.Parameters();
47 parameters.Set("screen",XMFLOAT4(1/projection._11,1/projection._22,1720,675));
48 context->ClearState();
auto*
target=scene.target.Get();
49 context->OMSetRenderTargets(1,&target,nullptr);context->RSSetViewports(1,&viewport);context->RSSetState(pipeline.raster.Get());
50 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
51 HR(probe.Bind(context,parameters),"bind cloud search probe");context->Draw(3,0);
52 context->OMSetRenderTargets(0,nullptr,nullptr);
53 for(const auto& pixel:pipeline.Pixels(gpu,scene,1))
54 {lost+=pixel.color[0]>0;hits+=pixel.color[1]>0;}
55 }
56 std::cout<<"Cloud search depth continuity: "<<lost<<" lost/moved first hits out of "<<hits<<" cloud intersections\n";
57 Check(hits>1000,"cloud search fixture must intersect cloud");
58 Check(lost==0,"moving terrain farther must not lose an already encountered cloud wisp");
59 DebugMessages(gpu);
60}
CloudWeather::Frame weather