Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / layer-extensions

Layer extensions

Layer extensions are reusable capabilities that augment a deck.gl layer without requiring a new layer class for each use. An application attaches extension instances through a layer's extensions prop, so one capability can work with many layer types while each layer keeps its own data and rendering role.

Extension model

An extension adds a focused behavior to the layer life cycle. It can add user props, per-object values, shader changes, shared effects, redraw requests, or cleanup work. The base LayerExtension contract is part of @deck.gl/core, while ready-made capabilities are published in the optional @deck.gl/extensions package.

Layer attachment

The extensions prop accepts a list of extension instances. The layer applies each instance during its normal update and draw cycle. Extension options select the capability shape, while the added layer props control that capability for each layer.

For example, PathStyleExtension({dash: true}) enables dashed-path support. getDashArray then supplies the pattern for each object. This split lets the same extension instance serve many layers without changing their data model.

References: modules/…/layer-props.ts• L201-207 modules/…/layer-extension.ts• L11-35 modules/…/path-style-extension.ts• L213-231

Layer life cycle

Extension behavior runs beside the layer rather than as a separate layer. The layer combines extension shader contributions with its own shader description, then calls extension hooks during setup, update, draw, picking, and cleanup. This lets an extension change output while the layer remains responsible for its normal rendering work.

References: modules/…/layer.ts• L464-477 modules/…/layer.ts• L1002-1019 modules/…/layer.ts• L1072-1119

Composite layer propagation

Composite layers create primitive sublayers to render their data. Their extension list and extension-added props pass through that boundary, so an extension attached to a composite layer can affect the sublayers that carry out the draw. Accessor context and update triggers also pass through so extension values still refer to the source object and refresh when its inputs change.

References: modules/…/layer-extension.ts• L43-64 modules/…/composite-layer.ts• L121-143 modules/…/composite-layer.ts• L145-188

Optional extensions package

@deck.gl/extensions is a separately published package for reusable capabilities that should not be part of every layer by default. It keeps optional shader, attribute, and effect work out of layers that do not use it. The package depends on compatible deck.gl core and rendering-engine releases rather than acting as a separate rendering system.

References: modules/…/package.json• L1-7 modules/…/package.json• L44-52

The package exposes named extension classes and related types. Its capabilities cover interaction, filtering, overlap control, spatial bounds, terrain, and reusable visual style. Terrain remains an experimental export named _TerrainExtension.

CapabilityPurpose
BrushingShow or hide objects near the current pointer position.
Data filteringShow, hide, or fade objects by numeric values or categories.
Collision filteringPrefer higher-priority objects when content overlaps.
MaskingShow objects inside or outside a source-defined region.
ClippingLimit instances or geometry to a rectangular region.
Terrain fittingPlace overlays on or render them through a 3D terrain surface.
Path stylingAdd dashed strokes or line offsets to supported path-like layers.
Fill stylingAdd image-based or generated patterns to supported filled layers.

References: modules/…/package.json• L1-7 modules/…/index.ts• L5-44

Capability limits

An extension only affects layer types and rendering paths that can support its behavior. Applications must treat an extension as a capability for a compatible layer, not as a guarantee that every layer accepts every feature.

CapabilityMain boundary
Path stylingSupports path, scatterplot, and text-background rendering in different ways.
Fill stylingDoes not apply to path-tessellated layers.
MaskingRequires a valid source layer and is not available in GlobeView.
Terrain fittingDepends on a terrain source and support for the selected rendering path.
Collision filteringGroups visible layers and resolves overlap within each group.
Data filteringUses the layer's supported GPU data path and a bounded set of numeric or category channels.

Clipping has two behaviors. Instance clipping hides a whole object when its anchor is outside the rectangle. Geometry clipping keeps the intersecting part of the geometry. The extension selects the mode from the layer shape unless the application sets clipByInstance.

References: modules/…/path-style-extension.ts• L233-343 modules/…/fill-style-extension.ts• L118-145 modules/…/mask-extension.ts• L20-35 modules/…/terrain-effect.ts• L45-51 modules/…/clip-extension.ts• L34-52

Extension flows

An extension flow starts with normal layer props and adds only the state and rendering work needed by the selected capability. The shader plugin interface lets the same capability describe its inputs and output changes for both supported rendering backends.

The diagram shows the common path from attachment to augmented output.

flowchart LR
  A[Layer props] --> B[Attached extension]
  B --> C[Extension options and defaults]
  C --> D[Layer update and draw hooks]
  D --> E[Extra state and shader inputs]
  E --> F[Augmented layer output]
  B --> G[Composite parent]
  G --> H[Primitive sublayers]
  H --> D

Brushing flow

BrushingExtension uses the current pointer position to show objects within a radius. The layer data stays unchanged. Pointer movement only requests a redraw so the shader can apply the new position.

The extension can test a source position, a target position, both endpoints, or a custom position returned by getBrushingTarget. A custom target adds per-object target data only when the layer needs it. The visibility test is described for both GLSL and WGSL paths.

References: modules/…/brushing-extension.ts• L11-16 modules/…/brushing-extension.ts• L19-37 modules/…/brushing-extension.ts• L51-95 modules/…/shader-module.ts• L97-170

Data filtering flow

DataFilterExtension keeps source data in place while the GPU decides which objects pass active numeric or category rules. Numeric values can hide objects or fade them within a soft range. Category values use a layer-local bit map, so one extension instance can serve several layers without mixing their category state.

Applications can change filter ranges or categories without rebuilding the source data. Optional item counting adds a separate result for the number of objects that pass the filter. The count uses a GPU result that is read back synchronously on WebGL when possible and asynchronously on WebGPU. The extension releases the count resources when the layer state ends.

References: modules/…/data-filter-extension.ts• L35-112 modules/…/data-filter-extension.ts• L134-185 modules/…/data-filter-extension.ts• L187-337 modules/…/data-filter-extension.ts• L342-351 modules/…/attributes.ts• L75-118 modules/…/shader-plugin.ts• L42-105 modules/…/aggregator.ts• L59-167

Collision filtering flow

Collision filtering uses a rendered collision map to decide which overlapping objects stay visible. Layers are grouped by collisionGroup, and higher collision priority is drawn first. Later draws read the shared map and fade or hide objects that overlap higher-priority content.

The map is refreshed when the view, participating layers, bounds, loading state, or transitions change. A small sample area smooths the visibility result and reduces flicker at pixel boundaries. The collision shader keeps this behavior aligned between WebGL and WebGPU.

References: modules/…/collision-filter-extension.ts• L9-74 modules/…/collision-filter-effect.ts• L46-103 modules/…/collision-filter-effect.ts• L127-173 modules/…/shader-module.ts• L80-189

Path styling flow

PathStyleExtension adds dashed strokes or line offsets to supported path-like layers. It supports path layers plus dashed scatterplot outlines and text-background borders. The extension changes the existing shader path instead of creating separate dashed layer classes.

Capability options enable dashes or offsets. Layer props then select dash arrays, units, alignment, gap picking, and per-object offsets. Segment mode repeats the pattern per rendered segment. Path mode keeps the pattern continuous across segments by using path-distance data and an extra geometry pass. The GLSL and WGSL plugins use the same public options and coordinate rules.

Dash units can be relative to stroke width, pixels, meters, or common space. Path metrics use the same projected space as the rendered path, which keeps dash phase stable when the view, coordinate origin, wrapping, or high-zoom projection changes.

References: modules/…/path-style-extension.ts• L35-126 modules/…/path-style-extension.ts• L213-343 modules/…/path-style-extension.ts• L345-427 modules/…/shaders.glsl.ts• L42-150 modules/…/shaders.wgsl.ts• L34-168

Fill styling flow

FillStyleExtension adds repeated patterns to supported filled layers. An application can provide an image atlas with named regions or generated definitions for hatches, cross-hatches, and dots. Accessors select the pattern, scale, offset, and background color for each object, and composite layers forward these values to the primitive layers that draw them.

Atlas patterns sample named image regions. Procedural patterns use validated pattern definitions and a compact parameter texture, so the fragment shader can generate the result without an image atlas. Pattern size can follow meters, common units, or screen pixels, while the pattern remains stable at high zoom. The extension supplies equivalent GLSL and WGSL shader paths.

References: modules/…/fill-style-extension.ts• L48-157 modules/…/fill-style-extension.ts• L159-252 modules/…/procedural-pattern.ts• L37-202 modules/…/shader-module.ts• L218-384 modules/…/shader-module.wgsl.ts• L110-182 modules/…/float-parameter-texture.ts• L7-25

Mask and terrain flows

Masking and terrain fitting use a source operation plus one or more affected layers. Shared projection rules turn source bounds into a common spatial region, then offscreen results provide context to the affected layer. This keeps CPU bounds and shader coordinates aligned across supported flat and globe-related projection paths, including local east, north, and up directions for globe meter offsets.

Masking assigns source layers to up to four shared channels. A consumer names its source with maskId, and the effect supplies the channel and bounds to the consumer shader. The mask pass clears and writes one channel at a time, which preserves the other active mask sources. The resolved mask context can serve normal and accumulation draws, so source points and visible output use the same region. The shader converts the consumer position to the flat mask space and discards fragments outside or inside the selected region based on the inverse setting.

Terrain fitting has two main results. A terrain source can write elevation for offset layers. It can also render draped layers into a cover texture so the final image follows the terrain surface rather than appearing as a flat overlay. terrainDrawMode selects offset or drape behavior when the layer does not set it directly. Both modes are available through the WebGL and WebGPU terrain paths.

The diagram shows how source layers produce shared spatial results for consuming layers.

sequenceDiagram
  participant App as Application
  participant Source as Mask or terrain source
  participant Effect as Shared effect
  participant Layer as Extended layer

  App->>Source: Declare source operation
  App->>Layer: Attach extension and props
  Effect->>Source: Build shared spatial result
  Effect->>Layer: Provide mask or terrain context
  Layer->>Layer: Render with selected context

References: modules/…/mask-effect.ts• L62-105 modules/…/mask-effect.ts• L155-210 modules/…/mask-pass.ts• L30-117 modules/…/shader-module.ts• L62-185 modules/…/mask-extension.ts• L20-105 modules/…/terrain-effect.ts• L54-129 modules/…/terrain-extension.ts• L15-81 modules/…/shader-module.ts• L36-49 modules/…/shader-module.ts• L107-151 modules/…/shader-module.ts• L176-244 modules/…/shader-module.wgsl.ts• L7-108 modules/…/projection-utils.ts• L61-112

Clipping flow

ClipExtension limits a layer to rectangular bounds without changing its data. It converts the bounds into the layer's rendering space, then either tests each object's anchor or trims fragments at the geometry boundary. The extension provides matching behavior for GLSL and WGSL paths.

This distinction lets point-like layers keep whole-object visibility while polygon-like layers keep only the part that intersects the rectangle. Wrapped geospatial bounds are handled in the same spatial comparison.

The same clip state can also be supplied to accumulation draws. This keeps the visible layer and derived results such as aggregated output within the same rectangle.

References: modules/…/clip-extension.ts• L11-52 modules/…/clip-extension.ts• L54-90 modules/…/shader-module.ts• L67-129 modules/…/clip-extension.ts• L25-117

Custom extension flow

A custom extension is useful when one behavior must apply to several unrelated layer classes or to a composite layer and its sublayers. The author defines the added props and only the hooks that matter, then attaches one instance wherever the behavior is needed.

Options should hold choices that define shader or structural behavior. Layer props should hold values that change during normal updates. This keeps extension equality and shader rebuild behavior predictable when equivalent instances are reused.

References: docs/…/layer-extensions.md• L5 docs/…/layer-extensions.md• L95-110 modules/…/layer-extension.ts• L27-35

Use the data and visualization extensions page for the wider extension area. Use the JSON specification page when a layer configuration crosses a serialized boundary. See the Carto integration page when extensions participate in a Carto-backed map workflow.

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to extension options or default props must stay aligned with shader defines, added attributes, and composite prop forwarding.
  • Changes to a shader plugin must preserve the matching GLSL and WGSL inputs, uniforms, varyings, and injection points.
  • Changes to shared projection rules must stay aligned between source bounds, offscreen viewports, globe handling, local globe meter-offset orientation, wrapped coordinates, and shader common-space tests.
  • Changes to brushing target selection must stay aligned between pointer redraws, custom target data, and the source or target positions exposed by supported layers.
  • Changes to clip mode must stay aligned with layer attributes, packed positions, world wrapping, and both rendering backends.
  • Changes to clip aggregation props must keep ordinary draws and accumulation draws in the same coordinate space.
  • Changes to path dash units or path metrics must stay aligned between public props, CPU distance data, and shader coordinate spaces.
  • Changes to fill pattern mappings or generated pattern records must stay aligned between per-object selection, texture format, and the texture consumed by both shader backends.
  • Changes to data-filter category state must preserve layer-local mappings when one extension instance is shared.
  • Changes to filtered-item counting must stay aligned between attribute indices, the framebuffer layout, device feature checks, and asynchronous result invalidation.
  • Changes to mask channel clearing must preserve selected-channel isolation across WebGL and WebGPU while retaining the active pass viewport and scissor.
  • Changes to mask coordinate conversion must keep instance and vertex paths aligned across GLSL and WGSL, wrapped longitude, and flat mask bounds.
  • Changes to mask or terrain source contracts must be checked against both source operations and consuming extension props.
  • Changes to terrain draw-mode selection must stay aligned with terrain effect setup, height-map or cover results, redraw state, and both rendering backends.
  • Changes to collision groups or priorities must stay aligned between collision-map rendering and normal layer visibility.
  • Changes to projection precision helpers must stay aligned between high and low coordinate parts in every backend that consumes them.
  • Changes to package exports must preserve the public class names and the separate type exports used by JavaScript and TypeScript applications.

Important failure modes

TriggerConsequenceGuard
An extension is attached to an unsupported layer or rendering path.The feature has no effect or produces an invalid result.Check the capability limits before composing extensions.
A composite layer does not forward an extension prop or update trigger.Sublayers keep stale values or differ from the parent behavior.Preserve extension pass-through props and accessor triggers.
Pointer movement does not request a redraw.Brushing stays at the old pointer position.Keep pointer events connected to the attached layer's redraw path.
A GLSL and WGSL shader path uses different inputs or coordinate rules.One rendering backend can fail during setup or render different output.Keep plugin declarations and injections aligned across backends.
A mask pass clears the full color attachment instead of only its selected channel.One mask source erases the mask data for other active sources.Use a channel-limited clear before each mask channel is rendered.
Mask bounds use a different coordinate space from the mask texture.Consumers discard the wrong fragments or do not apply the mask.Keep source bounds, flat projection, wrapping, and shader sampling aligned.
Clip bounds use a different coordinate space from layer geometry.Objects disappear too early or remain outside the requested region.Keep bound conversion aligned with packed positions and shader projection.
Clip state differs between visible and accumulation draws.Aggregated output includes data outside the visible region.Derive both draw paths from the same transformed clip bounds.
Path mode has GPU-only path data without supplied dash offsets.Continuous dash phase cannot be calculated.Supply readable path data or instanceDashOffsets.
A fill pattern has no matching atlas frame or generated definition.The object can appear unfilled.Keep selected names and pattern mappings aligned.
A procedural pattern has an invalid size, gap, angle, or skew.Pattern data creation fails before the layer can draw.Validate pattern definitions before use.
A mask consumer names an empty or unknown maskId.The layer renders without the intended mask.Use a visible mask source with a matching id.
More than four mask sources are active.Extra mask sources are ignored.Keep active mask sources within four channels.
Terrain fitting lacks a terrain source or the selected mode is unsupported by the active browser path.Overlays do not fit the intended surface.Provide a terrain operation and use a supported rendering path.
Collision-map state is stale after view or layer changes.Overlapping objects use old visibility decisions.Refresh the collision group when its view or participants change.
A category value exceeds the filter channel capacity.The object fails the category filter even when the source category is selected.Keep category counts within the capacity for the selected channel size.
Combined extensions exceed device attribute capacity.Layer or shader setup can fail on the target device.Review attribute cost before enabling several data and style extensions.

Key files

FileWhy to read it
modules/…/layer-extension.tsDefines the shared extension contract and composite prop pass-through.
modules/…/layer.tsShows where extensions join shader assembly and the layer life cycle.
modules/…/composite-layer.tsShows how extensions reach primitive sublayers.
modules/…/package.jsonDefines the optional package and its core package relationship.
modules/…/index.tsLists the public extension classes and types.
modules/…/brushing-extension.tsShows pointer-based visibility as a reusable capability.
modules/…/shader-module.tsShows the portable shader behavior for pointer-based visibility.
modules/…/data-filter-extension.tsShows numeric and category filtering with optional counts.
modules/…/shader-plugin.tsShows how filter inputs are exposed to both shader backends.
modules/…/aggregator.tsShows how optional filtered-item counts are produced.
modules/…/collision-filter-effect.tsShows how collision groups build and refresh shared overlap maps.
modules/…/shader-module.tsShows how the collision map changes layer visibility.
modules/…/clip-extension.tsShows rectangular clipping by anchor or geometry and shared clip state for accumulation.
modules/…/shader-module.tsShows the matching instance and geometry clipping paths.
modules/…/path-style-extension.tsShows reusable dash and offset behavior across layer variants.
modules/…/shaders.glsl.tsShows the shared GLSL shader path for dash and offset behavior.
modules/…/shaders.wgsl.tsShows the matching WebGPU path and portable layer inputs.
modules/…/fill-style-extension.tsShows atlas-backed and generated fill pattern selection.
modules/…/procedural-pattern.tsDefines the supported generated pattern shapes and validation.
modules/…/shader-module.tsShows how pattern data becomes fill output.
modules/…/shader-module.wgsl.tsShows the WebGPU fill pattern path.
modules/…/float-parameter-texture.tsShows how generated pattern parameters cross device texture formats.
modules/…/mask-effect.tsShows source channel allocation and shared mask context.
modules/…/mask-pass.tsShows how mask channels are cleared and rendered into the shared mask map.
modules/…/shader-module.tsShows how consumer positions become mask samples in both shader backends.
modules/…/masked-color-clear.tsShows the channel-limited clear used by WebGPU mask rendering.
modules/…/mask-extension.tsShows how a consumer names and applies a mask source.
modules/…/terrain-effect.tsShows shared terrain height and cover results.
modules/…/shader-module.tsShows how terrain context changes placement and output.
modules/…/shader-module.wgsl.tsShows the WebGPU terrain path for height-map writes and offset placement.
modules/…/terrain-extension.tsShows how layers select offset or drape behavior across rendering paths.
modules/…/projection-utils.tsShows the CPU projection rules shared by mask and terrain spatial results.
modules/…/project64.tsShows the high-precision projection module used by precision-sensitive extension paths.
docs/…/layer-extensions.mdDescribes the authoring model for custom reusable behavior.