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

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

1#include "../Viewscreen/ThrustConeRender.h"
2
3// Use the actual vehicle PS4/PS5 and production state guard. A white/cloud
4// backdrop must survive zero alpha, and opaque hull depth must still occlude.
5static void ThrustConeBlending(Window11& host)
6{
7 using namespace ThrustConeRender;
8 Check(Defer(true,false) && !Defer(true,true) && !Defer(false,false),"deferred exhaust excludes simulator and legacy path");
9 for(int type=0;type<256;++type)
10 {
11 const bool cone=type==200 || type==205 || type==210 || type==215 || type==220 || type==225;
12 Check(IsCone(type)==cone && Includes(Pass::All,type),"authored cone IDs and original all-components path");
13 Check(Includes(Pass::BeforeClouds,type)==!cone && Includes(Pass::AfterClouds,type)==cone,"exactly one draw pass per component");
14 }
15 CloudVolume::Parameters cloud;cloud.organic=true;
16 const auto at=[&](float altitude){return CloudVolume::Point{0,cloud.radius+altitude,0};};
17 Check(CloudVolume::Transmittance(at(117),at(116.9f),cloud)==1,"orbital exhaust in front of clouds retains authored alpha");
18 Check(CloudVolume::Transmittance(at(30),at(cloud.base+1),cloud)<.001f,"dense cloud suppresses exhaust behind the layer");
19 for(UINT samples:{1u,4u})
20 {
21 HR(host.SetSamples(samples),"exhaust MSAA target");
22 RenderDevice device(host.Draws());RenderMaterial material(device);
23 HR(device.SetRenderState(RenderState::CULLMODE,Cull::NONE),"cone test culling");
24 HR(device.SetRenderState(RenderState::STENCILENABLE,FALSE),"cone test stencil");
25 HR(device.SetRenderState(RenderState::ZENABLE,TRUE),"opaque hull depth");
26 HR(device.SetRenderState(RenderState::ZWRITEENABLE,TRUE),"opaque hull writes");
27 HR(device.SetFVF(VertexFormat::XYZ|VertexFormat::NORMAL|VertexFormat::TEX2),"cone vertex layout");
28 struct Vertex {float x,y,z,nx=0,ny=0,nz=-1,u=.5f,v=.5f,u2=0,v2=0;};
29 const Vertex vertices[]={{-1,-1,.5f},{0,1,.5f},{1,-1,.5f}};
30 ComPtr<RenderBuffer> buffer;void* memory=nullptr;
31 HR(device.CreateVertexBuffer(sizeof(vertices),0,0,ResourcePool::Managed,&buffer,nullptr),"cone fixture buffer");
32 HR(buffer->Lock(0,0,&memory,0),"cone lock");memcpy(memory,vertices,sizeof(vertices));HR(buffer->Unlock(),"cone upload");
33 HR(device.SetStreamSource(0,buffer.Get(),0,sizeof(Vertex)),"cone stream");
34 ComPtr<RenderTexture> texture;
35 HR(CreateTexture(&device,1,1,1,0,ImageFormat::BGRA8,ResourcePool::Managed,&texture),"cone texture");
36 LockedRectangle texel;HR(texture->LockRect(0,&texel,nullptr,0),"cone texture lock");
37 *static_cast<DWORD*>(texel.pBits)=0x8000ffff;HR(texture->UnlockRect(0),"cone texture upload");
38 HR(material.SetTexture("ColorMap",texture.Get()),"authored cone alpha texture");
40 HR(material.SetMatrix("matWorld",&identity),"cone world");HR(material.SetMatrix("matWorldViewProj",&identity),"cone projection");
41 const auto draw=[&](UINT shader,float thrust,float cloak,float depth,bool writeRegression=false) {
42 HR(device.Clear(0,nullptr,ClearFlags::TARGET|ClearFlags::ZBUFFER|ClearFlags::STENCIL,0xffffffff,depth,0),"cloud backdrop");
43 RiseMath::Vector4 features(cloak,0,0,0),control(0,0,thrust,200);
44 HR(material.SetVector("Features",&features),"cone cloak");HR(material.SetVector("clouduv",&control),"cone throttle");
45 {
46 OverlayState state(device);
47 if(writeRegression)HR(device.SetRenderState(RenderState::ZWRITEENABLE,TRUE),"old opaque cone depth");
48 HR(material.Begin(nullptr,0),"cone begin");HR(material.BeginPass(shader),"actual cone shader");
49 HR(device.DrawPrimitive(Primitive::TriangleList,0,1),"cone draw");
50 HR(material.EndPass(),"cone end pass");HR(material.End(),"cone end");
51 }
52 DWORD restored=0;HR(device.GetRenderState(RenderState::ZWRITEENABLE,&restored),"cone state restore");
53 Check(restored==TRUE,"overlay restores caller depth writes");
54 return Pixels(host.Device())[24*64+32];
55 };
56 for(UINT shader:{4u,5u})
57 {
58 Check(draw(shader,0,1,1)==0xffffffff,"zero throttle leaves cloud pixels untouched");
59 Check(draw(shader,1,0,1)==0xffffffff,"zero cloak alpha leaves cloud pixels untouched");
60 Check(draw(shader,1,1,.25f)==0xffffffff,"foreground opaque hull hides exhaust");
61 const auto half=draw(shader,1,1,1);
62 Check(((half>>16)&255)>=126 && ((half>>16)&255)<=128 && (half&65535)==65535,"half-alpha exhaust blends with white clouds");
63 const auto quarter=draw(shader,.5f,1,1);
64 Check(((quarter>>16)&255)>=190 && ((quarter>>16)&255)<=192,"partial cloud transmission attenuates cone alpha once");
65 // Read-only depth: clear only color, then draw a farther opaque
66 // surface. A cone at .5 must not reject that surface at .75.
67 for(bool oldDepth:{true,false})
68 {
69 draw(shader,1,1,1,oldDepth);
70 HR(device.Clear(0,nullptr,ClearFlags::TARGET,0xffffffff,1,0),"retain depth after cone");
71 auto behind=identity;behind._43=.25f;
72 HR(material.SetMatrix("matWorldViewProj",&behind),"surface behind cone");
73 {
74 OverlayState state(device);
75 HR(material.Begin(nullptr,0),"depth probe begin");HR(material.BeginPass(shader),"depth probe shader");
76 HR(device.DrawPrimitive(Primitive::TriangleList,0,1),"farther depth probe");
77 HR(material.EndPass(),"probe end pass");HR(material.End(),"probe end");
78 }
79 Check((Pixels(host.Device())[24*64+32]&0xffffff)==(oldDepth ? 0xffffff : half&0xffffff),
80 oldDepth ? "old cone depth reproduces missing background" : "exhaust never becomes opaque depth for later geometry");
81 HR(material.SetMatrix("matWorldViewProj",&identity),"reset cone projection");
82 }
83 }
84 DebugClean(host.Device());
85 }
86 HR(host.SetSamples(1),"restore test target samples");
87 std::cout<<"PASS: actual thrust shaders, cloud backdrop alpha, hull occlusion, read-only depth, 1x/4x MSAA and simulator routing\n";
88}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
float Transmittance(Point from, Point to, const Parameters &params, uint32_t seed=DefaultSeed)
constexpr uint8_t Pixels[262144]
HRESULT CreateTexture(RenderDevice *owner, UINT width, UINT height, UINT levels, DWORD usage, ImageFormat format, ResourcePool pool, RenderTexture **result)
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
bool Includes(Pass pass, int type)
bool Defer(bool volumeClouds, bool simulator)
bool IsCone(int type)