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

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

1#pragma once
2// The alpha safely declines the unsupported organic diagnostic MRT. Requesting
3// it must preserve visible clouds/depth and explicitly report unavailable.
4static void TestOrganicOpacity(Device11& gpu,CloudRenderer11& renderer,UINT samples)
5{
6 Pipeline pipeline(gpu.Device(),samples);
7 Scene scene(gpu.Device(),samples),opacity(gpu.Device(),samples);
8 CloudVolume::Parameters cloud;cloud.organic=true;cloud.weather=renderer.WeatherFrame();
9 XMFLOAT4X4 view,projection;
10 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,-1,0),XMVectorSet(0,1,0,0)));
11 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1,float(Width)/Height,.001f,384));
12 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
13 const float zero[4]{};
14 for(float altitude:{9.f,30.f,117.f})for(bool fog:{false,true})
15 {
16 const auto render=[&](bool diagnostic) {
17 std::cout<<"Opacity draw: samples="<<samples<<" altitude="<<altitude<<" fog="<<fog
18 <<" diagnostic="<<diagnostic<<" begin\n";
19 renderer.ResetCloudHistory();renderer.Pass().SetAdOpacityTarget(diagnostic ? opacity.target.Get() : nullptr);
20 for(unsigned frame=0;frame<(altitude>37 ? 8u : 1u);++frame)
21 {
22 scene.Clear(gpu.Context());opacity.Clear(gpu.Context());
23 gpu.Context()->ClearRenderTargetView(scene.target.Get(),zero);
24 gpu.Context()->ClearRenderTargetView(opacity.target.Get(),zero);
25 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
26 {0,cloud.radius+altitude,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1},
27 {.125f,.375f,.25f,1},fog ? XMFLOAT4(.05f,.06f,.07f,8) : XMFLOAT4()),"organic opacity render");
28 }
29 if(diagnostic)Check(!renderer.Pass().AdOpacityWritten(),"organic opacity is explicitly unavailable in this alpha");
30 auto result=pipeline.Pixels(gpu,scene,samples);
31 std::cout<<"Opacity draw GPU readback complete\n";
32 return result;
33 };
34 const auto baseline=render(false),measured=render(true),alpha=pipeline.Pixels(gpu,opacity,samples);
35 unsigned visible=0;
36 for(size_t i=0;i<baseline.size();++i)
37 {
38 Check(baseline[i].depth==measured[i].depth,"organic opacity preserves scene depth");
39 for(unsigned c=0;c<4;++c)Check(baseline[i].color[c]==measured[i].color[c],"organic opacity preserves cloud color");
40 Check(alpha[i].color[0]==0,"unavailable opacity target stays untouched");
41 visible+=measured[i].color[3]>.01f;
42 }
43 Check(visible>100,"organic opacity fixture contains visible clouds");
44 }
45 renderer.Pass().SetAdOpacityTarget(nullptr);renderer.ReleaseSizeDependent();DebugMessages(gpu);
46 // The fallback must also decline the unsupported diagnostic safely.
47 cloud.organic=false;renderer.ResetCloudHistory();scene.Clear(gpu.Context());opacity.Clear(gpu.Context());
48 renderer.Pass().SetAdOpacityTarget(opacity.target.Get());
49 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
50 {0,cloud.radius+9,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1}),"baseline opacity after organic disable");
51 Check(!renderer.Pass().AdOpacityWritten(),"baseline opacity also reports unavailable in this alpha");
52 pipeline.Pixels(gpu,scene,samples);DebugMessages(gpu);
53 renderer.Pass().SetAdOpacityTarget(nullptr);renderer.ReleaseSizeDependent();
54 std::cout<<"PASS: diagnostic unavailable without changing visible clouds/depth; fallback safe at "<<samples<<"x MSAA\n";
55}
CloudWeather::Frame weather
Definition CloudVolume.h:35