Skip to main content

Clutter

The Clutter plugin manages procedurally generated content such as vegetation, debris, or other repeated elements using a tile-based system. It leverages GPU compute shaders for stall-free, high-performance generation and placement, making it well-suited for large-scale or dynamic environments. The plugin provides fine-grained control over clutter distribution, density, and behavior through configurable parameters and user-defined callbacks, enabling efficient and flexible instancing across expansive scenes.

The Clutter offers fine-grained control over clutter distribution, density, and behavior through configurable parameters and user-defined callbacks. It enables efficient and flexible instancing of complex scene elements across expansive terrains or procedurally loaded regions.

info

This plugin utilizes the SceneCloner interface to replicate scene nodes, using the clone_graph_node() and clone_graph_nodes() functions in GLSL.

info

Cloned nodes can be hierarchical and may include lights, scripts, and any other Scene types.

#include <objects/clutter/include/TellusimClutter.h>

Example

// Create and configure the clutter system
Clutter clutter;
clutter.setNumTiles(16);
clutter.setTileSize(128.0f);
clutter.setTileSeed(16);
clutter.setTileDensity(96 * 96 / 2);
clutter.setMaxTiles(8);
clutter.setMaxRepeat(1);
clutter.setMaxDistance(clutter.getTileSize() * clutter.getNumTiles() * 0.5f);

// Assign a generation compute shader kernel and a callback for binding resources
clutter.setClutterKernel(clutter_kernel, [&](Compute compute, Clutter::ClutterParameters *parameters, uint32_t size) -> uint32_t {
compute.setSampler(0, linear_sampler);
compute.setTextures(0, { noise_texture, clutter_texture });
return size;
});

// Initialize the clutter system using a device, graph, and density
if(!clutter.create(device, graph, 1.0f)) return false;

// Update tile data based on the current camera
if(!clutter.update(device, sample_camera.getNode())) return false;

// Dispatch compute shader to generate clutter
if(!clutter.dispatch(device, compute)) return false;