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

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

1#include "IomereLighting.generated.h"
2
3void IomereLighting(Window11& host)
4{
5 RenderDevice device(host.Draws());
6 HR(device.SetRenderState(RenderState::ZENABLE,FALSE),"Iomere fixture depth");
7 HR(device.SetRenderState(RenderState::STENCILENABLE,FALSE),"Iomere fixture stencil");
8 HR(device.SetRenderState(RenderState::CULLMODE,Cull::NONE),"Iomere fixture culling");
9 HR(device.SetRenderState(RenderState::NORMALIZENORMALS,TRUE),"Iomere normalized surface normals");
10 HR(device.SetTextureStageState(0,TextureState::COLOROP,TextureOperation::SELECTARG2),"Iomere illumination probe");
11 HR(device.SetTextureStageState(0,TextureState::COLORARG2,TextureArgument::DIFFUSE),"Iomere diffuse probe");
12 HR(device.SetTextureStageState(0,TextureState::ALPHAOP,TextureOperation::SELECTARG2),"Iomere probe alpha");
13 HR(device.SetTextureStageState(0,TextureState::ALPHAARG2,TextureArgument::DIFFUSE),"Iomere diffuse alpha");
14 Material material{};material.Diffuse=RiseMath::Color(1,1,1,1);
15 HR(device.SetMaterial(&material),"Iomere diffuse material");
16 struct Vertex {float x,y,z,nx,ny,nz,u=0,v=0,u2=0,v2=0;};
17 const Vertex quad[]={{-.8f,.8f,.3f,0,0,-1},{.8f,.8f,.3f,0,0,-1},{-.8f,-.8f,.3f,0,0,-1},
18 {-.8f,-.8f,.3f,0,0,-1},{.8f,.8f,.3f,0,0,-1},{.8f,-.8f,.3f,0,0,-1}};
19 ComPtr<RenderBuffer> vertices;void* memory=nullptr;
20 HR(device.CreateVertexBuffer(sizeof(quad),0,0,ResourcePool::Managed,&vertices,nullptr),"Iomere probe mesh");
21 HR(vertices->Lock(0,0,&memory,0),"lock Iomere mesh");memcpy(memory,quad,sizeof(quad));
22 HR(vertices->Unlock(),"upload Iomere mesh");
23 Light local{};local.Type=LightKind::DIRECTIONAL;local.Direction={0,0,1};
25 const auto render=[&](float localBrightness, RiseMath::Vector3 sun, bool simulator=false,
26 bool above=true, RiseMath::Color foreground=RiseMath::Color(0,0,0,0), float distance=0.f, float pan=0.f) {
27 local.Diffuse=RiseMath::Color(localBrightness,localBrightness,localBrightness,1);local.Direction=sun;
28 HR(device.SetLight(0,&local),"observer weather light");HR(device.LightEnable(0,TRUE),"enable sun");
29 HR(device.Clear(0,nullptr,ClearFlags::TARGET,0xff000000,1,0),"clear Iomere probe");
30 auto world=identity,view=identity,projection=identity;
32 // Same angular size with the production 256 km far-plane compression.
33 if(distance>0) {
34 RiseMath::MatrixScaling(&world,distance/256,distance/256,distance/256);
35 world._43=distance;view._43=-256;
36 }
37 HR(device.SetTransform(TransformSlot::VIEW,&view),"Iomere camera");
38 HR(device.SetTransform(TransformSlot::PROJECTION,&projection),"Iomere projection");
39 DrawIomereFixture(&device,vertices.Get(),local,world,above,simulator,foreground);
40 const auto& restored=host.Draws().Fixed().lights[0];
41 Check(std::abs(restored.diffuse.x-localBrightness)<1e-6f,"Iomere restores observer weather lighting");
42 return Pixels(host.Device())[24*64+32]&0xffffff;
43 };
44 const auto daylight=render(1,{0,0,1});
45 Check((daylight&255)>240,"sun-facing Iomere receives unobstructed sunlight");
46 for(float observer:{0.f,.01f,.05f,.5f,1.f})
47 Check(render(observer,{0,0,1})==daylight,"Iomere sunlight is independent of observer night/clouds");
48 Check(render(.01f,{0,0,-1})==0,"Iomere night side remains dark");
49 const auto oblique=render(.01f,{.8660254f,0,.5f});
50 Check((oblique&255)>120 && (oblique&255)<135,"Iomere retains cosine surface shading");
51 Check(render(.01f,{.8660254f,0,.5f},false,true,RiseMath::Color(0,0,0,0),0,.25f)==oblique,
52 "panning the camera does not change Iomere surface illumination");
53 Check(render(.01f,{0,0,1},false,true,RiseMath::Color(0,0,0,0),249390)==daylight,
54 "far-plane compression preserves Iomere illumination");
55 const auto throughAir=render(.01f,{0,0,1},false,true,RiseMath::Color(0,0,0,.5f));
56 Check((throughAir&255)>120 && (throughAir&255)<135,"foreground atmosphere still attenuates Iomere");
57 Check(render(.01f,{0,0,1},true)==0,"Iomere remains excluded from simulator");
58 Check(render(.01f,{0,0,1},false,false)==0,"below-cloud visibility gate is preserved");
59 Check(render(.01f,{0,0,1})==daylight,"Iomere returns correctly after simulator/visibility transitions");
60 DebugClean(host.Device());
61 std::cout<<"PASS: Iomere observer independence, phase, far-plane scaling, atmosphere and simulator\n";
62}
constexpr uint8_t Pixels[262144]
Matrix * MatrixRotationY(Matrix *out, float value)
Definition ClientMath.h:127
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
Matrix * MatrixScaling(Matrix *out, float x, float y, float z)
Definition ClientMath.h:124