Skip to content

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 ​

  • struct Geometry — CPU triangle mesh.
  • struct Tile — One baked cell: its source placements and the resulting LOD meshes and atlases.

Public types ​

Meshes ​

cpp
using Meshes = std::shared_ptr<std::vector<std::shared_ptr<OpenGLMesh>>>

Shared mesh list, as used by InstancedVisuals LOD slots.

Constructors & destructor ​

FoliageMeshLodBaker ​

cpp
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

ParameterDescription
sourceViewer whose quality settings and main light the captures copy.
prototypesOne ready InstancedVisuals per species (opaque/masked triangles).
gridsReconstruction grid per level; each must divide captureResolution.
selectCaptureViewTrue for ten views (8 horizontal + top + bottom) in an RGBA8 atlas; false for six axis views in an RGBA16F atlas.
captureResolutionPer-view capture size: 256, 512 or 1024.

Exceptions

ExceptionDescription
std::invalid_argumenton any invalid argument or unready prototype.

Public member functions ​

setPreparedCache ​

cpp
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 ​

cpp
size_t preparedCacheLoads() const

Returns Tiles restored from the prepared cache.

preparedCacheStores ​

cpp
size_t preparedCacheStores() const

Returns Tiles written to the prepared cache.

mipLevelCount ​

cpp
int mipLevelCount() const

Returns Mip levels of each atlas texture.

add ​

cpp
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 ​

cpp
size_t update()

Perform one capture pass (or one cache load).

Returns Passes still remaining for all queued tiles; 0 when done.

tile ​

cpp
const Tile &tile(size_t i) const

Parameters

ParameterDescription
iTile index from add().

Returns Tile i (throws std::out_of_range).

install ​

cpp
void install(InstancedVisuals &visual, size_t index) const

Install 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

ParameterDescription
visualTarget batch.
indexTile index.
cpp
void install(
    InstancedVisuals &visual,
    size_t index,
    std::array<float, levelCount> errors) const

Same as install(visual, index) with explicit per-level relative error budgets.

Parameters

ParameterDescription
visualTarget batch.
indexTile index.
errorsNon-negative budget per level.

Exceptions

ExceptionDescription
std::logic_errorif the tile is unfinished or was installed with other budgets.

Static member functions ​

reconstruct static ​

cpp
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

ParameterDescription
depthCapture depth buffer (resolution x resolution, values in [0, 1]).
resolutionCapture size in pixels.
gridCells per side; divides resolution.
cameraOrthographic capture camera.
faceAtlas face index of the capture.
columnsAtlas columns.
rowsAtlas rows.

Returns Surface patches with atlas texture coordinates; throws std::invalid_argument on bad input.

Public attributes ​

levelCount ​

cpp
static constexpr size_t levelCount

Baked resolutions per tile.

RaiSim — physics for robotics and AI.