Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CloudQuality11.h

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

1// Hash exact GPU first-hit distances and opacity separately from lighting.
2// FNV-1a ignores row padding so captures compare across resource allocations.
3static uint64_t CloudQualityHash(Device11& gpu,ID3D11ShaderResourceView* view,bool opacity)
4{
5 ComPtr<ID3D11Resource> resource;view->GetResource(&resource);
6 ComPtr<ID3D11Texture2D> texture;HR(resource.As(&texture),"quality readback texture");
7 D3D11_TEXTURE2D_DESC desc{};texture->GetDesc(&desc);
8 Check(desc.SampleDesc.Count==1 && desc.MipLevels==1 && desc.ArraySize==1,"quality readback dimensions");
9 Check(desc.Format==(opacity ? DXGI_FORMAT_B8G8R8A8_UNORM : DXGI_FORMAT_R32G32_FLOAT),"quality readback format");
10 desc.Usage=D3D11_USAGE_STAGING;desc.BindFlags=desc.MiscFlags=0;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;
11 ComPtr<ID3D11Texture2D> staging;HR(gpu.Device()->CreateTexture2D(&desc,nullptr,&staging),"quality readback target");
12 gpu.Context()->CopyResource(staging.Get(),texture.Get());
13 D3D11_MAPPED_SUBRESOURCE mapped{};HR(gpu.Context()->Map(staging.Get(),0,D3D11_MAP_READ,0,&mapped),"quality readback");
14 uint64_t hash=14695981039346656037ull;
15 for(UINT y=0;y<desc.Height;++y)
16 {
17 const auto* row=static_cast<const uint8_t*>(mapped.pData)+size_t(y)*mapped.RowPitch;
18 for(UINT x=0;x<desc.Width;++x)
19 for(UINT byte=opacity ? 3u : 0u;byte<4;++byte)
20 hash=(hash^row[x*(opacity ? 4u : 8u)+byte])*1099511628211ull;
21 }
22 gpu.Context()->Unmap(staging.Get(),0);return hash;
23}
24
25// Fixed-camera cloud previews; no live window, input or game state involved.
26static void CloudQuality(Device11& gpu,const fs::path& shaders,const fs::path& output)
27{
28 using namespace DirectX;
29 fs::create_directories(output);
30 std::ofstream shape(output/"shape.csv");Check(shape.good(),"quality shape output");
31 shape<<"fixture,first_hit_hash,opacity_hash\n";
32 SetEnvironmentVariableA("RISE_VOLUMETRIC_CLOUDS","1");SetEnvironmentVariableA("RISE_CLOUD_SEED","0x52495345");
33 CloudRenderer11 renderer;HR(renderer.Initialize(gpu.Device(),shaders),"quality renderer");renderer.SetLightningEnabled(false);
34 constexpr UINT width=3440,height=1351;
35 D3D11_TEXTURE2D_DESC desc{};desc.Width=width;desc.Height=height;desc.MipLevels=desc.ArraySize=1;
36 desc.SampleDesc={1,0};desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.BindFlags=D3D11_BIND_RENDER_TARGET;
37 ComPtr<ID3D11Texture2D> image;ComPtr<ID3D11RenderTargetView> target;
38 HR(gpu.Device()->CreateTexture2D(&desc,nullptr,&image),"quality image");
39 HR(gpu.Device()->CreateRenderTargetView(image.Get(),nullptr,&target),"quality target");
40 SceneDepth11 depth;HR(depth.Create(gpu.Device(),width,height,desc.SampleDesc),"quality depth");
41 const D3D11_VIEWPORT viewport{0,0,float(width),float(height),0,1};
42 const auto radial=XMVector3Normalize(XMVectorSet(.438f,.895f,-.073f,0));
43 const auto east=XMVector3Normalize(XMVector3Cross(radial,XMVectorSet(0,0,1,0)));
44 XMFLOAT4X4 view,projection;
45 // Client's 115-degree parameter goes to PerspectiveRH as full near width.
46 const float nearZ=.0001f,nearWidth=nearZ*std::tan(XMConvertToRadians(115.f)*.5f);
47 XMStoreFloat4x4(&projection,XMMatrixPerspectiveRH(nearWidth,nearWidth*height/width,nearZ,100000));
49 for(unsigned weather:{77u,153u})
50 {
51 auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({64,32,std::vector<uint8_t>(64*32,uint8_t(weather))});CloudWeather::BuildMips(*map);
52 renderer.UpdateWeather(map,60);HR(renderer.PrepareResources(gpu.Context()),"quality weather");renderer.UpdateWeather(map,60);
53 params.weather=renderer.WeatherFrame();params.activity=weather/255.f;
54 for(float altitude:{14.f,16.2f,16.8f,117.f,500.f,1000.f,3000.f})for(unsigned sunlight:{0u,1u})
55 for(unsigned nearView=0;nearView<(altitude==16.2f ? 3u : altitude==16.8f ? 2u : 1u);++nearView)
56 {
57 const auto direction=XMVector3Normalize(nearView==2 ? east-radial*.15f :
58 altitude>=500 || nearView ? east*.25f-radial : east-radial*.65f);
59 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),direction,radial));
60 XMFLOAT3 eye,sun;
61 XMStoreFloat3(&eye,radial*(params.radius+altitude));
62 XMStoreFloat3(&sun,XMVector3Normalize(-radial*(sunlight ? .35f : 1.f)-east*(sunlight ? .94f : .01f)));
63 const float background[]={.5f,.55f,.8f,1};gpu.Context()->ClearRenderTargetView(target.Get(),background);
64 gpu.Context()->ClearDepthStencilView(depth.WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
65 HR(renderer.Render(gpu.Context(),target.Get(),depth,viewport,view,projection,eye,params,sun,
66 {1,1,1,1},{.3f,.4f,.5f,1},{.125f,.375f,.25f,1},{.6f,.7f,.8f,100},{.6f,.7f,.8f,168.64f}),"quality render");
67 const auto altitudeName=altitude==16.2f ? std::string("16.2") : altitude==16.8f ? std::string("16.8") : std::to_string(unsigned(altitude));
68 const auto name=altitudeName+"km-w"+std::to_string(weather)+"-sun"+std::to_string(sunlight)+(nearView==2 ? "-horizon" : nearView ? "-down" : "")+".png";
69 HR(SaveWICTextureToFile(gpu.Context(),image.Get(),GUID_ContainerFormatPng,(output/name).c_str()),"save quality preview");
70 shape<<name<<','<<CloudQualityHash(gpu,renderer.Pass().Distance(),false)<<','
71 <<CloudQualityHash(gpu,renderer.Pass().Image(),true)<<'\n';
72 Check(shape.good(),"quality shape write");std::cout<<name<<std::endl;
73 }
74 }
75 DebugMessages(gpu);
76}
void BuildMips(Map &map)
Definition DDS.h:24
DIRECTX_TOOLKIT_API HRESULT __cdecl SaveWICTextureToFile(_In_ ID3D11DeviceContext *pContext, _In_ ID3D11Resource *pSource, _In_ REFGUID guidContainerFormat, _In_z_ const wchar_t *fileName, _In_opt_ const GUID *targetFormat=nullptr, _In_ std::function< void __cdecl(IPropertyBag2 *)> setCustomProps=nullptr, _In_ bool forceSRGB=false)
CloudWeather::Frame weather
Definition CloudVolume.h:35