Skip to content

Foliage & Impostors ​

RedGPU.Landscape.FoliageManager streams tens to hundreds of thousands of 3D meshes—such as trees, rocks, and shrubs—across sub-cells on the terrain, combining multi-stage mesh LODs with Octahedral Impostors for high-speed rendering.


1. Registering Foliage Types (foliageManager.addType) ​

Pass a model loaded via GLTFLoader or Mesh to landscape.foliageManager.addType(options) to register a foliage type (Foliage).

  • lods: Specifies an array of 3D mesh LOD configurations ([{ mesh, lodDistance }]) switched by camera distance.
  • useImpostor: true (default): Beyond the final 3D mesh LOD distance up to cullingDistance, instances automatically transition into runtime-baked Octahedral Impostor billboards to minimize draw calls.
  • targetLayer: Automatically scatters vegetation only where a specific terrain splatting layer (e.g., 'Grass') has high weight.
javascript
new RedGPU.GLTFLoader(
    redGPUContext,
    './assets/terrain/pine_tree.glb',
    (loader) => {
        const treeMesh = loader.resultMesh;

        const pineFoliage = landscape.foliageManager.addType({
            name: 'PineTree',
            lods: [
                { mesh: treeMesh, lodDistance: 120 } // 0 ~ 120m: Render 3D mesh
            ],
            useImpostor: true,          // 120m ~ cullingDistance: Auto-switch to octahedral impostor
            cullingDistance: 4000,      // Maximum visible distance (4000m)
            shadowCullDistance: 150,    // Shadow casting distance (150m)
            densityPerHectare: 120,     // Target instance density per hectare (10,000㎡)
            targetLayer: 'Grass',       // Distribute proportional to 'Grass' terrain layer weight
            minSlope: 0,
            maxSlope: 35,               // Place only on slopes up to 35 degrees
            minScale: [0.4, 0.4, 0.4],
            maxScale: [0.7, 0.75, 0.7],
            trunkBendScale: 1.0,        // Trunk bending multiplier driven by global wind (scene.windManager)
            leafFlutterScale: 1.0       // Leaf flutter multiplier driven by global wind
        });
    }
);

Live Example: Foliage & Impostors ​


2. FoliageOptions Key Properties ​

CategoryPropertyDefaultDescription
Identity & LODnameRequiredUnique identifier name for the foliage type
lodsRequiredArray of distance-based LOD configurations ([{ mesh, lodDistance, receiveShadow }])
useImpostortrueAutomatically bakes and uses distant Octahedral Impostors
cullingDistance200.0Maximum visible distance from the camera at which instances are rendered
Density & PlacementdensityPerHectare1000.0Baseline placement density per hectare (10,000㎡)
densityMultiplier1.0Real-time multiplier applied to the baseline density
targetLayer''Name or index of the LandscapeLayer used to weight placement probability
densityScaleByWeighttrueWhether to scale instance density proportional to targetLayer weight
Transform & SlopeminSlope / maxSlope0.0 / 45.0Minimum and maximum terrain slope angles allowed for placement (in degrees)
minScale / maxScale[1, 1, 1]Per-instance random scale range [x, y, z]
alignToNormal / alignFactorfalse / 1.0Whether to align instance rotation with the terrain surface normal and alignment strength
bottomOffset0.0Vertical (Y) offset relative to the terrain surface
Ground Blend & WindgroundBlendStrength1.0Blending strength between the foliage base and terrain surface color/normal (0.0 ~ 1.0)
trunkBendScale / leafFlutterScale1.0 / 1.0Trunk bending and leaf flutter multipliers reacting to scene.windManager
ShadowscastShadow / receiveShadowtrue / trueEnables shadow casting and receiving
shadowCullDistance50.0Maximum distance at which shadows are cast in the shadow pass


Next Step: Learn Water System