Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
ProbeStore.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
24#pragma once
25
26#include "../../core/Half.hpp"
28#include "../../core/Types.hpp"
29#include "../../core/Hash.hpp"
31#include "./ProbeConstants.hpp"
32
33#include <algorithm>
34#include <cmath>
35#include <glm/glm.hpp>
36#include <vector>
37
38namespace esengine {
39
42public:
44 struct Volume {
45 glm::vec3 min{0.0f};
46 glm::vec3 max{0.0f};
47 const ProbeVolume* grid = nullptr;
49 glm::ivec3 indirection{-1};
50 };
51
57 static constexpr i32 kAtlasPages = 10;
58
60 static glm::ivec3 bricksFor(const glm::ivec3& resolution) {
61 glm::ivec3 n{1};
62 for (int a = 0; a < 3; ++a) n[a] = std::max(1, (resolution[a] - 1 + kBrickCells - 1) / kBrickCells);
63 return n;
64 }
65
66 void clear() {
67 volumes_.clear();
68 per_pixel_draws_ = 0;
69 per_object_draws_ = 0;
70 }
71
73 void noteDraw(bool perPixel) const { ++(perPixel ? per_pixel_draws_ : per_object_draws_); }
74 u32 perPixelDraws() const { return per_pixel_draws_; }
75 u32 perObjectDraws() const { return per_object_draws_; }
76
78 static constexpr u32 kReadsPerLookup = 1 + 9;
79
82 void forgetAtlas() {
83 atlas_key_.clear();
84 placed_.clear();
85 shape_ = Shape{};
86 atlas_width_ = atlas_height_ = atlas_depth_ = 0;
87 atlas_texture_ = 0;
88 for (Volume& v : volumes_) v.indirection = glm::ivec3(-1);
89 }
90
93 void add(const glm::vec3& min, const glm::vec3& max, const ProbeVolume* grid) {
94 if (!grid || !grid->isValid()) return;
95 if (max.x <= min.x || max.y <= min.y || max.z <= min.z) return;
96 volumes_.push_back({min, max, grid});
97 }
98
99 bool empty() const { return volumes_.empty(); }
100 u32 count() const { return static_cast<u32>(volumes_.size()); }
101
106 u64 revision() const {
108 const auto mix = [&h](const void* data, usize bytes) { h = hash::fnv1aBytes(h, data, bytes); };
109 for (const Volume& v : volumes_) {
110 mix(&v.min, sizeof(v.min));
111 mix(&v.max, sizeof(v.max));
112 mix(&v.grid, sizeof(v.grid));
113 mix(&v.grid->revision, sizeof(v.grid->revision));
114 }
115 if (revision_ == 0 || h != revision_hash_) {
116 revision_hash_ = h;
117 revision_ = nextRevision();
118 }
119 return revision_;
120 }
121
122
130 bool sample(const glm::vec3& p, ProbeConstants& out, bool perPixel = false) const {
131 const Volume* best = nullptr;
132 f32 bestSize = 0.0f;
133 for (const Volume& v : volumes_) {
134 if (p.x < v.min.x || p.x > v.max.x || p.y < v.min.y || p.y > v.max.y
135 || p.z < v.min.z || p.z > v.max.z) continue;
136 const glm::vec3 e = v.max - v.min;
137 const f32 size = e.x * e.y * e.z;
138 if (!best || size < bestSize) { best = &v; bestSize = size; }
139 }
140 if (!best) return false;
141
142 const ProbeVolume& g = *best->grid;
143 if (perPixel && best->indirection.x >= 0 && atlas_texture_ != 0) {
144 writeGridRun(*best, out);
145 return true;
146 }
147 if (g.sparse()) {
148 sampleBricks(*best, p, out);
149 return true;
150 }
151 i32 low[3] = {0, 0, 0};
152 i32 high[3] = {0, 0, 0};
153 f32 frac[3] = {0.0f, 0.0f, 0.0f};
154 for (u32 a = 0; a < 3; ++a) {
155 const i32 n = g.resolution[static_cast<int>(a)];
156 if (n <= 1) continue;
157 const f32 span = best->max[static_cast<int>(a)] - best->min[static_cast<int>(a)];
158 f32 u = (p[static_cast<int>(a)] - best->min[static_cast<int>(a)]) / span
159 * static_cast<f32>(n - 1);
160 u = std::fmin(std::fmax(u, 0.0f), static_cast<f32>(n - 1));
161 i32 i0 = static_cast<i32>(std::floor(u));
162 if (i0 > n - 2) i0 = n - 2;
163 low[a] = i0;
164 high[a] = i0 + 1;
165 frac[a] = u - static_cast<f32>(i0);
166 }
167
168 const i32 strideY = g.resolution.x;
169 const i32 strideZ = g.resolution.x * g.resolution.y;
170 const bool sky = g.hasSkyVisibility();
171 out = ProbeConstants{};
172 for (u32 corner = 0; corner < 8; ++corner) {
173 const f32 w = ((corner & 1u) ? frac[0] : 1.0f - frac[0])
174 * ((corner & 2u) ? frac[1] : 1.0f - frac[1])
175 * ((corner & 4u) ? frac[2] : 1.0f - frac[2]);
176 if (w <= 0.0f) continue;
177 const i32 x = (corner & 1u) ? high[0] : low[0];
178 const i32 y = (corner & 2u) ? high[1] : low[1];
179 const i32 z = (corner & 4u) ? high[2] : low[2];
180 const usize base = static_cast<usize>(x + y * strideY + z * strideZ) * 9;
181 for (u32 c = 0; c < 9; ++c) {
182 const glm::vec3& sh = g.irradiance[base + c];
183 out.irradiance[c].x += sh.x * w;
184 out.irradiance[c].y += sh.y * w;
185 out.irradiance[c].z += sh.z * w;
186 }
187 // The sky's visibility rides the spare channels: [1..8].w and reflection.y for the first.
188 if (sky) {
189 out.reflection.y += g.skyVisibility[base] * w;
190 for (u32 c = 1; c < 9; ++c) out.irradiance[c].w += g.skyVisibility[base + c] * w;
191 }
192 }
193 out.irradiance[0].w = 1.0f;
194 if (sky) out.reflection.z = 1.0f;
195 return true;
196 }
197
205 bool sampleBox(const glm::vec3& centre, const glm::vec3& half, ProbeConstants& out, bool perPixel = false) const {
206 if (sample(centre, out, perPixel)) return true;
207 const Volume* best = nullptr;
208 f32 bestSize = 0.0f;
209 for (const Volume& v : volumes_) {
210 const glm::vec3 vc = (v.min + v.max) * 0.5f;
211 const glm::vec3 vh = (v.max - v.min) * 0.5f;
212 const glm::vec3 gap = glm::abs(centre - vc) - (half + vh);
213 if (gap.x > 0.0f || gap.y > 0.0f || gap.z > 0.0f) continue;
214 const f32 size = vh.x * vh.y * vh.z;
215 if (!best || size < bestSize) { best = &v; bestSize = size; }
216 }
217 if (!best) return false;
218 return sample(glm::clamp(centre, best->min, best->max), out, perPixel);
219 }
220
230 bool layoutAtlas(u32 maxSide) {
231 const i32 side = static_cast<i32>(maxSide);
232 const i32 maxSlotsX = side / (kAtlasPages * kBrickTexels);
233 const i32 maxSlotsYZ = side / kBrickTexels;
234 std::vector<u64> key;
235 key.reserve(volumes_.size() * 2);
236 placed_.clear();
237 i32 bricks = 0;
238 glm::ivec3 extent{0};
239 for (usize i = 0; i < volumes_.size(); ++i) {
240 Volume& v = volumes_[i];
241 v.indirection = glm::ivec3(-1);
242 bool shared = false;
243 for (usize j = 0; j < i; ++j) {
244 if (volumes_[j].grid == v.grid) { shared = true; break; }
245 }
246 if (shared) continue;
247 const glm::ivec3 n = bricksFor(v.grid->resolution);
248 // A sparse grid brings its own bricks; a dense one is every cell a brick.
249 const i32 count = v.grid->sparse() ? static_cast<i32>(v.grid->bricks.size()) : n.x * n.y * n.z;
250 const glm::ivec3 grown{std::max(extent.x, n.x), std::max(extent.y, n.y), extent.z + n.z};
251 const Shape shape = shapeFor(bricks + count, maxSlotsX, maxSlotsYZ, grown);
252 if (shape.slots.x == 0 || shape.pageWidth * kAtlasPages > side || shape.height > side || shape.depth > side) {
253 continue;
254 }
255 placed_.push_back({v.grid, bricks, n, glm::ivec3(0, 0, extent.z), count});
256 bricks += count;
257 extent = grown;
258 key.push_back(v.grid->revision);
259 key.push_back(static_cast<u64>(extent.z));
260 }
261 shape_ = placed_.empty() ? Shape{} : shapeFor(bricks, maxSlotsX, maxSlotsYZ, extent);
262 // Every indirection block sits in the last page, so its x starts at that page's first texel.
263 for (Placed& p : placed_) p.indirection.x = (kAtlasPages - 1) * shape_.pageWidth;
264 for (Volume& v : volumes_) {
265 for (const Placed& p : placed_) {
266 if (p.grid == v.grid) { v.indirection = p.indirection; break; }
267 }
268 }
269 const u32 width = placed_.empty() ? 0u : static_cast<u32>(shape_.pageWidth * kAtlasPages);
270 const u32 height = placed_.empty() ? 0u : static_cast<u32>(shape_.height);
271 const u32 depth = placed_.empty() ? 0u : static_cast<u32>(shape_.depth);
272 const bool changed = key != atlas_key_ || width != atlas_width_ || height != atlas_height_ || depth != atlas_depth_;
273 atlas_key_ = std::move(key);
274 atlas_width_ = width;
275 atlas_height_ = height;
276 atlas_depth_ = depth;
277 return changed;
278 }
279
280 u32 atlasWidth() const { return atlas_width_; }
281 u32 atlasHeight() const { return atlas_height_; }
282 u32 atlasDepth() const { return atlas_depth_; }
284 u64 atlasBytes() const {
285 return static_cast<u64>(atlas_width_) * atlas_height_ * atlas_depth_ * 4u * sizeof(u16);
286 }
287
288 u32 pageWidth() const { return static_cast<u32>(shape_.pageWidth); }
290 u32 brickCount() const {
291 u32 n = 0;
292 for (const Placed& p : placed_) n += static_cast<u32>(p.count);
293 return n;
294 }
295
297 glm::ivec3 slotOrigin(i32 index) const {
298 const i32 sx = shape_.slots.x;
299 const i32 sy = shape_.slots.y;
300 return glm::ivec3(index % sx, (index / sx) % sy, index / (sx * sy)) * kBrickTexels;
301 }
302
309 void fillAtlas(std::vector<u16>& out) const {
310 const usize w = atlas_width_;
311 const usize h = atlas_height_;
312 out.assign(w * h * atlas_depth_ * 4, 0);
313 const auto texel = [&](i32 x, i32 y, i32 z) -> u16* {
314 return &out[((static_cast<usize>(z) * h + static_cast<usize>(y)) * w + static_cast<usize>(x)) * 4];
315 };
316 const i32 page = shape_.pageWidth;
317 for (const Placed& p : placed_) {
318 const ProbeVolume& g = *p.grid;
319 const glm::ivec3 r = g.resolution;
320 const bool sky = g.hasSkyVisibility();
321 if (g.sparse()) {
322 const auto put = [&](u16* t, usize probe) {
323 const glm::vec3& sh = g.irradiance[probe];
324 t[0] = packHalf(sh.x);
325 t[1] = packHalf(sh.y);
326 t[2] = packHalf(sh.z);
327 t[3] = packHalf(sky ? g.skyVisibility[probe] : 0.0f);
328 };
329 for (usize b = 0; b < g.bricks.size(); ++b) {
330 const glm::ivec4 k = g.bricks[b];
331 const glm::ivec3 o = slotOrigin(p.firstBrick + static_cast<i32>(b));
332 for (i32 t = 0; t < ProbeVolume::kBrickProbes; ++t) {
333 const i32 tx = t % kBrickTexels, ty = (t / kBrickTexels) % kBrickTexels, tz = t / (kBrickTexels * kBrickTexels);
334 const usize probe = (b * static_cast<usize>(ProbeVolume::kBrickProbes) + static_cast<usize>(t)) * 9;
335 for (i32 c = 0; c < 9; ++c) put(texel(c * page + o.x + tx, o.y + ty, o.z + tz), probe + static_cast<usize>(c));
336 }
337 // Every finest-brick cell the brick covers names it, with its span.
338 for (i32 z = k.z; z < std::min(k.z + k.w, p.bricks.z); ++z) {
339 for (i32 y = k.y; y < std::min(k.y + k.w, p.bricks.y); ++y) {
340 for (i32 x = k.x; x < std::min(k.x + k.w, p.bricks.x); ++x) {
341 u16* ind = texel(p.indirection.x + x, p.indirection.y + y, p.indirection.z + z);
342 ind[0] = packHalf(static_cast<f32>(o.x));
343 ind[1] = packHalf(static_cast<f32>(o.y));
344 ind[2] = packHalf(static_cast<f32>(o.z));
345 ind[3] = packHalf(static_cast<f32>(k.w));
346 }
347 }
348 }
349 }
350 continue;
351 }
352 for (i32 bz = 0; bz < p.bricks.z; ++bz) {
353 for (i32 by = 0; by < p.bricks.y; ++by) {
354 for (i32 bx = 0; bx < p.bricks.x; ++bx) {
355 const i32 index = p.firstBrick + bx + p.bricks.x * (by + p.bricks.y * bz);
356 const glm::ivec3 o = slotOrigin(index);
357 u16* ind = texel(p.indirection.x + bx, p.indirection.y + by, p.indirection.z + bz);
358 ind[0] = packHalf(static_cast<f32>(o.x));
359 ind[1] = packHalf(static_cast<f32>(o.y));
360 ind[2] = packHalf(static_cast<f32>(o.z));
361 ind[3] = packHalf(1.0f);
362 for (i32 tz = 0; tz < kBrickTexels; ++tz) {
363 const i32 pz = std::min(bz * kBrickCells + tz, r.z - 1);
364 for (i32 ty = 0; ty < kBrickTexels; ++ty) {
365 const i32 py = std::min(by * kBrickCells + ty, r.y - 1);
366 for (i32 tx = 0; tx < kBrickTexels; ++tx) {
367 const i32 px = std::min(bx * kBrickCells + tx, r.x - 1);
368 const usize probe = static_cast<usize>(px + r.x * (py + r.y * pz)) * 9;
369 for (i32 c = 0; c < 9; ++c) {
370 u16* t = texel(c * page + o.x + tx, o.y + ty, o.z + tz);
371 const glm::vec3& sh = g.irradiance[probe + static_cast<usize>(c)];
372 t[0] = packHalf(sh.x);
373 t[1] = packHalf(sh.y);
374 t[2] = packHalf(sh.z);
375 t[3] = packHalf(sky ? g.skyVisibility[probe + static_cast<usize>(c)] : 0.0f);
376 }
377 }
378 }
379 }
380 }
381 }
382 }
383 }
384 }
385
387 void setAtlasTexture(u32 id) { atlas_texture_ = id; }
388 u32 atlasTexture() const { return atlas_texture_; }
389
390private:
398 void writeGridRun(const Volume& v, ProbeConstants& out) const {
399 const ProbeVolume& g = *v.grid;
400 const glm::vec3 e = v.max - v.min;
401 const glm::vec3 r = glm::vec3(g.resolution);
402 out = ProbeConstants{};
403 out.irradiance[0].w = 2.0f;
404 out.irradiance[1] = glm::vec4(v.min, r.x - 1.0f);
405 out.irradiance[2] = glm::vec4(r.x > 1.0f ? (r.x - 1.0f) / e.x : 0.0f,
406 r.y > 1.0f ? (r.y - 1.0f) / e.y : 0.0f,
407 r.z > 1.0f ? (r.z - 1.0f) / e.z : 0.0f, r.y - 1.0f);
408 out.irradiance[3] = glm::vec4(glm::vec3(v.indirection), r.z - 1.0f);
409 out.irradiance[4] = glm::vec4(1.0f / static_cast<f32>(atlas_width_), 1.0f / static_cast<f32>(atlas_height_),
410 1.0f / static_cast<f32>(atlas_depth_), static_cast<f32>(shape_.pageWidth));
411 if (g.hasSkyVisibility()) out.reflection.z = 1.0f;
412 }
413
415 struct Shape {
416 glm::ivec3 slots{0};
417 i32 pageWidth = 0;
418 i32 height = 0;
419 i32 depth = 0;
420 };
423 struct Placed {
424 const ProbeVolume* grid = nullptr;
425 i32 firstBrick = 0;
426 glm::ivec3 bricks{1};
427 glm::ivec3 indirection{0};
428 i32 count = 0;
429 };
430
435 void sampleBricks(const Volume& v, const glm::vec3& p, ProbeConstants& out) const {
436 const ProbeVolume& g = *v.grid;
437 const glm::ivec3 cells = g.cells();
438 glm::vec3 grid{0.0f};
439 for (int a = 0; a < 3; ++a) {
440 const i32 n = g.resolution[a];
441 if (n <= 1) continue;
442 const f32 u = (p[a] - v.min[a]) / (v.max[a] - v.min[a]) * static_cast<f32>(n - 1);
443 grid[a] = std::fmin(std::fmax(u, 0.0f), static_cast<f32>(n - 1));
444 }
445 glm::ivec3 cell;
446 for (int a = 0; a < 3; ++a) cell[a] = std::min(static_cast<i32>(std::floor(grid[a] / kBrickCells)), cells[a] - 1);
447 const i32 b = g.cellBrick[static_cast<usize>(cell.x) + static_cast<usize>(cells.x)
448 * (static_cast<usize>(cell.y) + static_cast<usize>(cells.y) * static_cast<usize>(cell.z))];
449 const glm::ivec4 k = g.bricks[static_cast<usize>(b)];
450 i32 low[3];
451 f32 frac[3];
452 for (int a = 0; a < 3; ++a) {
453 const f32 local = (grid[a] - static_cast<f32>(k[a] * kBrickCells)) / static_cast<f32>(k.w);
454 low[a] = std::min(std::max(static_cast<i32>(std::floor(local)), 0), kBrickCells - 1);
455 frac[a] = std::fmin(std::fmax(local - static_cast<f32>(low[a]), 0.0f), 1.0f);
456 }
457 const bool sky = g.hasSkyVisibility();
458 out = ProbeConstants{};
459 for (u32 corner = 0; corner < 8; ++corner) {
460 const f32 w = ((corner & 1u) ? frac[0] : 1.0f - frac[0])
461 * ((corner & 2u) ? frac[1] : 1.0f - frac[1])
462 * ((corner & 4u) ? frac[2] : 1.0f - frac[2]);
463 if (w <= 0.0f) continue;
464 const i32 t = (low[0] + ((corner & 1u) ? 1 : 0))
465 + kBrickTexels * ((low[1] + ((corner & 2u) ? 1 : 0)) + kBrickTexels * (low[2] + ((corner & 4u) ? 1 : 0)));
466 const usize base = (static_cast<usize>(b) * static_cast<usize>(ProbeVolume::kBrickProbes) + static_cast<usize>(t)) * 9;
467 for (u32 c = 0; c < 9; ++c) {
468 const glm::vec3& sh = g.irradiance[base + c];
469 out.irradiance[c].x += sh.x * w;
470 out.irradiance[c].y += sh.y * w;
471 out.irradiance[c].z += sh.z * w;
472 }
473 if (sky) {
474 out.reflection.y += g.skyVisibility[base] * w;
475 for (u32 c = 1; c < 9; ++c) out.irradiance[c].w += g.skyVisibility[base + c] * w;
476 }
477 }
478 out.irradiance[0].w = 1.0f;
479 if (sky) out.reflection.z = 1.0f;
480 }
481
488 static Shape shapeFor(i32 bricks, i32 maxSlotsX, i32 maxSlotsYZ, const glm::ivec3& extent) {
489 Shape best;
490 if (bricks <= 0 || maxSlotsX <= 0 || maxSlotsYZ <= 0) return best;
491 i64 bestTexels = 0;
492 for (i32 sx = 1; sx <= std::min(bricks, maxSlotsX); ++sx) {
493 for (i32 sy = 1; sy <= std::min((bricks + sx - 1) / sx, maxSlotsYZ); ++sy) {
494 const i32 sz = (bricks + sx * sy - 1) / (sx * sy);
495 if (sz > maxSlotsYZ) continue;
496 Shape s;
497 s.slots = {sx, sy, sz};
498 s.pageWidth = std::max(sx * kBrickTexels, extent.x);
499 s.height = std::max(sy * kBrickTexels, extent.y);
500 s.depth = std::max(sz * kBrickTexels, extent.z);
501 const i64 texels = static_cast<i64>(s.pageWidth) * s.height * s.depth;
502 if (best.slots.x == 0 || texels < bestTexels) { best = s; bestTexels = texels; }
503 }
504 }
505 return best;
506 }
507
508 std::vector<Volume> volumes_;
509 mutable u64 revision_ = 0;
510 mutable u64 revision_hash_ = 0;
511 std::vector<u64> atlas_key_;
512 std::vector<Placed> placed_;
513 Shape shape_;
514 u32 atlas_width_ = 0;
515 u32 atlas_height_ = 0;
516 u32 atlas_depth_ = 0;
517 u32 atlas_texture_ = 0;
518 mutable u32 per_pixel_draws_ = 0;
519 mutable u32 per_object_draws_ = 0;
520};
521
522} // namespace esengine
IEEE binary32 → binary16, for the data the GPU takes at half width.
The indirect light where ONE draw stands, when a grid was baked for it.
A baked environment sampled on a grid, rather than held at one value.
What a resource's content is, as a number that changes whenever it does.
Core type definitions and utilities for ESEngine.
The frame's probe volumes, and the trilinear read through them.
static constexpr i32 kBrickCells
glm::ivec3 slotOrigin(i32 index) const
Where brick slot index's first texel sits in page 0.
u32 brickCount() const
Bricks the atlas holds, across every grid placed.
void add(const glm::vec3 &min, const glm::vec3 &max, const ProbeVolume *grid)
Takes a volume, or ignores one no point can be inside. A grid whose coefficients do not match its res...
static constexpr i32 kBrickTexels
bool layoutAtlas(u32 maxSide)
Places every volume's grid in the atlas. True when the atlas's texels changed and want uploading.
u32 atlasTexture() const
bool sampleBox(const glm::vec3 &centre, const glm::vec3 &half, ProbeConstants &out, bool perPixel=false) const
The volume a whole object stands in, by its world box rather than its origin.
bool sample(const glm::vec3 &p, ProbeConstants &out, bool perPixel=false) const
The irradiance at p, read trilinearly. False = no volume holds it.
void noteDraw(bool perPixel) const
Counts a draw that read a volume this frame, per pixel or per object: what the stats say a frame paid...
void fillAtlas(std::vector< u16 > &out) const
The atlas's texels, RGBA half floats, slice after slice: a coefficient's rgb and the sky's visibility...
u32 atlasHeight() const
u64 revision() const
What the frame's probe volumes say, as a number that changes whenever it does (see core/Revision....
u32 pageWidth() const
Texels across one page: the x distance from a coefficient's texel to the next one's.
u32 perObjectDraws() const
static constexpr i32 kAtlasPages
Pages across the atlas: the nine coefficients', then the indirection's.
static constexpr u32 kReadsPerLookup
Texture reads one per-pixel lookup costs: the indirection cell, then a filtered read per coefficient.
u64 atlasBytes() const
What the atlas takes on the GPU: four half floats a texel, no mips. What a sparse grid saves is here.
void forgetAtlas()
Drops the atlas's layout, so the next layoutAtlas places everything again and says it changed....
void setAtlasTexture(u32 id)
The atlas texture this frame's per-pixel runs point into; 0 = none, and every draw reads per object.
static glm::ivec3 bricksFor(const glm::ivec3 &resolution)
Bricks along each axis of a grid: enough cells for every probe interval, one on a flat axis.
u32 perPixelDraws() const
Irradiance at a grid of points — an Environment sampled, not held.
glm::ivec3 cells() const
u64 revision
Changes whenever the coefficients do (a new grid, its sky visibility set): what the frame's probe atl...
static constexpr i32 kBrickSide
static constexpr i32 kBrickCells
Cells a brick spans along each axis at its own spacing, and the probes it carries (its far faces too)...
std::vector< glm::ivec4 > bricks
Sparse only: each brick's first finest-brick cell (xyz) and its span in those cells (w)....
std::vector< f32 > skyVisibility
How much of the sky each probe sees: nine coefficients per probe, cosine-convolved like the irradianc...
std::vector< glm::vec3 > irradiance
Nine RGB coefficients per probe: in grid order when dense, brick after brick (each brick's probes x f...
bool hasSkyVisibility() const
static constexpr i32 kBrickProbes
glm::ivec3 resolution
Probes along each axis of the finest grid. One on an axis is a constant along it — which is what an E...
u64 fnv1aBytes(u64 h, const void *data, usize bytes)
Definition Hash.hpp:21
constexpr u64 kFnv64Offset
Definition Hash.hpp:12
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
u16 packHalf(f32 value)
IEEE binary32 to binary16.
Definition Half.hpp:25
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::int64_t i64
Signed 64-bit integer.
Definition Types.hpp:56
std::uint16_t u16
Unsigned 16-bit integer.
Definition Types.hpp:43
u64 nextRevision()
A revision no content has had before. Never 0, which reads as "none".
Definition Revision.hpp:24
float f32
32-bit floating point
Definition Types.hpp:59
The indirect light one instance stands in — both halves of it.
One volume: a world box, and the grid solved inside it.
glm::ivec3 indirection
Where its grid's indirection cells start in the atlas (a texel of the indirection page)....
const ProbeVolume * grid