Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/BrandCapture11.cpp

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

1// Offline brand review scenes. Production D3D11 model/material/cloud/rain paths;
2// no login, packets, live entity changes, campaign accounting or external delivery.
3#include "../Rendering/ClientRenderer11.h"
4#include "../Rendering/CloudRenderer11.h"
5#include "../Rendering/ExteriorRain11.h"
6#include "../Rendering/Window11.h"
7#include "../Viewscreen/RtsTerrainSurface.h"
8#include "BrandMaterials.generated.h"
9#include <cmath>
10#include <d3d11sdklayers.h>
11#include <fstream>
12#include <iomanip>
13#include <iostream>
14#include <set>
15#include <stdexcept>
16using namespace Rendering;
17using namespace DirectX;
18using Microsoft::WRL::ComPtr;
19namespace fs = std::filesystem;
20void RasterizeBrandSvg(RenderDevice &, const fs::path &, const fs::path &);
21static void HR(HRESULT value, const char *what)
22{
23 if (FAILED(value))
24 throw std::runtime_error(std::string(what) + " HRESULT=" + std::to_string(value));
25}
26static void Check(bool value, const char *what)
27{
28 if (!value)
29 throw std::runtime_error(what);
30}
31struct Vertex
32{
33 float x, y, z, nx, ny, nz, u, v, ou, ov;
34};
35struct Component
36{
37 unsigned first = 0, count = 0;
38 int texture = 0, type = 0, attach = 0;
39 bool lit = false;
40 float rate = 0;
41 XMFLOAT3 position{}, rotation{}, hinge{};
42};
43struct Mesh
44{
45 ComPtr<RenderBuffer> buffer;
46 std::vector<Vertex> vertices;
47 std::vector<Component> components;
48};
49template <typename T> static T Read(std::ifstream &file, std::streamoff offset)
50{
51 T result{};
52 file.seekg(offset);
53 file.read(reinterpret_cast<char *>(&result), sizeof(result));
54 Check(bool(file), "truncated authored model");
55 return result;
56}
57static Mesh LoadMesh(RenderDevice &device, const fs::path &stem, bool overlay)
58{
59 Mesh mesh;
60 std::ifstream daw(stem.wstring() + L".daw", std::ios::binary), dix(stem.wstring() + L".dix", std::ios::binary);
61 Check(bool(daw) && bool(dix), "model files missing");
62 const auto count = Read<uint16_t>(daw, 0);
63 const unsigned stride = overlay ? 40u : 32u;
64 mesh.vertices.resize(count);
65 for (unsigned i = 0; i < count; ++i)
66 {
67 Vertex v{};
68 daw.seekg(2 + std::streamoff(i) * stride);
69 daw.read(reinterpret_cast<char *>(&v), stride);
70 Check(bool(daw), "truncated vertex");
71 mesh.vertices[i] = v;
72 }
73 const auto total = Read<uint16_t>(dix, 0);
74 const float version = Read<float>(dix, 2);
75 for (unsigned i = 0; i < total; ++i)
76 {
77 const auto o = 99 + std::streamoff(i) * 100;
78 Component c;
79 c.first = Read<uint16_t>(dix, o);
80 c.count = Read<uint16_t>(dix, o + 2);
81 c.position = Read<XMFLOAT3>(dix, o + 4);
82 c.rotation = Read<XMFLOAT3>(dix, o + 16);
83 c.texture = Read<int16_t>(dix, o + 44);
84 c.type = Read<uint8_t>(dix, o + 58);
85 c.hinge = Read<XMFLOAT3>(dix, o + 75);
86 c.attach = Read<int16_t>(dix, o + 91);
87 if (version >= 2.44f)
88 {
89 c.lit = Read<uint8_t>(dix, o + 93) != 0;
90 c.rate = Read<float>(dix, o + 94);
91 }
92 Check(c.first + c.count * 3 <= count, "component vertex range");
93 mesh.components.push_back(c);
94 }
95 HR(device.CreateVertexBuffer(UINT(mesh.vertices.size() * sizeof(Vertex)), 0, 0, ResourcePool::Managed, &mesh.buffer,
96 nullptr),
97 "model buffer");
98 void *data = nullptr;
99 HR(mesh.buffer->Lock(0, 0, &data, 0), "model lock");
100 memcpy(data, mesh.vertices.data(), mesh.vertices.size() * sizeof(Vertex));
101 HR(mesh.buffer->Unlock(), "model upload");
102 return mesh;
103}
104struct Textures
105{
106 ComPtr<RenderTexture> base, light;
107};
108class MaterialCache
109{
110 RenderDevice &device;
111 std::map<std::pair<std::string, int>, Textures> items;
112
113 public:
114 std::set<std::string> sources;
115 explicit MaterialCache(RenderDevice &value) : device(value)
116 {
117 }
118 Textures &Get(const char *scope, int index)
119 {
120 auto key = std::make_pair(std::string(scope), index);
121 auto it = items.find(key);
122 if (it != items.end())
123 return it->second;
124 for (const auto &route : Routes)
125 if (key.first == route.scope && index == route.index)
126 {
127 Textures t;
128 HR(LoadTexture(&device, route.base, &t.base, scope == std::string("ship") ? 1u : 0u),
129 "production base texture");
130 sources.insert(fs::path(route.base).generic_string());
131 if (*route.light)
132 {
133 HR(LoadTexture(&device, route.light, &t.light), "production light texture");
134 sources.insert(fs::path(route.light).generic_string());
135 }
136 return items.emplace(key, std::move(t)).first->second;
137 }
138 throw std::runtime_error("missing production texture route " + key.first + "/" + std::to_string(index));
139 }
140};
141static RiseMath::Matrix Matrix(FXMMATRIX value)
142{
143 RiseMath::Matrix result;
144 XMStoreFloat4x4(reinterpret_cast<XMFLOAT4X4 *>(&result), value);
145 return result;
146}
147static void Vector(RenderMaterial &effect, const char *name, float x, float y, float z, float w)
148{
149 const RiseMath::Vector4 value(x, y, z, w);
150 HR(effect.SetVector(name, &value), name);
151}
152static void Transform(RenderMaterial &effect, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection)
153{
154 auto m = Matrix(world);
155 HR(effect.SetMatrix("matWorld", &m), "world");
156 m = Matrix(world * view * projection);
157 HR(effect.SetMatrix("matWorldViewProj", &m), "view projection");
158}
159static void DrawMesh(RenderDevice &device, RenderMaterial &effect, MaterialCache &cache, const Mesh &mesh,
160 const char *scope, FXMMATRIX base, CXMMATRIX view, CXMMATRIX projection, bool vehicle, bool night)
161{
162 HR(device.SetStreamSource(0, mesh.buffer.Get(), 0, sizeof(Vertex)), "mesh stream");
163 HR(device.SetFVF(VertexFormat::XYZ | VertexFormat::NORMAL | VertexFormat::TEX2), "authored UV layout");
164 HR(effect.BeginPass(vehicle ? 5u : 2u), "production vehicle/building pass");
165 for (const auto &c : mesh.components)
166 {
167 if (vehicle && c.attach == 7)
168 continue;
169 auto &t = cache.Get(scope, c.texture);
170 HR(effect.SetTexture("ColorMap", t.base.Get()), "base");
171 HR(effect.SetTexture("ColorMap2", t.light.Get()), "light");
172 const auto world = XMMatrixRotationRollPitchYaw(c.rotation.y, c.rotation.x, c.rotation.z) *
173 XMMatrixTranslation(c.position.x, c.position.y, c.position.z) * base;
174 Transform(effect, world, view, projection);
175 if (!vehicle)
176 Vector(effect, "Features", float(c.type), 0, 0, 0);
177 if (vehicle)
178 Vector(effect, "clouduv", 0, t.light && c.lit ? 1.f : 0.f, c.rate, float(c.type));
179 else
180 Vector(effect, "clouduv", 0, 0, night ? .7f : 0.f, night ? 1.f : 0.f);
181 HR(device.DrawPrimitive(Primitive::TriangleList, c.first, c.count), "draw production component");
182 }
183 HR(effect.EndPass(), "end production pass");
184}
185static Mesh Ground(RenderDevice &device, const fs::path &rts)
186{
187 Mesh mesh;
188 std::ifstream file(rts, std::ios::binary);
189 Check(bool(file), "RTS map missing");
190 const float span = 2.028f;
192 {{{-span / 2, span / 2, 0}, {0, span / 2, 0}, {span / 2, span / 2, 0}},
193 {{-span / 2, 0, 0}, {0, 0, 0}, {span / 2, 0, 0}},
194 {{-span / 2, -span / 2, 0}, {0, -span / 2, 0}, {span / 2, -span / 2, 0}}}};
195 for (int east = 0; east < 26; ++east)
196 for (int north = 0; north < 26; ++north)
197 {
198 unsigned char tile[2]{};
199 file.read(reinterpret_cast<char *>(tile), 2);
200 Check(bool(file), "truncated RTS map");
201 if (!tile[1])
202 continue;
203 Component c;
204 c.first = unsigned(mesh.vertices.size());
205 c.count = 2;
206 c.texture = tile[1];
207 mesh.components.push_back(c);
208 for (const auto corner : RtsTerrain::TileCorners)
209 {
210 const auto p = surface.Sample(east + corner.east, north + corner.north);
211 const auto uv = RtsTerrain::TextureCoordinate(corner, tile[0]);
212 mesh.vertices.push_back({p.x, p.y, p.z, 0, 0, 1, uv.u, uv.v, float(east + corner.east) / 26,
213 float(north + corner.north) / 26});
214 }
215 }
216 HR(device.CreateVertexBuffer(UINT(mesh.vertices.size() * sizeof(Vertex)), 0, 0, ResourcePool::Managed, &mesh.buffer,
217 nullptr),
218 "RTS buffer");
219 void *data = nullptr;
220 HR(mesh.buffer->Lock(0, 0, &data, 0), "RTS lock");
221 memcpy(data, mesh.vertices.data(), mesh.vertices.size() * sizeof(Vertex));
222 HR(mesh.buffer->Unlock(), "RTS upload");
223 return mesh;
224}
225static void DrawGround(RenderDevice &device, RenderMaterial &effect, MaterialCache &cache, const Mesh &ground,
226 FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, bool night)
227{
228 HR(device.SetStreamSource(0, ground.buffer.Get(), 0, sizeof(Vertex)), "RTS stream");
230 Transform(effect, world, view, projection);
231 HR(effect.SetTexture("CityRoadNorth", cache.Get("rts", 62).base.Get()), "north road");
232 HR(effect.SetTexture("CityRoadSouth", cache.Get("rts", 63).base.Get()), "south road");
233 ComPtr<RenderTexture> road;
234 HR(LoadTexture(&device, L"Textures/RTS/Road.dds", &road), "road material");
235 HR(effect.SetTexture("ColorMap4", road.Get()), "road edge blend");
236 cache.sources.insert("Textures/RTS/Road.dds");
237 RiseMath::Vector4 zero[4]{};
238 HR(effect.SetVectorArray("RtsRoadEmission", zero, 4), "road emission");
239 Vector(effect, "clouduv", 0, 0, night ? .2f : 0.f, night ? 1.f : 0.f);
240 HR(effect.BeginPass(11), "production RTS pass");
241 for (const auto &c : ground.components)
242 {
243 auto &t = cache.Get("rts", c.texture);
244 HR(effect.SetTexture("ColorMap", t.base.Get()), "RTS base");
245 HR(effect.SetTexture("ColorMap2", t.light.Get()), "RTS lights");
246 Vector(effect, "Features", 0,
247 c.texture == 62 ? 1.f
248 : c.texture == 63 ? 2.f
249 : 0.f,
250 night ? .2f : 0.f, t.light ? 1.f : 0.f);
251 HR(device.DrawPrimitive(Primitive::TriangleList, c.first, c.count), "RTS tile");
252 }
253 HR(effect.EndPass(), "RTS pass end");
254}
255static void DebugClean(Device11 &gpu)
256{
257 ComPtr<ID3D11InfoQueue> queue;
258 if (FAILED(gpu.Device()->QueryInterface(IID_PPV_ARGS(&queue))))
259 return;
260 for (UINT64 i = 0; i < queue->GetNumStoredMessages(); ++i)
261 {
262 SIZE_T size = 0;
263 queue->GetMessage(i, nullptr, &size);
264 std::vector<char> data(size);
265 auto *m = reinterpret_cast<D3D11_MESSAGE *>(data.data());
266 HR(queue->GetMessage(i, m, &size), "debug message");
267 if (m->Severity <= D3D11_MESSAGE_SEVERITY_WARNING)
268 throw std::runtime_error(m->pDescription);
269 }
270 queue->ClearStoredMessages();
271}
272struct WeatherCase
273{
274 const char *name;
275 uint8_t activity;
276 float sunlight, ambient, fog, cloudBase;
277 bool rain, night;
278};
279int main(int argc, char **argv)
280{
281 struct ComLifetime
282 {
283 HRESULT result = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
284 ~ComLifetime()
285 {
286 if (SUCCEEDED(result))
287 CoUninitialize();
288 }
289 } com;
290 try
291 {
292 HR(com.result, "COM initialization");
293 fs::path output = "outputs/brand-capture", logo, model = "Meshes/cargo-standard", svg;
294 int type = 12;
295 unsigned limit = 0;
296 float cameraDistanceScale = 1.f;
297 bool debug = true;
298 std::string sceneFilter, weatherFilter, angleFilter;
299 for (int i = 1; i < argc; ++i)
300 {
301 std::string a = argv[i];
302 if (a == "--output" && i + 1 < argc)
303 output = argv[++i];
304 else if (a == "--logo" && i + 1 < argc)
305 logo = argv[++i];
306 else if (a == "--svg" && i + 1 < argc)
307 svg = argv[++i];
308 else if (a == "--mesh" && i + 1 < argc)
309 model = argv[++i];
310 else if (a == "--vehicle-type" && i + 1 < argc)
311 type = std::stoi(argv[++i]);
312 else if (a == "--limit" && i + 1 < argc)
313 limit = std::stoul(argv[++i]);
314 else if (a == "--scene" && i + 1 < argc)
315 sceneFilter = argv[++i];
316 else if (a == "--weather" && i + 1 < argc)
317 weatherFilter = argv[++i];
318 else if (a == "--angle" && i + 1 < argc)
319 angleFilter = argv[++i];
320 else if (a == "--camera-distance-scale" && i + 1 < argc)
321 cameraDistanceScale = std::stof(argv[++i]);
322 else if (a == "--no-debug-layer")
323 debug = false;
324 else
325 throw std::runtime_error("unknown/missing argument");
326 }
327 Check(!logo.empty() && (fs::exists(logo) || !svg.empty()), "--logo must name the reviewed transparent PNG");
328 Check(cameraDistanceScale >= .2f && cameraDistanceScale <= 1.f, "camera distance scale must be between .2 and 1");
329 fs::create_directories(output);
330 SetEnvironmentVariableA("RISE_VOLUMETRIC_CLOUDS", "1");
331 SetEnvironmentVariableA("RISE_CLOUD_SEED", "0x52495345");
332 SetEnvironmentVariableA("RISE_LIGHTNING_SEED", "123456");
333 WindowOptions11 options;
334 options.visible = false;
335 options.width = 1920;
336 options.height = 1080;
337 options.samples = 4;
338 options.debugLayer = debug;
339 Window11 host;
340 HR(host.Create(options, {}), "hidden game render host");
341 HR(host.Resize(1920, 1080), "capture size");
342 RenderDevice device(host.Draws());
343 RenderMaterial effect(device);
344 if (!svg.empty())
345 {
346 RasterizeBrandSvg(device, svg, logo);
347 std::cout << "Prepared logo PNG: " << logo.generic_string() << std::endl;
348 return 0;
349 }
350 MaterialCache cache(device);
351 ComPtr<RenderTexture> cloudDetail;
352 HR(LoadTexture(&device, L"Textures/Clouds/clouddetailbelow.dds", &cloudDetail, 1), "production cloud detail");
353 HR(effect.SetTexture("CloudMap", cloudDetail.Get()), "terrain cloud light");
354 cache.sources.insert("Textures/Clouds/clouddetailbelow.dds");
355 ComPtr<RenderTexture> overlay;
356 HR(LoadTexture(&device, logo.c_str(), &overlay), "logo texture");
357 auto cargo = LoadMesh(device, model, true);
358 CloudRenderer11 clouds;
359 HR(clouds.Initialize(device.Native()), "production cloud renderer");
360 clouds.SetLightningEnabled(false);
361 ExteriorRain11 rain;
362 HR(rain.Initialize(device.Native()), "production rain renderer");
363 std::ofstream csv(output / "captures.csv");
364 csv << "file,scene,vehicle_type,weather,angle,eye_x_km,eye_y_km,eye_z_km,target_x_km,target_y_km,target_z_km,"
365 "rain_particles,cloud_activity,cloud_base_km,sunlight,ambient,fog_visibility_km,nearby_light_r,nearby_"
366 "light_g,nearby_light_b,sky_path,cloud_composited,background_zenith_weight,background_r,background_g,"
367 "background_b,sun_cosine,width,height,requested_"
368 "msaa,actual_msaa\n";
369 unsigned captured = 0;
370 // Vieneo is continuously cloud-covered: activity=0 is quiet stratus,
371 // not clear sky. Render the production deck in every preset.
372 const WeatherCase weather[] = {{"quiet-cloud-day", 0, 1.f, .35f, 20.f, 1.8f, false, false},
373 {"active-cloud-day", 185, .2f, .28f, 3.f, .6f, false, false},
374 {"rain-dusk", 200, .15f, .16f, .7f, .45f, true, false},
375 {"lit-cloud-night", 0, 0, .1f, 12.f, 1.8f, false, true}};
376 const char *names[] = {"deois-industrial", "deois-port"};
377 const wchar_t *stems[] = {L"Meshes/DEOIS-Industrial", L"Meshes/DEOIS-Port"};
378 // Authored district layouts are retained; this local scenario uses a flat
379 // plot with deterministic sky/weather, not a reconstructed live server tile.
380 const XMFLOAT3 placements[] = {{.118f, -.50f, 0}, {-.035f, -.09f, 0}};
381 const XMFLOAT3 offsets[] = {{-.0065f, -.0075f, .0038f}, {.0065f, -.0075f, .0038f}, {.008f, .0015f, .0075f}};
382 const char *angles[] = {"left-three-quarter", "right-three-quarter", "elevated-side"};
383 for (unsigned scene = 0; scene < 2; ++scene)
384 {
385 if (!sceneFilter.empty() && sceneFilter != names[scene])
386 continue;
387 auto city = LoadMesh(device, stems[scene], false);
388 auto ground = Ground(device, fs::path(stems[scene]).wstring() + L".rts");
389 const auto place = placements[scene];
390 for (const auto &w : weather)
391 {
392 if (!weatherFilter.empty() && weatherFilter != w.name)
393 continue;
394 auto map = std::make_shared<CloudWeather::Map>();
395 map->mips.push_back({64, 32, std::vector<uint8_t>(64 * 32, w.activity)});
397 clouds.UpdateWeather(map, 60);
398 HR(clouds.PrepareResources(device.Context()), "weather resources");
399 clouds.UpdateWeather(map, 60);
400 for (unsigned angle = 0; angle < 3; ++angle)
401 {
402 if (!angleFilter.empty() && angleFilter != angles[angle])
403 continue;
404 if (limit && captured >= limit)
405 break;
406 const auto o = offsets[angle];
407 const XMFLOAT3 target{place.x, place.y, place.z + .0013f};
408 const XMFLOAT3 eye{target.x + o.x * cameraDistanceScale,
409 target.y + o.y * cameraDistanceScale,
410 target.z + (o.z - .0013f) * cameraDistanceScale};
411 const auto view = XMMatrixLookAtRH(XMVectorZero(), XMLoadFloat3(&target) - XMLoadFloat3(&eye),
412 XMVectorSet(0, 0, 1, 0));
413 const float nearZ = .00005f, nearWidth = nearZ * std::tan(XMConvertToRadians(115.f) * .5f);
414 const auto projection = XMMatrixPerspectiveRH(nearWidth, nearWidth * 1080 / 1920, nearZ, 384.f);
416 params.weather = clouds.WeatherFrame();
417 params.activity = w.activity / 255.f;
418 params.base = w.cloudBase;
419 const CloudVolume::Point planetEye{eye.x, eye.y, params.radius + eye.z};
420 const float altitude = CloudVolume::Length(planetEye) - params.radius;
421 const auto column = CloudVolume::Boundaries(planetEye, params, clouds.Seed());
422 const float sunCosine = w.night ? -1.f : w.rain ? -.03f : .85f;
423 // Match weather.cpp: airglow belongs to the medium, not object light.
424 // Ambient remains a labeled scripted illumination input, not live weather.
425 const CloudVolume::Point airglow{.125f, .375f, .25f};
426 const auto cloudFog = CloudVolume::WithAirglow({w.ambient, w.ambient, w.ambient}, airglow,
427 sunCosine, altitude, column.base, column.top);
428 const float zenithWeight = CloudVolume::BackgroundZenithWeight(altitude, params);
429 // Same below-deck background/fog/base convention as OnFrameRender.
430 // At these surface cameras zenithWeight is zero: no blue clear-sky seam.
431 Check(zenithWeight == 0.f, "Vieneo preset camera must remain below the cloud deck");
432 const RiseMath::Color sky(cloudFog.x, cloudFog.y, cloudFog.z, 1);
433 const XMFLOAT3 cloudSun{std::sqrt(1.f - sunCosine * sunCosine), 0, -sunCosine};
434 const float incident = std::exp(-.5f * std::exp(-params.top / 7.5f));
435 const XMFLOAT4 cloudLight{.9411764706f * incident, .9607843137f * incident, incident, 1};
436 host.Draws().BindScene();
437 HR(device.Clear(0, nullptr, ClearFlags::TARGET | ClearFlags::ZBUFFER | ClearFlags::STENCIL, sky, 1,
438 0),
439 "clear scene");
440 HR(device.SetRenderState(RenderState::ZENABLE, TRUE), "depth");
441 HR(device.SetRenderState(RenderState::CULLMODE, Cull::CW), "scene culling");
442 HR(device.SetRenderState(RenderState::ALPHABLENDENABLE, FALSE), "opaque scene");
443 HR(effect.Begin(nullptr, 0), "scene material");
444 Vector(effect, "ambient", w.ambient, w.ambient, w.ambient, w.fog);
445 Vector(effect, "Sunlight", -.45f, .25f, .85f, w.sunlight);
446 Vector(effect, "Radiosity", 0, 0, 1, .08f);
447 Vector(effect, "Tangent", 1, 1, 1, 0);
448 Vector(effect, "shiplight", w.night ? .4f : 0.f, w.night ? .34f : 0.f, w.night ? .25f : 0.f, 0);
449 Vector(effect, "WeapPos", 0, 0, 0, 0);
450 Vector(effect, "volumeFog", sky.r, sky.g, sky.b, 1 / w.fog);
451 HR(effect.SetInt("LandingLightCount", 0), "disable player lamps");
452 HR(device.SetRenderState(RenderState::CULLMODE, Cull::NONE), "ground two sided");
453 DrawGround(device, effect, cache, ground, XMMatrixTranslation(-eye.x, -eye.y, -eye.z), view,
454 projection, w.night);
455 HR(device.SetRenderState(RenderState::CULLMODE, Cull::CW), "restore authored mesh culling");
456 Vector(effect, "Features", 0, 0, 0, 0);
457 HR(effect.SetTexture("OverlayMap", nullptr), "clear scenery logo");
458 DrawMesh(device, effect, cache, city, "city", XMMatrixTranslation(-eye.x, -eye.y, -eye.z), view,
459 projection, false, w.night);
460 HR(effect.SetTexture("OverlayMap", overlay.Get()), "assigned brand creative");
461 Vector(effect, "Features", 1, 1, 1, type == 10 ? 1.f : 0.f);
462 Vector(effect, "ambient", w.ambient, w.ambient, w.ambient, w.fog);
463 const auto base = XMMatrixRotationZ(XM_PI) *
464 XMMatrixTranslation(place.x - eye.x, place.y - eye.y, place.z - eye.z);
465 DrawMesh(device, effect, cache, cargo, "ship", base, view, projection, true, w.night);
466 HR(effect.End(), "scene material end");
467 XMFLOAT4X4 v, p;
468 XMStoreFloat4x4(&v, view);
469 XMStoreFloat4x4(&p, projection);
470 HR(clouds.Render(device.Context(), host.Device().SceneTarget(), host.Device().Depth(),
471 host.Draws().Viewport(), v, p, {planetEye.x, planetEye.y, planetEye.z}, params,
472 cloudSun, cloudLight, {w.ambient, w.ambient, w.ambient, 1},
473 {airglow.x, airglow.y, airglow.z, 1}, {sky.r, sky.g, sky.b, w.fog},
474 {sky.r, sky.g, sky.b, CloudVolume::AtmosphericHazeDistanceKm(params.top)}),
475 "production Vieneo cloud-deck composite");
476 if (w.rain)
477 {
479 rainParams.precipitation = 32;
480 rainParams.intensity = .8f;
481 rainParams.upWorld = {0, 0, 1};
482 rainParams.wind = {.004f, 0, 0};
483 rainParams.sunlight = {.45f, .45f, .48f, 1};
484 XMFLOAT4X4 camera;
485 XMStoreFloat4x4(&camera, XMMatrixInverse(nullptr, view));
486 for (unsigned warm = 0; warm < 60; ++warm)
487 rain.Update(1.f / 60, rainParams, camera);
488 HR(rain.Render(device.Context(), host.Device().SceneTarget(), host.Device().Depth(),
489 host.Draws().Viewport(), v, p, &clouds),
490 "production exterior rain");
491 }
492 const std::string filename =
493 std::string(names[scene]) + "-" + w.name + "-" + angles[angle] + ".png";
494 ComPtr<RenderSurface> surface;
495 HR(device.GetBackBuffer(0, 0, 0, &surface), "capture surface");
496 HR(SaveSurfaceToFile((output / filename).c_str(), ImageFile::PNG, surface.Get(), nullptr, nullptr),
497 "PNG encode");
498 D3D11_TEXTURE2D_DESC desc{};
499 host.Device().SceneColor()->GetDesc(&desc);
500 csv << filename << ',' << names[scene] << ',' << type << ',' << w.name << ',' << angles[angle]
501 << ',' << eye.x << ',' << eye.y << ',' << eye.z << ',' << target.x << ',' << target.y << ','
502 << target.z << ',' << (w.rain ? rain.DropCount() : 0) << ',' << params.activity << ','
503 << params.base << ',' << w.sunlight << ',' << w.ambient << ',' << w.fog << ','
504 << (w.night ? .4f : 0.f) << ',' << (w.night ? .34f : 0.f) << ',' << (w.night ? .25f : 0.f)
505 << ",vieneo-below-cloud-base,1," << zenithWeight << ',' << sky.r << ',' << sky.g << ',' << sky.b
506 << ',' << sunCosine << ",1920,1080,4," << desc.SampleDesc.Count << '\n';
507 Check(bool(csv), "metadata write");
508 DebugClean(host.Device());
509 std::cout << filename << std::endl;
510 ++captured;
511 }
512 if (limit && captured >= limit)
513 break;
514 }
515 if (limit && captured >= limit)
516 break;
517 }
518 Check(captured > 0, "scene/weather/angle selectors matched no capture preset");
519 std::ofstream assets(output / "assets.txt");
520 assets << "Private unapproved branding review. Controlled offline scenes using production game shaders and "
521 "authored assets.\nModel: "
522 << model.generic_string() << "\nLogo: " << logo.generic_string() << "\n";
523 for (const auto &path : cache.sources)
524 assets << path << '\n';
525 std::cout << "PASS: captured " << captured << " production-renderer images; no server connected. "
526 << host.Device().Status() << '\n';
527 return 0;
528 }
529 catch (const std::exception &error)
530 {
531 std::cerr << "FAIL: " << error.what() << '\n';
532 return 1;
533 }
534}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, const Vector &planetEye, const CloudVolume::Parameters &params, const Vector &sunlight, const Color &light, const Color &ambient, const Color &airglow=Color(.125f,.375f,.25f, 1), const Color &horizonHaze=Color(0, 0, 0, 0), const Color &atmosphereHaze=Color(0, 0, 0, 0), const Color &nightVisionGain=Color(1, 1, 1, 0))
CloudWeather::Frame WeatherFrame()
void SetLightningEnabled(bool value)
void UpdateWeather(const CloudWeather::MapPtr &map, double elapsed)
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
HRESULT PrepareResources(ID3D11DeviceContext *context)
ID3D11Texture2D * SceneColor() const
Definition Device11.h:69
ID3D11RenderTargetView * SceneTarget() const
Definition Device11.h:68
ID3D11Device * Device() const
Definition Device11.h:65
const std::string & Status() const
Definition Device11.h:75
const SceneDepth11 & Depth() const
Definition Device11.h:70
const D3D11_VIEWPORT & Viewport() const
unsigned DropCount() const
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
ExteriorRain::BasicParameters< Vector, Color > Parameters
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, CloudRenderer11 *clouds=nullptr)
void Update(float elapsed, const Parameters &parameters, const Matrix &localToWorld)
HRESULT DrawPrimitive(Primitive type, UINT first, UINT count)
HRESULT SetStreamSource(UINT stream, RenderBuffer *buffer, UINT offset, UINT stride)
ID3D11DeviceContext * Context()
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT SetFVF(DWORD value)
HRESULT Clear(DWORD count, const RECT *rectangles, DWORD flags, PackedColor color, float depth, DWORD stencil)
HRESULT CreateVertexBuffer(UINT bytes, DWORD usage, DWORD format, ResourcePool pool, RenderBuffer **result, void *shared)
HRESULT GetBackBuffer(UINT chain, UINT buffer, UINT type, RenderSurface **result)
HRESULT SetInt(const char *name, int value)
HRESULT SetVectorArray(const char *name, const RiseMath::Vector4 *value, UINT count)
HRESULT SetVector(const char *name, const RiseMath::Vector4 *value)
HRESULT Begin(UINT *count, DWORD flags)
HRESULT BeginPass(UINT pass)
HRESULT SetTexture(const char *name, RenderTexture *value)
HRESULT SetMatrix(const char *name, const RiseMath::Matrix *value)
DrawContext11 & Draws()
Definition Window11.h:52
HRESULT Create(const WindowOptions11 &options, Callbacks callbacks)
Definition Window11.cpp:24
HRESULT Resize(UINT width, UINT height)
Definition Window11.cpp:74
Device11 & Device()
Definition Window11.h:51
float BackgroundZenithWeight(float altitude, const Parameters &params)
Definition CloudVolume.h:52
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Length(Point p)
Definition CloudVolume.h:94
Point WithAirglow(Point scattered, Point airglow, float sunCosine, float altitude, float base, float top)
void BuildMips(Map &map)
Definition DDS.h:24
Light Transform(const Light &source, const RiseMath::Matrix &modelToWorld)
Kinematic Ground(Vec r, double spin, double time)
constexpr uint32_t TARGET
constexpr uint32_t ZBUFFER
constexpr uint32_t STENCIL
constexpr uint32_t CW
constexpr uint32_t NONE
DirectX::XMFLOAT3 Vector
Definition Math11.h:7
DirectX::XMFLOAT4X4 Matrix
Definition Math11.h:9
constexpr uint32_t CULLMODE
constexpr uint32_t ALPHABLENDENABLE
constexpr uint32_t ZENABLE
constexpr uint32_t NORMAL
constexpr uint32_t XYZ
constexpr uint32_t TEX2
HRESULT SaveSurfaceToFile(const wchar_t *path, ImageFile format, RenderSurface *surface, const void *, const RECT *crop)
HRESULT LoadTexture(RenderDevice *owner, const wchar_t *path, RenderTexture **result, UINT levels=0, UINT width=0, UINT height=0)
constexpr TileCorner TileCorners[6]
TexCoord TextureCoordinate(TileCorner corner, unsigned char rotation)
path
Definition erin.py:153
type
Definition erin.py:143
CloudWeather::Frame weather
Definition CloudVolume.h:35
Vector Sample(int east, int north) const