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 / engine-render-loop

Render engine and frame execution

The engine package is the high-level scene runtime over the common device, resource, shader, and pass APIs. It turns application state and data sources into timed render or compute work, then adds the services that make a scene interactive: animation, camera control, picking, audio, asset loading, text, effects, lighting, physics, and dynamic resources. See the rendering runtime and platforms page for the platform model, the core API page for shared device contracts, the scene graph page for scene structure, the glTF rendering features page for asset behavior, the lighting page for lighting behavior, and the GPU physics page for the lower-level physics graph.

Engine role

The engine connects product-level scene features to common runtime APIs. A caller can describe models, materials, scene structure, data-backed renderers, asset content, lighting, physics, or post-processing work without managing each device resource and frame boundary alone. The public engine surface groups these capabilities through the engine entry points, including Arrow, effects, glTF, lighting, splats, and text. (modules/…/index.ts• L5-45, modules/…/index.ts• L47-131, modules/…/index.ts• L142-206, modules/…/index.ts• L213-350, modules/…/index.ts• L5-247, modules/…/index.ts• L5-210, modules/…/index.ts• L15-191, modules/…/index.ts• L5-125)

The main capability groups are:

  • Frame timing, redraw control, submission, measurement, and shutdown.
  • Models, scene graphs, materials, geometry, dynamic resources, and shader passes.
  • Physically based materials, environments, shadows, light maps, reflection probes, clustered lights, and screen-space visibility.
  • Data-backed renderers for columnar paths, polygons, text, and splats.
  • glTF scene creation with animation, materials, lights, audio, skinning, morph targets, instancing, and GPU crowd animation.
  • Compute work, buffer and texture transforms, animation, camera input, interaction, picking, audio, and scene physics.

References: modules/…/index.ts• L5-45 modules/…/index.ts• L142-206 modules/…/index.ts• L213-350 modules/…/index.ts• L101-247 modules/…/index.ts• L15-191 modules/…/index.ts• L5-125 modules/…/physics-controller.ts• L22-72

Frame execution

AnimationLoop is the main coordinator for repeated rendering. It gives application callbacks one frame context and keeps device setup, resource initialization, frame work, optional display work, submission, error handling, and cleanup within one lifecycle. makeAnimationLoop provides the same lifecycle for applications that want resource ownership tied to the loop.

Frame lifecycle

The loop initializes the device and application resources once. It then updates frame state, calls application render code, submits encoded work when needed, and schedules the next frame until the application stops it. This diagram shows the relationship between the host frame source and device work.

flowchart LR
    A[Device and canvas] --> B[Initialize loop]
    B --> C[Create frame state]
    C --> D[Request frame]
    D --> E[Update size and time]
    E --> F[Update timeline and input]
    F --> G[Encode render or compute work]
    G --> H[Submit device work]
    H --> D
    H --> I[Finalize and release]

Initialization may wait for application resources. A render callback may return false when it encoded no work. A frame error is reported and stops the loop. The template form keeps asynchronous setup and cleanup at the same start and stop boundaries. (modules/…/animation-loop.ts• L200-241, modules/…/animation-loop.ts• L243-289, modules/…/animation-loop.ts• L373-404, modules/…/animation-loop-template.ts• L7-28, modules/…/make-animation-loop.ts• L54-87)

References: modules/…/animation-loop.ts• L200-241 modules/…/animation-loop.ts• L243-289 modules/…/animation-loop.ts• L373-404 modules/…/animation-loop-template.ts• L7-28 modules/…/make-animation-loop.ts• L54-87

Frame state and timing

AnimationProps is the shared frame context for initialization and rendering. It combines the active device and canvas with drawing size, aspect ratio, engine time, logical time, frame count, redraw state, optional timeline data, host frame data, and quality settings. Resize and aspect changes mark the loop for redraw, while callers can wait for the next completed render.

The loop accepts the browser frame source or a custom AnimationFrameProvider. A provider can attach host data to the callback, which the frame context exposes as animationFrame. The loop also records frame rate and CPU time, and can include GPU timing when the device enables it. (modules/…/animation-props.ts• L9-38, modules/…/animation-loop.ts• L167-195, modules/…/animation-loop.ts• L303-312, modules/…/animation-loop.ts• L354-385, modules/…/animation-loop.ts• L463-498, modules/…/request-animation-frame.ts• L7-45)

References: modules/…/animation-props.ts• L9-38 modules/…/animation-loop.ts• L167-195 modules/…/animation-loop.ts• L303-312 modules/…/animation-loop.ts• L354-385 modules/…/animation-loop.ts• L463-498 modules/…/request-animation-frame.ts• L7-45

Scene and render work

The engine separates scene meaning from device commands. Models combine geometry, shader inputs, bindings, materials, and pipeline state. Scene graphs organize those models and their transforms. Render passes and compute units turn prepared state into ordered work for the common runtime.

Models and scene graphs

Model is the main reusable draw unit. It adapts geometry into GPU data and joins it with material-owned bindings and shader state. Its preparation stage updates resources and pipeline state before its draw stage records work in a render pass. GPUVectorModel provides the data-column form used by batched and data-driven renderers. It accepts typed vectors or constants, derives or honors their buffer layouts, and can resolve dynamic buffers as data changes.

Scene graph nodes add hierarchy, transforms, visibility, and traversal order. A model node connects a leaf in that hierarchy to a draw unit. The graph decides which scene items are active and in what order, while the model and pass decide how those items reach the device. Vector batches preserve aligned geometry and attribute rows across multiple draws, including independent instance batches, without changing the caller's source data. A model can also draw a supplied set of aligned chunks as one scoped operation, with per-batch shader values kept separate until submission. (modules/…/model.ts• L19-25, modules/…/model.ts• L38-142, modules/…/gpu-vector-model.ts• L180-194, modules/…/gpu-vector-model.ts• L619-785, modules/…/gpu-vector-model.ts• L795-864, modules/…/gpu-vector-model.ts• L1075-1155, modules/…/gpu-vector-bindings.ts• L26-135, modules/…/gpu-vector-draw-batches.ts• L8-105, modules/…/gpu-vector-model-batches.ts• L13-139, modules/…/batch-uniform-buffer.ts• L7-43, modules/…/scenegraph-node.ts• L14-58, modules/…/group-node.ts• L97-153, modules/…/model-node.ts• L25-69)

References: modules/…/model.ts• L19-25 modules/…/model.ts• L38-142 modules/…/gpu-vector-model.ts• L180-194 modules/…/gpu-vector-model.ts• L619-785 modules/…/gpu-vector-model.ts• L795-864 modules/…/gpu-vector-model.ts• L1075-1155 modules/…/gpu-vector-bindings.ts• L26-135 modules/…/gpu-vector-draw-batches.ts• L8-105 modules/…/gpu-vector-model-batches.ts• L13-139 modules/…/batch-uniform-buffer.ts• L7-43 modules/…/scenegraph-node.ts• L14-58 modules/…/group-node.ts• L97-153 modules/…/model-node.ts• L25-69

Materials and dynamic resources

Material owns the shader inputs and resource bindings that describe a reusable surface. It can resolve deferred texture sources, dynamic buffers, and buffer ranges into the bindings needed by a model. Uniform changes keep the material identity, while structural resource changes create a new material variant.

This model lets stable geometry and changing content use one render contract. A video, streamed image, or changing buffer can become ready later without forcing application code to replace the whole draw object. (modules/…/material.ts• L37-60, modules/…/material.ts• L78-133, modules/…/material.ts• L173-250, modules/…/dynamic-texture.ts• L5-9, modules/…/dynamic-buffer.ts• L5-19)

References: modules/…/material.ts• L37-60 modules/…/material.ts• L78-133 modules/…/material.ts• L173-250 modules/…/dynamic-texture.ts• L5-9 modules/…/dynamic-buffer.ts• L5-19

Physically based lighting

The lighting runtime turns scene materials, light sources, and environment data into reusable physically based rendering work. Physically based rendering (PBR) is the shared surface model for material response. The engine can add direct-light shadows, contact visibility, ambient occlusion, image-based lighting, light-map output, and reflection capture without creating a separate scene or frame system. (modules/…/pbr-material.ts• L11-26, modules/…/pbr-model.ts• L439-452, modules/…/index.ts• L16-125)

Lighting follows the same preparation and recording boundary as other engine work. The surface pass first produces camera depth and encoded normals. Shadow and visibility passes consume those camera inputs, while the PBR model consumes their results when it shades visible geometry. A clustered light grid can organize point lights for WebGPU consumers, and a light-map baker can accumulate UV-space irradiance for later material use. (modules/…/pbr-surface-pass.ts• L6-18, modules/…/pbr-surface-pass.ts• L26-82, modules/…/shadow-map-renderer.ts• L59-82, modules/…/ambient-occlusion-pass.ts• L12-30, modules/…/contact-shadow-pass.ts• L15-26, modules/…/clustered-light-grid.ts• L40-79, modules/…/lightmap-baker.ts• L15-33)

This diagram shows how lighting resources and intermediate visibility data join the ordinary model draw.

flowchart LR
    A[Scene lights and camera] --> B[Shadow maps]
    C[Scene surfaces] --> D[Depth and normal targets]
    D --> E[Ambient and contact visibility]
    A --> F[Clustered light lists]
    G[Environment textures] --> H[PBR material and model]
    B --> H
    E --> H
    F --> H
    H --> I[Lit scene]
    J[UV-space samples] --> K[Light map]
    K --> H

Environment data enters through either loaded PBR textures or a prefilter step that creates diffuse irradiance, specular reflection, and BRDF lookup resources. These resources remain compatible with the common material bindings, so glTF assets and hand-built models can use the same environment contract. (modules/…/pbr-environment.ts• L7-55, modules/…/prefiltered-environment.ts• L22-50, modules/…/prefiltered-environment.ts• L74-86, modules/…/pbr-environment.ts• L18-37, modules/…/pbr-environment.ts• L138-155)

Quality settings provide one shared choice for shadow-map size, cascade count, sampling effort, contact resolution, and contact tracing. The lighting exports expose these pieces as separate resources so an application can choose which stages it needs while keeping the data contracts between stages explicit. (modules/…/shadow-quality.ts• L5-18, modules/…/shadow-map-renderer.ts• L125-167, modules/…/contact-shadow-composite.ts• L13-24, modules/…/index.ts• L36-125)

The light-map atlas helper prepares a CPU-side chart layout from scene geometry. It assigns padded UV rectangles and ownership data for the light-map baker, then provides checks and debug data before GPU work begins. A reflection probe captures six views around a point and filters them into a publishable cube environment. It can spread face work across frames or keep capture and filtering in the current frame, with the active result kept separate until a refresh completes. (modules/…/lightmap-atlas.ts• L8-39, modules/…/lightmap-atlas.ts• L43-50, modules/…/lightmap-atlas.ts• L257-347, modules/…/reflection-probe.ts• L26-60, modules/…/reflection-probe.ts• L62-63, modules/…/reflection-probe.ts• L147-245)

References: modules/…/index.ts• L16-125 modules/…/pbr-environment.ts• L7-55 modules/…/pbr-material.ts• L11-84 modules/…/pbr-model.ts• L439-607 modules/…/pbr-surface-pass.ts• L6-122 modules/…/shadow-map-renderer.ts• L125-279 modules/…/shadow-quality.ts• L5-50 modules/…/ambient-occlusion-pass.ts• L12-129 modules/…/contact-shadow-composite.ts• L13-67 modules/…/contact-shadow-pass.ts• L15-107 modules/…/clustered-light-grid.ts• L21-79 modules/…/clustered-light-grid.ts• L177-270 modules/…/lightmap-baker.ts• L15-33 modules/…/lightmap-baker.ts• L52-233 modules/…/lightmap-atlas.ts• L8-39 modules/…/lightmap-atlas.ts• L43-50 modules/…/lightmap-atlas.ts• L257-347 modules/…/reflection-probe.ts• L26-63 modules/…/reflection-probe.ts• L147-245 modules/…/prefiltered-environment.ts• L22-86 modules/…/pbr-environment.ts• L18-37 modules/…/pbr-environment.ts• L138-155

Geometry and data-driven renderers

Geometry supplies the shared vertex and index shape expected by models. The engine includes common solid and surface primitives, plus a ring shape that supports a partial sweep and end caps. Applications can add attributes when a renderer needs more data.

Columnar data uses the same model path through GPU vector data. The Arrow renderers map path, polygon, text, and splat records into render-ready batches and provide matching picking and source-mapping helpers. GPU vector bindings can keep columns in borrowed source buffers, pack constants for the active backend, and draw aligned chunks with vertex or instance counts. This keeps large data sets in a data-oriented path instead of requiring one scene object per record. (modules/…/geometry-primitives.ts• L23-40, modules/…/geometry-primitives.ts• L68-176, modules/…/ring-geometry.ts• L13-49, modules/…/index.ts• L5-19, modules/…/index.ts• L101-203, modules/…/gpu-vector-bindings.ts• L51-207, modules/…/gpu-vector-draw-batches.ts• L8-105)

References: modules/…/geometry-primitives.ts• L23-40 modules/…/geometry-primitives.ts• L68-176 modules/…/ring-geometry.ts• L13-49 modules/…/index.ts• L5-19 modules/…/index.ts• L101-203 modules/…/gpu-vector-bindings.ts• L51-207 modules/…/gpu-vector-draw-batches.ts• L8-105

Render passes and effects

ShaderPassRenderer applies an ordered chain of image operations to a source texture. It owns the intermediate targets and the previous result chain, then presents the final texture to the screen or returns it for later work. Composite passes can also keep history for effects that use earlier frames.

The engine effects surface provides image adjustment, blur, warp, fun, anti-aliasing, lighting, fog, reflection, ambient-occlusion, and temporal pass modules. The effect modules describe image work; the renderer provides the shared sequencing, target, resize, and presentation behavior. (modules/…/shader-pass-renderer.ts• L49-88, modules/…/shader-pass-renderer.ts• L96-182, modules/…/shader-pass-renderer.ts• L185-220, modules/…/index.ts• L5-42, modules/…/index.ts• L44-82, modules/…/index.ts• L130-210)

References: modules/…/shader-pass-renderer.ts• L49-88 modules/…/shader-pass-renderer.ts• L96-182 modules/…/shader-pass-renderer.ts• L185-220 modules/…/index.ts• L5-42 modules/…/index.ts• L130-210

Compute and transforms

Computation is the engine's shader-aware compute unit. It assembles compute shader inputs, prepares a pipeline, updates uniforms, and dispatches direct or indirect work through a compute pass. It is a WebGPU-only capability. Its asynchronous factory can prepare several pipelines together, while predraw lets callers order uniform uploads before the compute pass consumes them. This separates shader-input updates from dispatch so one command encoder can preserve the required order.

BufferTransform and TextureTransform cover data conversion paths that use render work as a transform. Buffer transforms write shader results to buffer ranges on WebGL2. Texture transforms use a GPUVectorModel to render into a target texture and submit that work. These helpers sit beside the general compute path because their support and output contracts differ by backend. (modules/…/computation.ts• L81-109, modules/…/computation.ts• L167-274, modules/…/computation.ts• L284-326, modules/…/computation.ts• L380-387, modules/…/buffer-transform.ts• L22-47, modules/…/buffer-transform.ts• L63-133, modules/…/texture-transform.ts• L43-47, modules/…/texture-transform.ts• L57-112)

References: modules/…/computation.ts• L81-109 modules/…/computation.ts• L167-274 modules/…/computation.ts• L284-326 modules/…/computation.ts• L380-387 modules/…/buffer-transform.ts• L22-47 modules/…/buffer-transform.ts• L63-133 modules/…/texture-transform.ts• L43-47 modules/…/texture-transform.ts• L57-112

Asset and media pipelines

The engine includes runtime-facing adapters for common scene and media inputs. These adapters turn external data into the same scene graph, model, material, animation, resource, and picking contracts used by hand-built scenes.

glTF runtime

The glTF runtime parses a glTF document into scene graphs, models, PBR materials, textures, lights, audio, cameras, skinning, morph targets, instancing, and animation clips. It also reports extension support and can select imported clips or build animated crowds. Loaded image-based lighting environments become dynamic resources that resolve into the same PBR environment contract as generated environments. This makes glTF an asset input to the engine rather than a separate render path. (modules/…/index.ts• L15-78, modules/…/index.ts• L96-123, modules/…/index.ts• L122-191, modules/…/create-gltf-model.ts• L574-887, modules/…/parse-gltf.ts• L96-284)

Parsing first creates materials aligned with the source material list. It then builds mesh and node maps, attaches the hierarchy, and creates independent primitive models when a node needs its own skin, morph state, light-map binding, or instance data. The parser keeps generated texture ownership with the returned asset while borrowed environment resources remain outside that ownership. (modules/…/parse-gltf.ts• L119-171, modules/…/parse-gltf.ts• L173-285, modules/…/parse-gltf.ts• L287-299)

PBR parsing converts material features into one portable description of shader defines, bindings, uniforms, pipeline parameters, and generated textures. It validates the UV sets needed by texture features, supports the supported glTF material extensions, and can use either a legacy PBR environment or a linear-light scene environment with intensity, rotation, and mip data. Texture upload supports ordinary and validated compressed mip chains, with a fallback texture when the source cannot be used. (modules/…/parse-pbr-material.ts• L239-372, modules/…/parse-pbr-material.ts• L375-403, modules/…/parse-pbr-material.ts• L627-750, modules/…/parse-pbr-material.ts• L1210-1323, modules/…/parse-pbr-material.ts• L1402-1507, modules/…/pbr-material.ts• L14-37)

The generated glTF model keeps material-owned bindings separate from scene-owned shader inputs. It can publish rigid-body transforms on WebGPU and can carry per-instance transforms, skin palettes, morph targets, or GPU crowd animation through managed resources. This lets a shared glTF primitive serve ordinary nodes and large animated groups without changing the scene-graph contract. (modules/…/create-gltf-model.ts• L486-544, modules/…/create-gltf-model.ts• L586-755, modules/…/create-gltf-model.ts• L769-887, modules/…/create-gltf-model.ts• L926-960)

References: modules/…/index.ts• L15-78 modules/…/index.ts• L96-123 modules/…/index.ts• L122-191 modules/…/create-gltf-model.ts• L486-544 modules/…/create-gltf-model.ts• L574-887 modules/…/parse-gltf.ts• L96-299 modules/…/parse-gltf.ts• L320-548 modules/…/parse-pbr-material.ts• L239-372 modules/…/parse-pbr-material.ts• L627-750 modules/…/parse-pbr-material.ts• L1210-1323 modules/…/parse-pbr-material.ts• L1402-1507 modules/…/pbr-material.ts• L14-37

Text rendering

The text runtime turns font data and text inputs into GPU-ready glyph data and model state. Its 2D path supports atlas-backed text, dictionary or storage forms, and data-driven text preparation. It therefore uses the same geometry, model, dynamic resource, and picking contracts as other engine content. (modules/…/index.ts• L1-5, modules/…/index.ts• L1-120, modules/…/index.ts• L1-80)

References: modules/…/index.ts• L1-5 modules/…/index.ts• L1-120 modules/…/index.ts• L1-80

Gaussian splat rendering

The splat runtime represents Gaussian splat data, prepares it from direct or glTF sources, manages visibility and residency, sorts it for view-dependent drawing, and exposes picking. It supports both ordinary and paged or hierarchical renderers, so large splat scenes can load and refine data around the current view. (modules/…/index.ts• L5-57, modules/…/index.ts• L58-126)

The glTF bridge keeps splat data attached to source mesh primitives while scene traversal resolves visible nodes, inherited transforms, and GPU-instanced matrices. Decoded Arrow batches remain borrowed and independently owned by the caller, so the same prepared primitive data can serve multiple scene instances without baking node transforms into the data. Unsupported decoded primitive settings and invalid feature-ID columns are rejected before the prepared groups are returned. (modules/…/make-gpu-splat-data-from-gltf.ts• L23-42, modules/…/make-gpu-splat-data-from-gltf.ts• L47-163, modules/…/make-gpu-splat-data-from-gltf.ts• L165-224, modules/…/README.md• L45-85)

This path leaves mixed-scene ordering, node visibility, transforms, and renderer ownership with the host. The host applies each reported world transform when it draws the borrowed batches and destroys the renderer before the batches it borrows. (modules/…/README.md• L6-19, modules/…/README.md• L27-40, modules/…/README.md• L66-82)

References: modules/…/index.ts• L5-57 modules/…/index.ts• L58-136 modules/…/make-gpu-splat-data-from-gltf.ts• L23-42 modules/…/make-gpu-splat-data-from-gltf.ts• L47-163 modules/…/make-gpu-splat-data-from-gltf.ts• L165-224 modules/…/README.md• L6-40 modules/…/README.md• L45-85

Animation and interaction

Animation and interaction update scene state that the next frame consumes. They do not replace the frame loop or render passes. Instead, they provide time, input, selection, audio, physics, and host-physics state before application code records the frame.

Timeline and scene animation

Timeline is the shared clock for engine animations. Channels apply their own delay, duration, rate, and repeat rules. Clips and mixers use that clock to update target values, while ScenegraphAnimator selects imported scene clips and can cross-fade between them before a scene update callback runs. (modules/…/timeline.ts• L12-35, modules/…/timeline.ts• L41-165, modules/…/scenegraph-animator.ts• L9-17, modules/…/scenegraph-animator.ts• L39-100)

References: modules/…/timeline.ts• L12-35 modules/…/timeline.ts• L41-165 modules/…/scenegraph-animator.ts• L9-17 modules/…/scenegraph-animator.ts• L39-100

Camera and graph interaction

OrbitControls maps pointer, wheel, and touch input to camera orbit, pan, zoom, and optional auto-rotation state. Interactivity and the scene controllers expose a higher-level route from input or behavior data to scene properties. Application frame code reads the resulting camera and scene state when it prepares draws.

Physics is represented as a host contract for impulses, ray tests, triggers, and vector or hit results. The contract keeps scene behavior independent of a particular physics engine or GPU backend. (modules/…/orbit-controls.ts• L5-65, modules/…/orbit-controls.ts• L66-135, modules/…/orbit-controls.ts• L161-218, modules/…/interactivity.ts• L1-80, modules/…/physics.ts• L5-19)

References: modules/…/orbit-controls.ts• L5-65 modules/…/orbit-controls.ts• L66-135 modules/…/orbit-controls.ts• L161-218 modules/…/interactivity.ts• L1-80 modules/…/physics.ts• L5-19

Physics scene integration

PhysicsController binds scene-graph nodes to a GPU rigid-body world. It resolves bodies and joints from nodes or scene paths, prepares the world asynchronously, and then advances bounded fixed-time steps during frame work. Its transform source publishes the current GPU poses to renderers, so physics can move scene content without a CPU readback on every frame. (modules/…/physics-controller.ts• L22-109, modules/…/physics-controller.ts• L137-191, modules/…/physics-controller.ts• L260-347)

The controller separates setup edits from frame updates. Body, joint, vehicle, geometry, or topology changes mark the world for preparation or rebuild. A rebuild can preserve dynamic poses and velocities, while reset restores authored state. Explicit pose reads, captures, and restores are asynchronous inspection or edit operations rather than part of the normal frame path. (modules/…/physics-controller.ts• L199-257, modules/…/physics-controller.ts• L349-401, modules/…/scenegraph-instance.ts• L74-121, modules/…/scenegraph-instance.ts• L158-255)

ScenegraphPhysicsInstance makes replacement transactional. It compiles a new command graph, publishes its poses, waits for prior GPU work, and only then swaps the live execution. A revision identifies the active borrowed render buffers and event identities, which prevents consumers from using resources from an older world. (modules/…/scenegraph-instance.ts• L32-63, modules/…/scenegraph-instance.ts• L124-155, modules/…/scenegraph-instance.ts• L257-291)

This diagram shows the normal relationship between scene setup, fixed-step simulation, and rendering.

flowchart LR
    A[Scene nodes and body definitions] --> B[Prepare or rebuild physics world]
    B --> C[Published transform source]
    C --> D[Render scene]
    E[Frame delta] --> F[Bounded fixed steps]
    F --> G[GPU physics commands]
    G --> C
    H[Explicit pose read or capture] --> I[Async inspection]

References: modules/…/physics-controller.ts• L74-109 modules/…/physics-controller.ts• L260-347 modules/…/physics-controller.ts• L349-401 modules/…/scenegraph-instance.ts• L32-63 modules/…/scenegraph-instance.ts• L124-172 modules/…/scenegraph-instance.ts• L175-291

Picking and audio

Picking renders scene identity into a device-supported target and reads the result back as an object and batch index. The manager chooses index picking when the device supports it or color picking otherwise, then updates highlight and tooltip state only when the cursor needs a new pick.

Audio uses graph, controller, source, and environment concepts to connect scene content to sound playback. glTF audio definitions can enter this system through the asset runtime, while application interaction can control the same audio state. (modules/…/picking-manager.ts• L16-75, modules/…/picking-manager.ts• L100-137, modules/…/picking-manager.ts• L161-227, modules/…/audio-graph.ts• L1-80, modules/…/audio-controller.ts• L1-120, modules/…/index.ts• L113-119)

References: modules/…/picking-manager.ts• L16-75 modules/…/picking-manager.ts• L100-137 modules/…/picking-manager.ts• L161-227 modules/…/audio-graph.ts• L1-80 modules/…/audio-controller.ts• L1-120 modules/…/index.ts• L113-119

Backend boundaries

The engine keeps one application-facing model while allowing the active device to choose shader language, limits, resource formats, and supported work. getPlatformInfo supplies the device facts needed by shader and pipeline preparation. Backend-specific limits remain visible where a capability cannot be portable, such as WebGPU computation, WebGL2 buffer transforms, clustered light grids, reflection probes, published physics transforms, and index-picking formats. (modules/…/get-platform-info.ts• L8-18, modules/…/computation.ts• L167-192, modules/…/buffer-transform.ts• L63-70, modules/…/clustered-light-grid.ts• L99-115, modules/…/reflection-probe.ts• L93-114, modules/…/picking-manager.ts• L52-75, modules/…/create-gltf-model.ts• L574-587)

This boundary is also why model preparation and command recording are separate. High-level objects prepare resources against the active device, then render or compute passes record commands through common runtime interfaces. A WebGPU model also tracks the color and depth formats of its current render target, so a pass change can trigger the needed pipeline update. The WebGL and WebGPU backend pages describe the final device behavior. (modules/…/gpu-vector-model.ts• L415-419, modules/…/gpu-vector-model.ts• L685-704, modules/…/gpu-vector-model.ts• L1710-1747)

References: modules/…/get-platform-info.ts• L8-18 modules/…/computation.ts• L167-192 modules/…/buffer-transform.ts• L63-70 modules/…/clustered-light-grid.ts• L99-115 modules/…/reflection-probe.ts• L93-114 modules/…/picking-manager.ts• L52-75 modules/…/create-gltf-model.ts• L574-587 modules/…/gpu-vector-model.ts• L415-419 modules/…/gpu-vector-model.ts• L685-704 modules/…/gpu-vector-model.ts• L1710-1747

Change checklist

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

  • Keep AnimationProps, raw loop callbacks, template callbacks, custom frame providers, and redraw completion behavior aligned.
  • Preserve the no-work result and submission order when changing frame callbacks or pass presentation.
  • Keep model, material, dynamic-resource, shader-layout, attachment-format, and render-pass contracts aligned across WebGL and WebGPU.
  • Preserve vector layout inference, constant packing, source-buffer offsets, row alignment, and draw counts when changing GPU vector models.
  • Preserve batch selection and state restoration when changing aligned or independently instanced vector draws.
  • Reserve aligned per-batch uniform storage before drawing and submit work before reusing those slots or growing the allocation.
  • Preserve GPU vector row alignment and draw counts when changing Arrow, text, polygon, path, or splat data preparation.
  • Keep moved package exports and import paths aligned with the engine entry points. Do not leave consumers on deleted source-package paths.
  • Preserve glTF material-list alignment, generated-texture ownership, scene-node maps, independent skin or morph state, and instancing data as one asset flow.
  • Keep glTF material defines, texture-coordinate checks, compressed mip validation, PBR bindings, and pipeline parameters aligned with the shader module.
  • Keep PBR material bindings, environment texture conventions, shadow outputs, surface depth and normal targets, and lighting feature defines aligned.
  • Keep shadow quality settings consistent across shadow maps, contact shadows, and their composite passes.
  • Keep clustered-light capacity, point-light record layout, camera depth range, and consumer shader uniforms aligned.
  • Keep light-map chart coverage, padded UVs, chart ownership, irradiance accumulation, and result ownership aligned.
  • Keep reflection probe face order, capture matrices, filtering targets, frame budget, and publication state aligned.
  • Keep shader-pass names such as original and previous distinct from writable targets. Reset temporal history after resize or invalidation.
  • Preserve picking mode support, device-pixel coordinate conversion, encoded index limits, and batch/object result shapes.
  • Keep animation clock units distinct between engine time, timeline channels, clip actions, and scene update callbacks.
  • Keep physics node bindings, body indices, fixed timestep units, substep limits, published transform revisions, and rebuild state preservation aligned.
  • Do not expose physics publication buffers while a reset, rebuild, or destruction is pending. Retire old GPU worlds only after their work completes.
  • Preserve compute pipeline preparation and uniform upload ordering when using asynchronous computation or a command encoder.
  • Preserve the backend limits for WebGPU computation, WebGL2 buffer transforms, reflection probes, published glTF transforms, and index picking.
  • Preserve splat mesh/primitive identity, Arrow batch boundaries, source row offsets, instance transforms, and borrowed-data ownership across glTF preparation.

Important failure modes

TriggerConsequenceGuard
Render work throwsThe current frame reports an error and the loop stops.Provide onError and release the loop after handling the failure.
Initialization failsNo frame runs and the loop start rejects.Treat asynchronous initialization as the resource readiness boundary.
A custom frame provider does not cancel a scheduled callbackA stopped or replaced loop can receive stale frame work.Use the provider cancellation path when stopping or replacing the provider.
A model or material resource is not readyThe draw cannot produce a complete frame.Wait for readiness and keep redraw requested until the resource resolves.
Model state changes after preparationThe draw can use stale bindings or pipeline state.Prepare changing state through the frame encoder before opening the pass.
A pipeline does not match the active target formatsPipeline creation or drawing can fail.Let the model synchronize attachment formats with the current render pass before drawing.
GPU vector batches have incompatible lengths, layouts, or offsetsOne data-driven draw cannot bind the batch set coherently.Validate aligned vectors and explicit packed layouts before drawing.
A vector batch is selected without restoring prior bindings and countsLater draws can use the wrong buffers or draw range.Use the batch helper's restore boundary around transient batch state.
Per-batch managed uniform slots are changed before prior work is submittedEarlier batches can read the later batch's uniform values.Submit the current work before changing values or reusing the batch allocation.
A shader pass reads its write targetThe pass is rejected or produces invalid feedback.Read from previous or a separate target.
Temporal history is used after resize or resetEffects use invalid previous-frame data.Reset or reinitialize history before temporal work.
A computation runs on a non-WebGPU deviceConstruction fails because the capability is unavailable.Select computation only after checking the device type.
Asynchronous computation pipeline creation failsThe computation is destroyed and creation rejects.Handle the async creation error before adding the computation to frame work.
A WebGL buffer transform runs outside WebGL2Construction fails because transform feedback is unavailable.Check support before selecting BufferTransform.
Picking requests unsupported index modeMode resolution fails instead of producing pick data.Use auto or confirm the device supports the required format.
An unknown scene animation clip is selectedSelection fails and the active clip stays unchanged.Select only names supplied by the imported scene clip set.
A required glTF extension is unsupportedAsset loading cannot produce the required scene content.Check the extension support summary before loading.
A glTF material needs an unavailable UV set or has invalid compressed mip dataA texture feature is skipped or texture creation falls back.Validate primitive attributes and provide contiguous, supported mip levels.
A glTF crowd combines nested instancing or exceeds its chosen skin or animation contractModel creation rejects the setup or produces an invalid instance draw.Use one supported instancing path and keep capacity, palette, and animation layouts aligned.
Splat residency or hierarchy data is stale for the viewVisible splats can be missing or incorrectly refined.Update view-dependent residency and hierarchy state before drawing.
A borrowed splat renderer outlives or outlasts its source batchesDraws can access destroyed GPU data.Destroy the borrowing renderer before its batches and keep batch ownership explicit.
Ring geometry receives invalid dimensions or sweepConstruction fails instead of producing usable geometry.Keep radii, height, segments, and sweep within the geometry contract.
Physics updates run before preparation or during a rebuildBody commands or published transforms are rejected or stale.Finish prepare or rebuild before frame updates and do not overlap async edits.
Physics catch-up exceeds the configured substep budgetElapsed time is dropped instead of being simulated.Choose a suitable maximumSubsteps and inspect droppedTime.
A physics body or joint points to a missing scene nodePreparation fails and no new world is installed.Resolve all node references before preparing the world.
Physics publication is borrowed across a reset or rebuild revisionA renderer can read retired buffers or mismatched body indices.Fetch the transform frame again after a revision change.
Shadow light count or map capacity exceeds the configured or device limitShadow rendering rejects the frame or cannot create its depth resources.Set capacities and map sizes within the quality and device limits before rendering.
Camera depth range or projection convention does not match a lighting passShadow cascades, clustered light lists, or screen-space visibility use incorrect regions.Pass positive near/far ranges and use the camera convention expected by the selected pass.
Surface depth and normal targets use different devices or sizesAmbient occlusion or contact shadows reject the inputs.Render both targets from the same camera and resize them together.
A clustered-light list exceeds its configured point-light or per-cluster capacityLights are rejected or extra lights are dropped from a cluster.Size the grid for the scene and treat its fixed capacities as part of the lighting contract.
An environment is sampled before its dynamic textures are readyPBR draws use unavailable environment resources.Resolve the loaded environment before passing its textures to PBR bindings.
Light-map baking has no sample or uses invalid chart coverageNo usable result is produced or dilation crosses chart boundaries.Draw at least one valid UV-space sample and provide a same-size chart texture when dilating.
Light-map chart rectangles overlap or exceed the atlasUVs or chart ownership no longer describe a valid bake layout.Run atlas validation and increase the atlas size or lower the texel density.
A reflection probe runs on WebGL or its refresh is read before publicationProbe construction fails or materials see no complete current environment.Select the probe only on WebGPU and use its texture only after a full refresh publishes it.

Key files

FileWhy to read it
modules/…/index.tsPublic engine exports for frame, model, geometry, resource, picking, interaction, audio, and animation APIs.
modules/…/animation-loop.tsMain frame lifecycle, redraw state, timing, errors, and submission.
modules/…/make-animation-loop.tsResource-owned loop construction and cleanup boundaries.
modules/…/animation-props.tsShared state passed through initialization and rendering.
modules/…/model.tsHigh-level relationship between geometry, material, bindings, and draws.
modules/…/gpu-vector-model.tsShared draw path for shaders, dynamic bindings, borrowed vectors, batches, and attachment formats.
modules/…/batch-uniform-buffer.tsAligned uniform slots used to keep managed values distinct across batch draws.
modules/…/gpu-vector-bindings.tsVector layout, constant, buffer, and row-count binding rules.
modules/…/gpu-vector-draw-batches.tsAlignment and restoration rules for multi-batch draws.
modules/…/gpu-vector-model-batches.tsShared vector chunk contract and validation for aligned batches.
modules/…/group-node.tsHierarchy transforms, visibility, traversal, and depth order.
modules/…/material.tsMaterial-owned shader inputs, resource bindings, and dynamic-resource resolution.
modules/…/index.tsPublic lighting exports for PBR, shadows, visibility, clustered lights, light maps, and reflection probes.
modules/…/pbr-model.tsShared PBR model features, including shadow, contact, ambient-occlusion, and light-map paths.
modules/…/shadow-map-renderer.tsDirectional, spot, and point shadow views and depth-map recording.
modules/…/pbr-surface-pass.tsCamera depth and normal targets used by screen-space lighting stages.
modules/…/clustered-light-grid.tsWebGPU point-light grouping and lighting-consumer bindings.
modules/…/lightmap-atlas.tsGeometry-to-chart layout, padded UVs, ownership checks, and atlas diagnostics for light-map baking.
modules/…/reflection-probe.tsWebGPU cube capture, filtering budget, and complete-result publication for local reflections.
modules/…/ambient-occlusion-pass.tsScreen-space ambient visibility output.
modules/…/contact-shadow-pass.tsDirectional contact visibility output.
modules/…/contact-shadow-composite.tsQuality-scaled contact trace, blur, and scene composite chain.
modules/…/prefiltered-environment.tsImage-based lighting environment generation from an equirectangular source.
modules/…/lightmap-baker.tsUV-space irradiance sampling and accumulation.
modules/…/shadow-quality.tsShared lighting quality settings.
modules/…/shader-pass-renderer.tsOrdered targets, temporal history, and screen presentation.
modules/…/index.tsEngine entry point for image, screen-space, and temporal effects.
modules/…/computation.tsWebGPU compute preparation, async creation, uniform updates, and dispatch.
modules/…/texture-transform.tsRender-based texture transform path over a GPU vector model.
modules/…/index.tsColumnar path, polygon, text, and splat conversion and rendering entry points.
modules/…/index.tsglTF scene, material, animation, lighting, audio, and extension entry points.
modules/…/create-gltf-model.tsPrimitive model creation, PBR material ownership, instancing, morph targets, and GPU crowd resources.
modules/…/parse-gltf.tsglTF material alignment, scene-node construction, primitive creation, and asset ownership.
modules/…/parse-pbr-material.tsglTF material feature parsing, texture validation, and texture upload.
modules/…/pbr-material.tsParsed PBR material contract shared by the parser and model creator.
modules/…/index.tsText data preparation and GPU text rendering entry points.
modules/…/index.tsSplat data, residency, hierarchy, sorting, rendering, and picking entry points.
modules/…/README.mdPublic splat lifecycle, glTF bridge expectations, host draw boundaries, and ownership rules.
modules/…/orbit-controls.tsCamera input, frame-time updates, and cleanup.
modules/…/timeline.tsShared animation time and playback channels.
modules/…/scenegraph-animator.tsScene clip selection, cross-fade policy, and scene update timing.
modules/…/physics-controller.tsScene-node physics setup, fixed-step updates, transform publication, rebuilds, and lifecycle.
modules/…/scenegraph-instance.tsTransactional physics execution replacement, captures, revisions, GPU submission, and destruction.
modules/…/picking-manager.tsPicking mode selection, render targets, coordinate conversion, and results.
modules/…/get-platform-info.tsDevice facts used by shader and pipeline preparation.