Introducing a new way to review your PRs.

Read the announcement

visgl / luma.gl

High-performance Toolkit for WebGL-based Data Visualization

View on GitHub

30 documents · Updated Nov 20, 2026

docs / three-integration

Three.js integration and interoperability

The Three.js integration connects Three.js scenes and objects to luma.gl and deck.gl rendering. It supports full Three.js-style rendering through luma.gl, selected Three content inside caller-owned passes, native deck.gl layers in an existing Three application, and shared GPU buffers between luma.gl compute and Three.js. It is an experimental compatibility layer rather than a replacement for either renderer.

Integration model

Renderer-backed scenes

The renderer-backed path lets Three.js keep control of scene traversal, materials, animation, sorting, shadows, and transmission. LumaRenderer supplies the GPU backend through a borrowed luma.gl WebGPU or WebGL2 device. This path lets an application use luma.gl resources without rewriting an existing Three.js scene (modules/…/luma-renderer.ts• L10-18, modules/…/luma-backend.ts• L187-207).

The translation boundary maps Three.js resource descriptions into luma.gl GPU resources and render work. It preserves upstream binding groups and packed uniform data where possible. WebGL2 supports graphics, while Three.js compute through this backend requires WebGPU (modules/…/translate.ts• L15-71, modules/…/luma-backend.ts• L203-215, modules/…/luma-backend.ts• L852-902).

References: modules/…/luma-renderer.ts• L10-18 modules/…/luma-backend.ts• L187-215 modules/…/luma-backend.ts• L852-902 modules/…/translate.ts• L15-71

Pass-embedded objects

The pass-embedded path places Three.js content into a pass that the application already owns. ThreeMeshAdapter maps a supported ordinary mesh to luma.gl draw state. ThreeSceneAdapter prepares a supported scene and records its draw into the caller's pass. The application keeps control of pass order, native luma.gl draws, submission, and source-object lifetime (modules/…/objects.ts• L72-97, modules/…/objects.ts• L265-295, modules/…/scene-adapter.ts• L117-149).

The mesh path is narrower than the scene path. It targets ordinary triangle meshes with basic untextured materials. Prepared scenes can retain Three.js node materials, textures, lighting, shadows, animation, and related scene services within the tested subset (modules/…/objects.ts• L99-137, modules/…/scene-adapter.ts• L48-55).

References: modules/…/objects.ts• L72-97 modules/…/objects.ts• L99-137 modules/…/objects.ts• L265-295 modules/…/scene-adapter.ts• L48-55 modules/…/scene-adapter.ts• L117-149

Existing Three application paths

The integration separates paths by resource and render ownership. A renderer-backed scene owns its rendering sequence. An adapted mesh joins a caller-owned pass. Native deck.gl layers can share an existing Three WebGL2 depth buffer or use a separate transparent canvas. A buffer bridge shares GPU data without translating a material or scene.

NeedIntegration pathMain result
Render an existing Three.js scene through luma.glLumaRendererThree.js orchestration with luma.gl GPU resources
Mix a simple Three mesh with luma.gl drawsThreeMeshAdapterOne caller-owned pass with shared depth
Mix a prepared Three scene with deck.glThreeSceneAdapter and ThreeSceneLayerA prepared scene drawn into deck.gl's pass
Add native deck layers to a Three WebGL2 canvasThreeDeckInterleavedShared Three/deck color and depth buffers
Add native deck layers above a Three WebGL or WebGPU appThreeDeckOverlaySeparate transparent deck canvas driven by Three
Use luma.gl compute output in Three.jsThreeBufferBridgeShared GPU buffer with no CPU readback

The interleaved path requires a depth-enabled Three WebGL2 default framebuffer with standard depth mapping and a full-canvas viewport. The overlay path does not share a device or depth buffer. It can attach to an initialized Three WebGL or WebGPU renderer (modules/…/interleaved.ts• L18-37, modules/…/overlay.ts• L26-45, modules/…/README.md• L181-199).

References: modules/…/README.md• L181-199 modules/…/interleaved.ts• L18-49 modules/…/overlay.ts• L26-45 modules/…/interop.ts• L26-56

Scene adaptation

Prepared scene rendering

ThreeSceneAdapter adapts a prepared Three.js scene for a caller-owned render pass. Preparation performs resource work that needs a separate target, such as texture upload, environment preparation, and shadow-map updates. The final draw records the scene into the caller's pass without clearing, ending, or submitting that pass (modules/…/scene-adapter.ts• L117-149, modules/…/luma-backend.ts• L130-167).

This split keeps Three.js scene behavior intact while allowing another renderer to compose the result with its own content. The application owns the source scene and device. The adapter owns the temporary and backend resources it creates. A preparation failure poisons that adapter, so the application must create a new adapter before preparing or drawing again (modules/…/scene-adapter.ts• L48-55, modules/…/scene-adapter.ts• L117-149).

References: modules/…/scene-adapter.ts• L48-55 modules/…/scene-adapter.ts• L117-149 modules/…/luma-backend.ts• L130-167

Camera and coordinate adaptation

Camera synchronization converts a deck.gl viewport into a Three.js camera pose and projection. It preserves the view-projection relationship and adjusts clip depth for WebGPU. For an existing Three application, the inverse helper snapshots the host camera without changing its pose or projection (modules/…/deck.ts• L46-100, modules/…/overlay.ts• L48-79). These helpers define the boundary between deck.gl's view model and Three.js's camera model.

For bounded geographic scenes, the integration can use a local meter frame around a coordinate origin. The frame supports local position, height, scale, and heading while keeping geometry near the origin for stable GPU math. It is a local Mercator approximation and does not provide globe rendering for large extents (modules/…/deck.ts• L54-66, modules/…/README.md• L785-807).

Scene placement can apply an orientation-preserving affine modelMatrix to a prepared scene without changing its source objects. The same placement must be used for camera synchronization, visible rendering, GPU picking, highlighting, and surface coordinates (modules/…/deck.ts• L67-82, modules/…/deck.ts• L280-339, modules/…/README.md• L608-645).

References: modules/…/deck.ts• L46-100 modules/…/deck.ts• L280-339 modules/…/overlay.ts• L48-79 modules/…/README.md• L608-645 modules/…/README.md• L785-807

Renderer coordination

Shared luma.gl and deck.gl passes

ThreeMeshLayer uses deck.gl's existing device, viewport, color attachment, depth attachment, and active pass. Native deck.gl layers and adapted Three.js meshes therefore participate in one depth-tested composition rather than rendering into separate images (modules/…/deck.ts• L108-187).

ThreeSceneLayer applies the same model to a prepared scene. The adapter records Three.js draws into deck.gl's pass after camera synchronization. Deck.gl remains responsible for the pass lifecycle and submission (modules/…/deck.ts• L201-242, modules/…/deck.ts• L280-342). See scene graphs for the broader scene relationship and data and visualization assets for the surrounding asset model.

References: modules/…/deck.ts• L108-187 modules/…/deck.ts• L201-242 modules/…/deck.ts• L280-342 modules/…/README.md• L485-568

Host-driven deck rendering

The existing-Three paths make the host application the owner of camera updates, input, frame scheduling, and redraws. HostDrivenDeck stops deck.gl's own scheduler and exposes a frame method. The host can then render Three.js and advance deck.gl with the same camera and timestamp (modules/…/host-driven-deck.ts• L24-49).

ThreeDeckInterleaved preserves the host's color and depth buffers. It resets Three.js state around deck.gl work and draws native deck layers into the host WebGL2 surface. ThreeDeckOverlay owns a transparent canvas and a separate WebGL2 device. It follows the host canvas size and pixel ratio while leaving pointer events with the Three.js canvas (modules/…/interleaved.ts• L128-175, modules/…/overlay.ts• L161-209). Sharing a canvas or device does not merge animation loops or schedule host frames (modules/…/README.md• L103-142).

References: modules/…/host-driven-deck.ts• L24-49 modules/…/interleaved.ts• L128-175 modules/…/overlay.ts• L161-209 modules/…/README.md• L103-142

Shared Three and deck buffers

ThreeDeckInterleaved draws native deck layers into a Three-owned WebGL2 canvas. Opaque Three objects hide deck geometry behind them. Deck geometry writes depth for later Three draws. This produces one color and depth composition while Three.js keeps its renderer, camera, controls, canvas sizing, and frame loop (modules/…/interleaved.ts• L40-49, modules/…/interleaved.ts• L132-163, modules/…/README.md• L8-55).

The support probe checks the shared-surface contract before attachment. It requires WebGL2, a depth buffer, standard depth mapping, the default framebuffer, and a full-canvas viewport. It does not change renderer state (modules/…/interleaved.ts• L18-37). The integration restores host canvas settings and leaves the host renderer, context, canvas, and device borrowed after disposal (modules/…/interleaved.ts• L50-125, modules/…/interleaved.ts• L166-175).

ThreeDeckOverlay is the separate-surface alternative. Browser alpha compositing places deck.gl above the Three.js image, but there is no shared depth, lighting, postprocessing, GPU resource sharing, or combined picking (modules/…/overlay.ts• L26-45, modules/…/overlay.ts• L82-92, modules/…/overlay.ts• L202-209). The overlay follows host canvas dimensions and pixel ratio on each host-driven frame (modules/…/overlay.ts• L166-200).

References: modules/…/interleaved.ts• L18-37 modules/…/interleaved.ts• L40-49 modules/…/interleaved.ts• L50-125 modules/…/interleaved.ts• L132-175 modules/…/overlay.ts• L26-45 modules/…/overlay.ts• L82-92 modules/…/overlay.ts• L166-209

Shared GPU buffers

ThreeBufferBridge lets upstream Three.js read luma.gl-owned vertex, index, and instance buffers on the same WebGPU device. Luma.gl compute writes the buffer, the queue is submitted, and Three.js renders the new values directly. This avoids a readback, CPU rebuild, and re-upload (modules/…/interop.ts• L26-56, modules/…/interop.ts• L100-146, modules/…/README.md• L403-443).

The bridge shares data rather than all rendering behavior. It is intended for packed floating-point vertex or instance attributes and packed uint16 or uint32 indices. The application must manage bounds and the lifetime of the geometry, bridge, renderer, buffer, and device (modules/…/interop.ts• L135-169, modules/…/README.md• L445-483). For related asset movement across systems, see data interchange formats.

References: modules/…/interop.ts• L26-56 modules/…/interop.ts• L100-169 modules/…/README.md• L403-483

GPU picking and highlighting

ThreeSceneLayer can use deck.gl's GPU picking pass for prepared scenes. Applications provide unique IDs and root objects. Rendered descendants resolve to the nearest listed root, while unlisted geometry still writes depth as an occluder. Native deck geometry and Three.js geometry therefore share selection depth (modules/…/deck.ts• L189-199, modules/…/deck.ts• L301-339, modules/…/README.md• L647-685).

Depth picking reconstructs a surface coordinate from the selected pixel. It follows supported vertex deformation, skinning, morphs, alpha coverage, local geographic origins, and scene placement. Its result has device-pixel and floating-point depth precision rather than exact CPU triangle precision (modules/…/scene-adapter.ts• L85-98, modules/…/README.md• L705-736). Highlighting changes the final display color without changing source materials or opening another pass (modules/…/scene-adapter.ts• L151-159, modules/…/README.md• L743-783).

pickThreeObject remains an independent CPU raycast helper. It can find the nearest supplied Three.js triangle. It does not account for arbitrary native deck.gl occlusion or material alpha coverage. Use GPU picking for the composed scene (modules/…/deck.ts• L344-362, modules/…/README.md• L801-804).

References: modules/…/deck.ts• L189-199 modules/…/deck.ts• L301-362 modules/…/scene-adapter.ts• L85-98 modules/…/scene-adapter.ts• L151-159 modules/…/README.md• L647-736

Rendering comparison workflow

The experimental examples render matching content through luma.gl and upstream Three.js. Shared camera state and animation time make the two views useful as a visual reference for interoperability behavior rather than as unrelated demos (modules/…/README.md• L201-228). The workflow covers simple meshes, prepared glTF scenes, animation, physical materials, deck.gl composition, geographic placement, GPU picking, and shared buffers.

The main flow moves from a caller-owned device or host renderer to a selected integration path. The result is an independent renderer, a shared pass, a shared-depth canvas, an overlay canvas, or a shared GPU buffer. The output can be compared with an upstream Three.js reference when a compatibility check is needed.

This diagram shows how Three.js content reaches the available interoperability surfaces.

flowchart LR
  A[Three scene or mesh] --> B{Integration need}
  B -->|Full scene behavior| C[LumaRenderer]
  B -->|One luma.gl pass| D[ThreeMeshAdapter]
  B -->|Prepared scene in deck.gl| E[ThreeSceneAdapter]
  B -->|Deck in existing Three app| F{Canvas path}
  F -->|Shared WebGL depth| G[ThreeDeckInterleaved]
  F -->|Separate transparent canvas| H[ThreeDeckOverlay]
  B -->|Compute data sharing| I[ThreeBufferBridge]
  C --> J[Luma.gl device and passes]
  D --> K[Caller-owned pass]
  E --> L[Deck.gl active pass]
  G --> M[Three color and depth buffers]
  H --> N[Browser compositing]
  I --> O[Upstream Three render]

References: modules/…/README.md• L201-228 modules/…/README.md• L485-570 modules/…/interleaved.ts• L18-49 modules/…/overlay.ts• L26-45

Ownership and boundaries

Resource ownership

The integration borrows devices and source Three.js objects. The caller creates and destroys the device. It keeps source scenes, meshes, materials, host canvases, and shared buffers alive until all consumers finish. Adapters and bridges release only the resources they create (modules/…/README.md• L26-32, modules/…/README.md• L188-203, modules/…/interop.ts• L157-169).

Pass-embedded rendering also leaves lifecycle control with the caller. The caller must prepare or synchronize content before drawing and submit work before reusing per-draw state. It must not change the same adapter's camera data before its recorded work is submitted (modules/…/README.md• L206-214, modules/…/scene-adapter.ts• L117-149). Detaching an overlay or interleaved integration does not dispose the host renderer, canvas, context, or device (modules/…/interleaved.ts• L166-175, modules/…/overlay.ts• L202-209).

References: modules/…/README.md• L26-32 modules/…/README.md• L188-214 modules/…/interop.ts• L157-169 modules/…/interleaved.ts• L166-175 modules/…/overlay.ts• L202-209

Compatibility limits

The integration supports selected rendering workflows rather than every Three.js feature. The broad renderer path covers the tested scene, material, texture, animation, shadow, and compute subset. The mesh, deck.gl, shared-depth, and overlay paths are smaller by design. Unsupported material state, backend hooks, pass formats, coordinate modes, or host surfaces fail instead of silently producing an unrelated result (modules/…/luma-backend.ts• L88-100, modules/…/deck.ts• L120-145, modules/…/interleaved.ts• L18-37, modules/…/overlay.ts• L26-45).

The package is pinned to Three.js 0.185.1, deck.gl 9.4.0, and luma.gl 10 in the tested workspace. WebGL2 compute, shared-depth render targets, XR, globe projection, combined overlay picking, and several advanced Three.js features remain outside the prototype (modules/…/package.json• L49-60, modules/…/README.md• L297-302, modules/…/README.md• L521-533).

References: modules/…/luma-backend.ts• L88-100 modules/…/deck.ts• L120-145 modules/…/interleaved.ts• L18-37 modules/…/overlay.ts• L26-45 modules/…/package.json• L49-60 modules/…/README.md• L297-302

Change checklist

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

  • Keep renderer-backed and pass-embedded support separate when changing materials or scene features. Support in LumaRenderer does not make a feature valid for ThreeMeshAdapter or ThreeMeshLayer.
  • Keep camera synchronization aligned between Cartesian views and local-meter geographic views. The coordinate origin and optional modelMatrix must stay consistent across viewport conversion, scene preparation, drawing, picking, and surface reconstruction.
  • Keep host-driven scheduling aligned between HostDrivenDeck, ThreeDeckInterleaved, and ThreeDeckOverlay. A host integration must not install a second frame loop or claim host input.
  • Keep shared-depth support checks aligned with Three.js framebuffer, depth mapping, viewport, and GL cache state. A change to color, depth, or sample support can break composition before any draw occurs.
  • Keep shared-buffer lifetime order intact. Three.js geometries must release borrowed attributes before the bridge. The luma.gl buffer must remain alive until both renderers finish.
  • Keep upstream Three.js version changes paired with parity checks. The buffer bridge and renderer backend depend on upstream renderer contracts.

Important failure modes

TriggerConsequenceGuard
A pass-embedded adapter draws before synchronization or preparationThe adapter rejects the draw or uses stale camera and resource stateSynchronize a mesh or prepare a scene before recording its draw
A prepared scene fails during preparation and the same adapter is reusedLater preparation and drawing are rejected because Three.js render state may be incompleteDispose the failed adapter and create a new one
A Three.js scene uses unsupported material or backend stateTranslation throws instead of producing compatible GPU stateUse the renderer-backed path only for features in its tested subset
An interleaved host uses a different framebuffer, nonstandard depth mapping, scissor view, or missing depth attachmentThe Three.js and deck.gl images cannot share color and depth safelyRun the support probe and use a full default WebGL2 framebuffer
An overlay host canvas is not a direct child of a positioned containerThe transparent deck.gl canvas cannot align with the Three.js canvasSatisfy the overlay attachment contract before creation
A deck.gl layer uses a different device, multisample target, or missing depth attachmentThe Three.js content cannot join deck.gl's active passShare deck.gl's device and use a compatible single-sample color/depth pass
Luma.gl compute is not submitted before Three.js renders a shared bufferThree.js reads data before the compute result is ordered on the queueEnd and submit luma.gl work before the Three.js render
A borrowed geometry or buffer is disposed in the wrong orderThe bridge sees a live Three.js cache with a released GPU resourceDispose geometries, then the bridge, then shared buffers and the device
Geographic Three.js content uses a globe view or an inconsistent originCamera placement and object placement do not describe the same local frameUse a bounded Mercator view and pass one coordinate origin through both paths

Key files

FileWhy to read it
modules/…/README.mdGives the supported integration paths, workflow examples, ownership rules, picking behavior, and experimental limits.
modules/…/luma-renderer.tsShows the renderer entry point and the borrowed-device boundary.
modules/…/luma-backend.tsExplains how Three.js rendering and compute work reaches luma.gl resources and passes.
modules/…/translate.tsShows the high-level mapping from Three.js bindings, vertex data, and material state to luma.gl descriptions.
modules/…/objects.tsDefines the simple mesh adapter and prepared scene adapter used for mixed luma.gl and Three.js passes.
modules/…/scene-adapter.tsDefines preparation, caller-pass drawing, GPU picking, depth picking, and highlighting for Three.js scenes.
modules/…/deck.tsConnects Three.js cameras, meshes, and scenes to deck.gl viewports, layers, passes, geographic frames, placement, and picking.
modules/…/host-driven-deck.tsDefines host-owned frame scheduling for existing Three.js applications.
modules/…/interleaved.tsDefines the shared-depth deck.gl path inside a Three.js WebGL2 canvas and its support contract.
modules/…/overlay.tsDefines separate transparent-canvas deck.gl rendering above an existing Three.js application.
modules/…/interop.tsDefines shared GPU-buffer use between luma.gl compute and upstream Three.js rendering.
modules/…/deck-picking-renderer.spec.tsVerifies shared depth, root-level IDs, surface coordinates, placement, and highlighting.
modules/…/geographic-renderer.spec.tsVerifies local-meter geographic rendering and selection against upstream Three.js.
modules/…/interleaved-renderer.spec.tsVerifies shared WebGL color/depth composition, support rejection, host preservation, and recreation.
modules/…/overlay-renderer.spec.tsVerifies host-driven overlay composition, resize, timing, and detach behavior.
modules/…/interop-renderer.spec.tsVerifies direct shared vertex, index, and instance buffers without geometry uploads.