Skip to main content

TreeLayer

TreeLayer renders procedural 3D trees on WebGL2 and WebGPU. Templates describe wood, foliage and crop attachments for eight species, with individual leaves up close, fitted leaf clumps at middle distances and fitted crown hulls farther away. Trees sharing a template can vary in size, growth, foliage, color, crops and wind.

The demo above is the Seasonal Farm example.

Usage​

import {TreeLayer} from '@deck.gl-community/layers/tree-layers';

new TreeLayer({
id: 'trees',
data: [
{position: [-122.4194, 37.7749], species: 'oak', height: 10, season: 'autumn'},
{
position: [-122.4196, 37.7749],
species: 'citrus',
height: 5,
crop: {kind: 'fruit', color: [244, 153, 34, 255], count: 40, radius: 0.08}
}
],
pickable: true
});

Each row is a TreeSpec by default. Use getTree to map other records:

new TreeLayer({
data: records,
getTree: record => ({position: record.coordinates, species: record.kind, height: record.height})
});

Properties​

Inherits all CompositeLayer properties. Picking, autoHighlight and highlightedObjectIndex use the source row.

PropertyDefaultDescription
getTreed => dReturns the TreeSpec for a row.
characteristics{}Shared template characteristics. See Characteristics.
sizeScale1Multiplier for all tree and crop dimensions.
lodBias0Positive values switch to simpler crown detail closer to the camera. Negative values retain individual detail farther away.
windEnabledtrueFollows the scene’s WindEffect.
getCoverageWeight1Per-tree optical coverage, for fading trees in and out.
transitionsnullInterpolation settings keyed by a TreeLayer accessor. Pass a duration in milliseconds or an object with duration and optional easing.
woodMaterial, foliageMaterial, cropMaterialnullOptional Phong material overrides.

Per-field accessors​

Each accessor overrides one TreeSpec field, so you can change a single trait, such as a global season, without rebuilding your data. Function accessors follow deck.gl's updateTriggers convention.

AccessorOverridesFallback
getPositionpositiond => d.position
getElevationelevation0
getTreeTypespecies'pine'
getHeightheightspecies default
getTrunkHeightFractiontrunkHeightFractionspecies default
getTrunkRadiustrunkRadiusspecies default
getCanopyRadiuscrownRadiusspecies default
getTrunkColortrunkColorspecies default
getCanopyColorcanopyColorspecies and season default
getSeasonseason'summer'
getBranchLevelsbranchLevels3
getCropcropnull
getGrowth, getHealth, getFoliagegrowth, health, foliage1
getFlush, getDamage, getDecayflush, damage, decay0
getLeanlean[0, 0]

getCanopyRadius uses a legacy scale: broadleaf crowns render at about half its value. For a crown radius in metres, set crownRadius in getTree instead.

Canopy colors​

Return an RGBA color from getCanopyColor to override a tree's foliage color, or return null to keep its natural species/season palette. With the default accessor, TreeSpec.canopyColor supplies the authored override. Natural and custom-colored trees can share one layer. The same behavior applies to shells, transitions, and coarse, fine, macro and airborne leaves on WebGL2 and WebGPU.

new TreeLayer({
data: records,
getTree: record => record.tree,
getCanopyColor: record => record.classColor ?? null,
updateTriggers: {getCanopyColor: paletteRevision}
});

Authored colors use neutral light intensity and hue-preserving display encoding. Surfaces retain shading, specular form and shadows; foliageMaterial: {unlit: true} displays the supplied RGB directly. Botanical pigment, age, health, flush and underside color shifts continue for natural palettes and are bypassed for authored colors. Lifecycle geometry, wind, bark and crop materials retain their existing behavior.

Canopy alpha remains optical coverage, and layer opacity retains per-surface transparency, including gamma encoding and accumulation through overlapping surfaces. RGB changes and changes between natural and authored color retain cached geometry and detail selection; alpha or coverage changes can update wood and shadow residency. Keep source data stable and use updateTriggers for function accessors. The default tint accessor refreshes the corresponding authored TreeSpec field through getTree when its color trigger changes.

SelectionPulseExtension retains mature-leaf shading and conservative spatial culling. Its color-only pulse preserves alpha, so opaque attached leaves also retain opaque blending. Other extension implementations use the general rendering path; changing extensions refreshes cached leaf selections.

Types​

TreeSpec​

FieldDescription
positionTree base position. Required.
speciesOne of the species below. Defaults to pine.
heightTotal height in metres.
crownRadiusCrown radius in metres.
trunkRadiusTrunk base radius in metres.
trunkHeightFractionFraction of height below the crown, 0–1.
elevationBase elevation in metres.
seasonspring, summer, autumn or winter.
cropA CropConfig value or null.
growthFraction of the tree's development, from 0 to 1. Defaults to 1.
healthFoliage health, from 0 to 1. Defaults to 1.
foliageLeaf coverage, from 0 to 1. Defaults to the season.
flushAmount of new growth color, from 0 to 1. Defaults to 0.
leanTuple of tilt and compass bearing in degrees. Broadleaf templates show a root plate when a tree leans far enough to lift it.
damageLimb damage, from 0 to 1. Defaults to 0.
decayWood and leaf decay, from 0 to 1. Defaults to 0.
characteristicsPer-tree characteristics, merged over the layer prop.
trunkColorRGBA bark color override.
canopyColorRGBA foliage color override.
branchLevelsPine tier count, 1–5.

Species are pine, oak, palm, birch, cherry, banyan, mangrove and citrus. Oak, birch and cherry lose their leaves in winter; the others are evergreen.

CropConfig​

FieldDescription
colorRGBA crop color.
countCrops attached inside the crown.
radiusEnclosing radius in metres.
droppedCountCrops scattered on the ground, in addition to count.
kindfruit (default), lemon, cone, acorn, catkin, flower or propagule.

Characteristics​

Characteristics shape broadleaf crowns and leaves. Pine uses its own branching tiers and needle shapes. For palm, seed varies the frond template. Changing characteristics regenerates shared templates, so keep the number of distinct combinations small.

FieldDefaultRangeEffect
seed0integerGrowth pattern.
crownSpread10.6–1.5Crown width.
crownDepth10.6–1.4Crown height.
crownAsymmetry10–2Lopsidedness.
branchDensity10.5–1.5Number of branches.
branchLift10–3Upward branch angle.
internodeLength10.7–1.4Branch segment length.
leafSize10.5–1.8Leaf size.
leafDensity10.25–2Leaf count.
branchWander10–2Curvature of limbs and shoots.
twigDroop10–2Droop of outer shoots and twigs.

Wind​

Add a WindEffect to Deck’s effects with strength, direction and optional time. Gust fronts travel downwind across the grove. Strength controls bend and gust intensity, and the effect clock drives sway, flutter and falling leaves. Use windEnabled: false for a sheltered layer.

Shadows​

Use deck.gl's LightingEffect with a DirectionalLight whose _shadow is true. The effect sets the shadow map's coverage, resolution and color. TreeLayer casts and receives shadows on WebGL2 and WebGPU and keeps its caster geometry stable across visible canopy LOD changes. Set shadowEnabled: false to stop trees from casting. Separate ground and terrain layers need shader support for receiving shadows on their backend. Seasonal Farm supplies a receiver for its plots and paths on WebGL2 and WebGPU.

Limitations​

  • Supports MapView, GlobeView and Cartesian views. With MapView.repeat, trees render in the primary world copy only.
  • On GlobeView, wood, crops and canopies share one east-north-up pose per tree, unchanged across the zoom-12 switch to Web Mercator. Canopies and connected wood behind the horizon are skipped; crops rely on a globe surface's depth, such as MapLibre's globe, to hide the far side.
  • In Cartesian and metre-offset coordinates, modelMatrix supports translation only.

Migrating from the Gaussian canopy renderer​

Remove maxCanopySplats, maxCanopyPixels and foveationStrength. If you used a preview build, remove its quality switch as well. Set lodBias to tune the distance at which trees use coarser detail. Use the source row's TreeSpec or field accessors to control appearance. Custom sublayer overrides that target Gaussian canopies need to move to the tree's supported material, accessor or extension properties. A standalone Gaussian canopy can still use SplatLayer.

Source​

modules/layers/src/tree-layers/tree-layer