载入中...
搜索中...
未找到
VegetationFieldGpu.cpp
浏览该文件的文档.
2
3#include <utility>
4
5#include <algorithm>
6#include <bit>
7#include <cmath>
8#include <limits>
9#include <new>
10#include <vector>
12#include "graphics/PbrSurface.h"
14
15namespace eve::graphics {
16namespace {
17constexpr uint32_t layerCount = 9;
18constexpr uint64_t uploadByteBudget = 256ull * 1024 * 1024;
19
20Diagnostic invalid(std::string message) {
22 "graphics.vegetation.extras-atlas");
23}
24
25uint16_t floatToHalf(float value) {
26 const uint32_t bits = std::bit_cast<uint32_t>(value);
27 const uint32_t sign = (bits >> 16) & 0x8000u;
28 const uint32_t mantissa = bits & 0x7fffffu;
29 const int32_t exponent = int32_t((bits >> 23) & 0xffu) - 127;
30 if (exponent < -24) return uint16_t(sign);
31 if (exponent < -14) {
32 const uint32_t shift = uint32_t(-exponent - 1);
33 uint32_t halfMantissa = (mantissa | 0x800000u) >> shift;
34 const uint32_t remainder = (mantissa | 0x800000u) & ((1u << shift) - 1u);
35 const uint32_t halfway = 1u << (shift - 1u);
36 if (remainder > halfway || (remainder == halfway && (halfMantissa & 1u))) ++halfMantissa;
37 return uint16_t(sign | halfMantissa);
38 }
39 uint32_t halfExponent = uint32_t(exponent + 15);
40 uint32_t halfMantissa = mantissa >> 13;
41 const uint32_t remainder = mantissa & 0x1fffu;
42 if (remainder > 0x1000u || (remainder == 0x1000u && (halfMantissa & 1u))) {
43 if (++halfMantissa == 0x400u) {
44 halfMantissa = 0;
45 ++halfExponent;
46 }
47 }
48 return uint16_t(sign | (halfExponent << 10) | halfMantissa);
49}
50
51bool finite(glm::vec3 value) { return std::isfinite(value.x) && std::isfinite(value.y) && std::isfinite(value.z); }
52} // namespace
53
55 VegetationChannel channel, glm::vec3 center, glm::vec3 extent, uint32_t width,
56 uint32_t height, bool snapToTexel) {
57 const uint64_t texels = uint64_t(width) * height * layerCount;
58 if (!finite(center) || !finite(extent) || extent.x < 1e-4f || extent.y < 1e-4f || extent.z < 1e-4f || !width ||
59 !height || width > 2048 || height > 2048 || texels > uploadByteBudget / (4 * sizeof(uint16_t)))
60 return Result<VegetationGpuAtlas>::failure(invalid("invalid atlas geometry or upload budget exceeded"));
61
62 const double dx = 2.0 * extent.x / width;
63 const double dz = 2.0 * extent.z / height;
64 if (snapToTexel) {
65 center.x = float(std::round(double(center.x) / dx) * dx);
66 center.z = float(std::round(double(center.z) / dz) * dz);
67 }
68 if (!finite(center) || !finite(center + extent) || !finite(center - extent))
69 return Result<VegetationGpuAtlas>::failure(invalid("atlas bounds overflow"));
70
71 const uint64_t sourceRevision = field.revision();
72 try {
73 std::vector<uint16_t> pixels(size_t(texels) * 4);
74 for (uint32_t layer = 0; layer < layerCount; ++layer) {
75 for (uint32_t y = 0; y < height; ++y) {
76 for (uint32_t x = 0; x < width; ++x) {
77 const glm::vec3 position(float(double(center.x) - extent.x + (x + 0.5) * dx), center.y,
78 float(double(center.z) - extent.z + (y + 0.5) * dz));
79 std::array<uint8_t, 4> selected{};
80 selected[size_t(channel)] = uint8_t(layer);
81 auto sample = field.sample(position, selected);
82 if (!sample.ok()) return Result<VegetationGpuAtlas>::failure(sample.status());
83 const auto& sampled = sample.value();
84 const glm::vec4 value = channel == VegetationChannel::Color ? sampled.color
85 : channel == VegetationChannel::Extras ? sampled.extras
86 : channel == VegetationChannel::Motion ? sampled.motion
87 : sampled.vertex;
88 if (std::abs(value.x) > 65504.f || std::abs(value.y) > 65504.f || std::abs(value.z) > 65504.f ||
89 std::abs(value.w) > 65504.f)
91 invalid("vegetation value exceeds finite RGBA16F range"));
92 const size_t offset = ((size_t(layer) * height + y) * width + x) * 4;
93 pixels[offset + 0] = floatToHalf(value.x);
94 pixels[offset + 1] = floatToHalf(value.y);
95 pixels[offset + 2] = floatToHalf(value.z);
96 pixels[offset + 3] = floatToHalf(value.w);
97 }
98 }
99 }
100 if (field.revision() != sourceRevision)
101 return Result<VegetationGpuAtlas>::failure(invalid("field changed while baking vegetation atlas"));
102 auto uploaded = factory.newTextureArrayRgba16f(width, height, layerCount, pixels);
103 if (!uploaded.ok()) return Result<VegetationGpuAtlas>::failure(uploaded.status());
105 {uploaded.value(), sourceRevision, width, height, layerCount, center, extent});
106 } catch (const std::bad_alloc&) {
108 DiagnosticCode::Failed, "vegetation atlas allocation failed", {}, {}, "graphics.vegetation.atlas"));
109 }
110}
111
113 glm::vec3 center, glm::vec3 extent, uint32_t width,
114 uint32_t height, bool snapToTexel) {
115 return uploadAtlas(factory, field, VegetationChannel::Extras, center, extent, width, height, snapToTexel);
116}
117
119 glm::vec3 center, glm::vec3 extent, uint32_t width,
120 uint32_t height, bool snapToTexel) {
121 return uploadAtlas(factory, field, VegetationChannel::Color, center, extent, width, height, snapToTexel);
122}
123
125 glm::vec3 center, glm::vec3 extent, uint32_t width,
126 uint32_t height, bool snapToTexel) {
127 return uploadAtlas(factory, field, VegetationChannel::Motion, center, extent, width, height, snapToTexel);
128}
129
131 glm::vec3 center, glm::vec3 extent, uint32_t width,
132 uint32_t height, bool snapToTexel) {
133 return uploadAtlas(factory, field, VegetationChannel::Vertex, center, extent, width, height, snapToTexel);
134}
135
137 bool failed = false;
138 for (auto* atlas : {&set.extras, &set.colors, &set.motion, &set.vertex}) {
139 if (!atlas->texture) continue;
140 if (factory.releaseTexture(atlas->texture))
141 atlas->texture = nullptr;
142 else
143 failed = true;
144 }
145 if (failed)
147 "vegetation GPU field texture release failed", {}, {},
148 "graphics.vegetation.atlas"));
149 return Result<void>::success();
150}
151
153 glm::vec3 center, glm::vec3 extent, uint32_t width,
154 uint32_t height, bool snapToTexel) {
155 VegetationGpuFieldSet candidate;
156 auto fail = [&](const Status& status) {
157 auto released = releaseVegetationGpuFieldSet(factory, candidate);
158 if (!released)
160 Diagnostic::error(DiagnosticCode::Failed, "vegetation GPU field upload rollback failed", {}, {},
161 "graphics.vegetation.atlas"));
163 };
164 auto extras = uploadVegetationExtrasAtlas(factory, field, center, extent, width, height, snapToTexel);
165 if (!extras) return Result<VegetationGpuFieldSet>::failure(extras.status());
166 candidate.extras = std::move(extras).takeValue();
167 auto colors = uploadVegetationColorsAtlas(factory, field, candidate.extras.center, extent, width, height, false);
168 if (!colors) return fail(colors.status());
169 candidate.colors = std::move(colors).takeValue();
170 auto motion = uploadVegetationMotionAtlas(factory, field, candidate.extras.center, extent, width, height, false);
171 if (!motion) return fail(motion.status());
172 candidate.motion = std::move(motion).takeValue();
173 auto vertex = uploadVegetationVertexAtlas(factory, field, candidate.extras.center, extent, width, height, false);
174 if (!vertex) return fail(vertex.status());
175 candidate.vertex = std::move(vertex).takeValue();
176 if (candidate.extras.fieldRevision != field.revision()) {
177 auto released = releaseVegetationGpuFieldSet(factory, candidate);
178 if (!released)
180 Diagnostic::error(DiagnosticCode::Failed, "vegetation GPU field upload rollback failed", {}, {},
181 "graphics.vegetation.atlas"));
182 return Result<VegetationGpuFieldSet>::failure(invalid("field changed during set upload"));
183 }
184 return Result<VegetationGpuFieldSet>::success(std::move(candidate));
185}
186
187namespace {
188Result<VegetationGpuAtlas> uploadBakedChannel(IResourceFactory& factory,
189 std::span<const VegetationChannelAtlas, layerCount> layers,
190 std::uint64_t sourceRevision) {
191 const auto& geometry = layers.front();
192 const std::uint64_t texels = std::uint64_t(geometry.width) * geometry.height * layerCount;
193 try {
194 std::vector<std::uint16_t> pixels(std::size_t(texels) * 4);
195 for (std::size_t layer = 0; layer < layerCount; ++layer) {
196 const auto& values = layers[layer].pixels;
197 for (std::size_t index = 0; index < values.size(); ++index) {
198 const auto value = values[index];
199 if (!std::isfinite(value.x) || !std::isfinite(value.y) || !std::isfinite(value.z) ||
200 !std::isfinite(value.w) || std::abs(value.x) > 65504.f || std::abs(value.y) > 65504.f ||
201 std::abs(value.z) > 65504.f || std::abs(value.w) > 65504.f)
202 return Result<VegetationGpuAtlas>::failure(invalid("pre-baked vegetation value exceeds RGBA16F range"));
203 const std::size_t offset = (layer * values.size() + index) * 4;
204 pixels[offset] = floatToHalf(value.x);
205 pixels[offset + 1] = floatToHalf(value.y);
206 pixels[offset + 2] = floatToHalf(value.z);
207 pixels[offset + 3] = floatToHalf(value.w);
208 }
209 }
210 auto uploaded = factory.newTextureArrayRgba16f(geometry.width, geometry.height, layerCount, pixels);
211 if (!uploaded) return Result<VegetationGpuAtlas>::failure(uploaded.status());
212 return Result<VegetationGpuAtlas>::success({uploaded.value(), sourceRevision, geometry.width, geometry.height,
213 layerCount, geometry.center, geometry.extent});
214 } catch (const std::bad_alloc&) {
216 Diagnostic::error(DiagnosticCode::Failed, "pre-baked vegetation atlas allocation failed", {}, {},
217 "graphics.vegetation.atlas"));
218 }
219}
220
221Result<void> validateBakedChannel(std::span<const VegetationChannelAtlas, layerCount> layers) {
222 const auto& first = layers.front();
223 const std::uint64_t pixels = std::uint64_t(first.width) * first.height;
224 if (first.width == 0 || first.height == 0 || first.width > 2048 || first.height > 2048 ||
225 !finite(first.center) || !finite(first.extent) || first.extent.x < 1e-4f || first.extent.y < 1e-4f ||
226 first.extent.z < 1e-4f)
227 return Result<void>::failure(invalid("pre-baked vegetation channel geometry is invalid"));
228 for (const auto& layer : layers) {
229 if (layer.width != first.width || layer.height != first.height || layer.center != first.center ||
230 layer.extent != first.extent || layer.pixels.size() != pixels)
231 return Result<void>::failure(invalid("pre-baked vegetation channel layers are incoherent"));
232 }
233 return Result<void>::success();
234}
235} // namespace
236
238 IResourceFactory& factory, std::span<const VegetationAtlas, 9> layers, std::uint64_t sourceRevision) {
239 const auto& first = layers.front();
240 const std::uint64_t pixels = std::uint64_t(first.width) * first.height;
241 if (sourceRevision == 0 || first.width == 0 || first.height == 0 || first.width > 2048 || first.height > 2048 ||
242 !finite(first.center) || !finite(first.extent) || first.extent.x < 1e-4f || first.extent.y < 1e-4f ||
243 first.extent.z < 1e-4f || pixels * layerCount > uploadByteBudget / (4 * sizeof(std::uint16_t)))
244 return Result<VegetationGpuFieldSet>::failure(invalid("pre-baked vegetation atlas geometry is invalid"));
245 for (const auto& layer : layers) {
246 if (layer.width != first.width || layer.height != first.height || layer.center != first.center ||
247 layer.extent != first.extent || std::any_of(layer.channels.begin(), layer.channels.end(),
248 [&](const auto& values) { return values.size() != pixels; }))
249 return Result<VegetationGpuFieldSet>::failure(invalid("pre-baked vegetation atlas layers are incoherent"));
250 }
251 try {
252 std::array<VegetationChannelAtlas, layerCount> colors, extras, motion, vertex;
253 for (std::size_t layer = 0; layer < layerCount; ++layer) {
254 auto copy = [&](VegetationChannelAtlas& destination, std::size_t channel) {
255 destination.width = layers[layer].width;
256 destination.height = layers[layer].height;
257 destination.center = layers[layer].center;
258 destination.extent = layers[layer].extent;
259 destination.pixels = layers[layer].channels[channel];
260 };
261 copy(colors[layer], 0);
262 copy(extras[layer], 1);
263 copy(motion[layer], 2);
264 copy(vertex[layer], 3);
265 }
266 return uploadVegetationGpuFieldSet(factory, colors, extras, motion, vertex, sourceRevision);
267 } catch (const std::bad_alloc&) {
269 Diagnostic::error(DiagnosticCode::Failed, "pre-baked vegetation channel projection allocation failed",
270 {}, {}, "graphics.vegetation.atlas"));
271 }
272}
273
275 IResourceFactory& factory, std::span<const VegetationChannelAtlas, 9> colors,
276 std::span<const VegetationChannelAtlas, 9> extras, std::span<const VegetationChannelAtlas, 9> motion,
277 std::span<const VegetationChannelAtlas, 9> vertex, std::uint64_t sourceRevision) {
278 if (sourceRevision == 0)
279 return Result<VegetationGpuFieldSet>::failure(invalid("pre-baked vegetation revision must be nonzero"));
280 for (const auto channel : {colors, extras, motion, vertex}) {
281 auto valid = validateBakedChannel(channel);
283 }
284 std::uint64_t combinedTexels = 0;
285 for (const auto channel : {colors, extras, motion, vertex}) {
286 const auto& first = channel.front();
287 const std::uint64_t channelTexels = std::uint64_t(first.width) * first.height * layerCount;
288 if (channelTexels > std::numeric_limits<std::uint64_t>::max() - combinedTexels)
289 return Result<VegetationGpuFieldSet>::failure(invalid("pre-baked vegetation upload size overflow"));
290 combinedTexels += channelTexels;
291 }
292 if (combinedTexels > uploadByteBudget / (4 * sizeof(std::uint16_t)))
293 return Result<VegetationGpuFieldSet>::failure(invalid("pre-baked vegetation upload budget exceeded"));
294
295 VegetationGpuFieldSet candidate;
296 auto rollback = [&](const Status& status) {
297 auto released = releaseVegetationGpuFieldSet(factory, candidate);
298 if (!released)
300 Diagnostic::error(DiagnosticCode::Failed, "pre-baked vegetation GPU upload rollback failed", {}, {},
301 "graphics.vegetation.atlas"));
303 };
304 auto extrasUpload = uploadBakedChannel(factory, extras, sourceRevision);
305 if (!extrasUpload) return Result<VegetationGpuFieldSet>::failure(extrasUpload.status());
306 candidate.extras = std::move(extrasUpload).takeValue();
307 auto colorsUpload = uploadBakedChannel(factory, colors, sourceRevision);
308 if (!colorsUpload) return rollback(colorsUpload.status());
309 candidate.colors = std::move(colorsUpload).takeValue();
310 auto motionUpload = uploadBakedChannel(factory, motion, sourceRevision);
311 if (!motionUpload) return rollback(motionUpload.status());
312 candidate.motion = std::move(motionUpload).takeValue();
313 auto vertexUpload = uploadBakedChannel(factory, vertex, sourceRevision);
314 if (!vertexUpload) return rollback(vertexUpload.status());
315 candidate.vertex = std::move(vertexUpload).takeValue();
316 return Result<VegetationGpuFieldSet>::success(std::move(candidate));
317}
318
319namespace {
320Result<void> bindVegetationGpuFieldsAtRevision(PbrSurface& surface, std::uint64_t expectedRevision,
322 const VegetationMotionGpuAtlas& motion, const VegetationVertexGpuAtlas& vertex,
323 const VegetationGpuRuntime& runtime) {
324 const auto validAtlas = [&](const VegetationGpuAtlas& atlas) {
325 return atlas.texture && atlas.fieldRevision == extras.fieldRevision && atlas.width && atlas.height &&
326 atlas.width <= 2048 && atlas.height <= 2048 && atlas.layers == layerCount && finite(atlas.center) &&
327 finite(atlas.extent) && atlas.extent.x >= 1e-4f && atlas.extent.y >= 1e-4f && atlas.extent.z >= 1e-4f;
328 };
329 if (!validAtlas(extras) || !validAtlas(colors) || !validAtlas(motion) || !validAtlas(vertex) ||
330 extras.fieldRevision != expectedRevision || extras.layers != layerCount ||
331 (runtime.enableMotion && !runtime.motionNoise) ||
332 !finite(glm::vec3(runtime.motionDirection[0], 0, runtime.motionDirection[1])) ||
333 !finite(glm::vec3(runtime.worldOrigin[0], runtime.worldOrigin[1], runtime.worldOrigin[2])) ||
334 !std::isfinite(runtime.time) || std::abs(runtime.time) > 1e12 || !std::isfinite(runtime.globalBending) ||
335 !std::isfinite(runtime.globalBranch) || !std::isfinite(runtime.globalFlutter) ||
336 !std::isfinite(runtime.noiseTiling) || !std::isfinite(runtime.motionFadeDistance) ||
337 !std::isfinite(runtime.cameraFadeMin) || !std::isfinite(runtime.cameraFadeMax) ||
338 !std::isfinite(runtime.fadeNoiseTiling) || runtime.globalBending < 0 || runtime.globalBending > 1000000 ||
339 runtime.globalBranch < 0 || runtime.globalBranch > 1000000 || runtime.globalFlutter < 0 ||
340 runtime.globalFlutter > 1000000 || runtime.noiseTiling < 0 || runtime.noiseTiling > 1000000 ||
341 runtime.motionFadeDistance < 0 || runtime.motionFadeDistance > 1000000 || runtime.cameraFadeMin < 0 ||
342 runtime.cameraFadeMin > 1000000 || runtime.cameraFadeMax < 0 || runtime.cameraFadeMax > 1000000 ||
343 runtime.fadeNoiseTiling < 0 || runtime.fadeNoiseTiling > 1000000)
344 return Result<void>::failure(invalid("incoherent, stale or invalid vegetation GPU field binding"));
345
346 const auto coords = [](const VegetationGpuAtlas& atlas) {
347 return std::array<float, 4>{1.f / (2.f * atlas.extent.x), 1.f / (2.f * atlas.extent.z),
348 .5f - atlas.center.x / (2.f * atlas.extent.x),
349 .5f - atlas.center.z / (2.f * atlas.extent.z)};
350 };
351 PbrSurface candidate = surface;
352 candidate.vegetationExtras.texture = extras.texture;
353 candidate.vegetationExtras.coords = coords(extras);
354 candidate.vegetationExtras.usage.fill(1);
355 candidate.vegetationColors.texture = colors.texture;
356 candidate.vegetationColors.coords = coords(colors);
357 candidate.vegetationColors.usage.fill(1);
358 candidate.vegetationMotion.texture = motion.texture;
359 candidate.vegetationMotion.noise = runtime.motionNoise;
360 candidate.vegetationMotion.coords = coords(motion);
361 candidate.vegetationMotion.globalDirection = runtime.motionDirection;
362 candidate.vegetationMotion.worldOrigin = runtime.worldOrigin;
363 candidate.vegetationMotion.time = runtime.time;
364 candidate.vegetationMotion.globalBending = runtime.globalBending;
365 candidate.vegetationMotion.globalBranch = runtime.globalBranch;
366 candidate.vegetationMotion.globalFlutter = runtime.globalFlutter;
367 candidate.vegetationMotion.noiseTiling = runtime.noiseTiling;
368 candidate.vegetationMotion.fadeDistance = runtime.motionFadeDistance;
369 candidate.vegetationMotion.mode =
371 candidate.vegetationMotion.usage.fill(1);
372 candidate.vegetationAlpha.noise = runtime.fadeNoise;
373 candidate.vegetationAlpha.cameraFadeMin = runtime.cameraFadeMin;
374 candidate.vegetationAlpha.cameraFadeMax = runtime.cameraFadeMax;
375 candidate.vegetationAlpha.noiseTiling = runtime.fadeNoiseTiling;
376 candidate.vegetationVertex.texture = vertex.texture;
377 candidate.vegetationVertex.coords = coords(vertex);
378 candidate.vegetationVertex.source = PbrVegetationDeformationSource::GpuFields;
379 candidate.vegetationVertex.usage.fill(1);
380 auto valid = validatePbrSurface(candidate);
381 if (!valid) return valid;
382 surface = std::move(candidate);
383 return Result<void>::success();
384}
385} // namespace
386
389 const VegetationMotionGpuAtlas& motion, const VegetationVertexGpuAtlas& vertex,
390 const VegetationGpuRuntime& runtime) {
391 return bindVegetationGpuFieldsAtRevision(surface, field.revision(), extras, colors, motion, vertex, runtime);
392}
393
395 const VegetationGpuFieldSet& set, const VegetationGpuRuntime& runtime) {
396 return bindVegetationGpuFields(surface, field, set.extras, set.colors, set.motion, set.vertex, runtime);
397}
398
400 std::uint64_t expectedRevision, const VegetationGpuRuntime& runtime) {
401 return bindVegetationGpuFieldsAtRevision(surface, expectedRevision, set.extras, set.colors, set.motion, set.vertex,
402 runtime);
403}
404
405} // namespace eve::graphics
double y
double x
std::string selected
std::string message
wgpu::PopErrorScopeStatus status
std::int32_t first
std::uint32_t height
std::uint32_t width
size_t offset
std::array< float, 3 > position
bool valid
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
glm::dvec2 center
glm::dvec3 dx
glm::dvec3 dz
bool finite
TileLayer * layer
std::set< std::string > values
Object::Ptr value
uint8_t * pixels
std::string geometry
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Structured status and zero or more diagnostics for an operation.
Definition Status.h:70
Texture / mesh / shader / canvas creation and release.
virtual Result< Texture * > newTextureArrayRgba16f(uint32_t width, uint32_t height, uint32_t layers, std::span< const uint16_t > rgbaHalf)
Upload a sampled 2D array of tightly packed linear RGBA16F texels.
virtual bool releaseTexture(Texture *texture)=0
Release texture.
Backend-independent, owning vegetation influence field. Single writer; concurrent const evaluation is...
eve::Diagnostic Diagnostic
Status invalid(const char *message)
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
VegetationGpuAtlas VegetationColorsGpuAtlas
Result< void > releaseVegetationGpuFieldSet(IResourceFactory &factory, VegetationGpuFieldSet &set)
Release every texture still present in a detached field set. Successful entries are nulled....
VegetationGpuAtlas VegetationVertexGpuAtlas
VegetationGpuAtlas VegetationMotionGpuAtlas
VegetationChannel
Independent vegetation field channels; values use linear color and world units.
Result< VegetationGpuFieldSet > uploadVegetationGpuFieldSet(IResourceFactory &factory, const VegetationField &field, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Bake and upload all four nine-layer projections as one publication. Earlier uploads are released if a...
Result< VegetationGpuAtlas > uploadAtlas(IResourceFactory &factory, const VegetationField &field, VegetationChannel channel, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Result< void > validatePbrSurface(const PbrSurface &s)
Validate finite material factors and sampler enums without changing the input.
Result< void > bindVegetationGpuFields(PbrSurface &surface, const VegetationField &field, const VegetationExtrasGpuAtlas &extras, const VegetationColorsGpuAtlas &colors, const VegetationMotionGpuAtlas &motion, const VegetationVertexGpuAtlas &vertex, const VegetationGpuRuntime &runtime)
Atomically bind four coherent GPU projections to an owning PBR parameter snapshot.
Result< VegetationExtrasGpuAtlas > uploadVegetationExtrasAtlas(IResourceFactory &factory, const VegetationField &field, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Bake and atomically upload all nine Extras layers as a linear RGBA16F 2D array.
Result< VegetationVertexGpuAtlas > uploadVegetationVertexAtlas(IResourceFactory &factory, const VegetationField &field, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Bake and atomically upload all nine Vertex layers as a linear RGBA16F 2D array.
VegetationGpuAtlas VegetationExtrasGpuAtlas
Result< VegetationMotionGpuAtlas > uploadVegetationMotionAtlas(IResourceFactory &factory, const VegetationField &field, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Bake and atomically upload all nine Motion layers as a linear RGBA16F 2D array.
Result< VegetationColorsGpuAtlas > uploadVegetationColorsAtlas(IResourceFactory &factory, const VegetationField &field, glm::vec3 center, glm::vec3 extent, uint32_t width, uint32_t height, bool snapToTexel)
Bake and atomically upload all nine Colors layers as a linear RGBA16F 2D array. Ownership,...
Owning material parameter snapshot; texture pointers remain borrowed. Base color/metallic/roughness c...
Definition PbrSurface.h:240
One owning vegetation channel in row-major X/Z order at texel centers. Channel atlases may use indepe...
Immutable GPU projection of nine layers from one vegetation field channel. The source field remains a...
Coherent detached projections for all four vegetation channels. Textures are factory-owned....
Runtime-owned global inputs shared by one coherent vegetation field binding. Time is explicit for det...