raisin::FoliageMeshLodBaker
class · #include <rayrai/FoliageMeshLodBaker.hpp>
A textured 3D foliage LOD reconstructed from six or ten source-mesh captures. Each small surface patch stays fixed in world axes; it never faces the view. Source leaf holes, albedo and normals survive in the atlases. Call update() until zero before using tile().levels. This baker owns textures and must outlive every visual using them; use on the current GL render thread. Self-shadow visibility is baked for the example's fixed sun; runtime PBR lights the mesh. This is not Nanite or a foliage voxel ray tracer.
Nested classes
structGeometry — CPU triangle mesh.structTile — One baked cell: its source placements and the resulting LOD meshes and atlases.
Public types
Meshes
using Meshes = std::shared_ptr<std::vector<std::shared_ptr<OpenGLMesh>>>Shared mesh list, as used by InstancedVisuals LOD slots.
Constructors & destructor
FoliageMeshLodBaker
FoliageMeshLodBaker(
raisin::RayraiWindow &source,
std::span<const std::shared_ptr<raisin::InstancedVisuals>> prototypes,
std::array<int, levelCount> grids={64, 32, 16},
bool selectCaptureView=false,
int captureResolution=512)Parameters
| Parameter | Description |
|---|---|
source | Viewer whose quality settings and main light the captures copy. |
prototypes | One ready InstancedVisuals per species (opaque/masked triangles). |
grids | Reconstruction grid per level; each must divide captureResolution. |
selectCaptureView | True for ten views (8 horizontal + top + bottom) in an RGBA8 atlas; false for six axis views in an RGBA16F atlas. |
captureResolution | Per-view capture size: 256, 512 or 1024. |
Exceptions
| Exception | Description |
|---|---|
std::invalid_argument | on any invalid argument or unready prototype. |
Public member functions
setPreparedCache
void setPreparedCache(
const std::filesystem::path &directory,
uint64_t contentKey)Enable an on-disk cache of baked tiles in directory, keyed partly by contentKey. The caller's content key must cover source meshes, material settings, textures and baker implementation changes. Capture layout, roots, tint and lighting are additionally fingerprinted here. Configure before update().
preparedCacheLoads
size_t preparedCacheLoads() constReturns Tiles restored from the prepared cache.
preparedCacheStores
size_t preparedCacheStores() constReturns Tiles written to the prepared cache.
mipLevelCount
int mipLevelCount() constReturns Mip levels of each atlas texture.
add
size_t add(raisin::StreamedFoliage::Placements roots)Queue a tile; roots holds one placement list per prototype (throws otherwise). Cells with no instances produce no geometry.
Returns Tile index for tile() and install().
update
size_t update()Perform one capture pass (or one cache load).
Returns Passes still remaining for all queued tiles; 0 when done.
tile
const Tile &tile(size_t i) constParameters
| Parameter | Description |
|---|---|
i | Tile index from add(). |
Returns Tile i (throws std::out_of_range).
install
void install(InstancedVisuals &visual, size_t index) constInstall this tile's three resolutions in the renderer's six selection slots. Grid spacing is an approximation budget, not a Hausdorff bound. Verify silhouettes from oblique views before choosing production grids. Uses an error budget of 0.5 / grid for each level.
Parameters
| Parameter | Description |
|---|---|
visual | Target batch. |
index | Tile index. |
void install(
InstancedVisuals &visual,
size_t index,
std::array<float, levelCount> errors) constSame as install(visual, index) with explicit per-level relative error budgets.
Parameters
| Parameter | Description |
|---|---|
visual | Target batch. |
index | Tile index. |
errors | Non-negative budget per level. |
Exceptions
| Exception | Description |
|---|---|
std::logic_error | if the tile is unfinished or was installed with other budgets. |
Static member functions
reconstruct static
static Geometry reconstruct(
std::span<const float> depth,
int resolution,
int grid,
const raisin::Camera &camera,
size_t face,
int columns=3,
int rows=2)Reconstruct world-space surface patches from one orthographic depth capture. Independent micro-surfaces prevent triangles bridging depth discontinuities or empty space. The original alpha mask supplies detail inside each patch.
Parameters
| Parameter | Description |
|---|---|
depth | Capture depth buffer (resolution x resolution, values in [0, 1]). |
resolution | Capture size in pixels. |
grid | Cells per side; divides resolution. |
camera | Orthographic capture camera. |
face | Atlas face index of the capture. |
columns | Atlas columns. |
rows | Atlas rows. |
Returns Surface patches with atlas texture coordinates; throws std::invalid_argument on bad input.
Public attributes
levelCount
static constexpr size_t levelCountBaked resolutions per tile.