Skip to content
threejs-debug-view logo

threejs-debug-view

Named debug views for Three.js WebGPU — wire the native runtime into your loop, or add the optional R3F adapter for layouts, overlap, and shader cost with Leva and DOM labels.

threejs-debug-view exposes named debug views for the buffers your scene already produces: beauty, normals, depth, material channels, wireframe, lighting-only, reflection-only, overlap, and shader cost.

Import from threejs-debug-view when you own the WebGPU render loop. You get view definitions, render planning, and runtime helpers such as createDebugPipelineRuntime and createDebugViewportRenderer. No React, R3F, or Leva required.

import {
DEFAULT_DEBUG_VIEWS,
createDebugRenderPlan,
createDebugPipelineRuntime,
createDebugViewUniforms,
resolveDebugViewLayout,
updateDebugViewUniforms,
} from "threejs-debug-view"
import { WebGPURenderer } from "three/webgpu"
const views = DEFAULT_DEBUG_VIEWS
const layout = resolveDebugViewLayout("single")
const plan = createDebugRenderPlan(views, 0, layout)
const uniforms = createDebugViewUniforms()
const runtime = createDebugPipelineRuntime(
scene,
camera,
plan,
layout,
renderer as WebGPURenderer,
uniforms,
)
function animate() {
updateDebugViewUniforms(uniforms, plan.activePipelineView, layout, plan.pipelineViews.length, 1)
runtime.pipeline.render()
requestAnimationFrame(animate)
}

Native install · Native Runtime

Optional React Three Fiber adapter. Import from threejs-debug-view/r3f for DebugViewLayer — built-in views, Leva controls, and DOM labels/legends inside a <Canvas>.

import { DebugViewLayer } from "threejs-debug-view/r3f"
function DebugLayer() {
if (!import.meta.env.DEV) return null
return <DebugViewLayer />
}

R3F install · R3F guide

Keep debug views behind a dev flag unless you intentionally expose them in production.

Use the panel to switch views, layouts, and pane assignments. Try the Overlap and Lights scene tabs for measured overlap and light overlap. On Shader Complexity or Measured Overlap, click the viewport to sample a pixel and move the legend marker.

Open the demo in a new tab

DEFAULT_DEBUG_VIEWS ships sixteen named sources. Override and heatmap passes are demand-driven — they render only when the active view or layout needs them.

SourceModeWhat it shows
beautypassthroughFinal lit color
normalpassthroughView-space geometry normals
depthdepthView-space depth
albedopassthroughBase color without lighting
materialNormalpassthroughMaterial normal map output
emissivepassthroughEmissive color
roughnesspassthroughPacked scalar (R)
metallicpassthroughPacked scalar (G)
aopassthroughPacked scalar (B); material AO, not SSAO
opacitypassthroughPacked scalar (A)
wireframepassthroughWireframe override pass
lightingOnlypassthroughNeutral lighting-only override
reflectionOnlypassthroughReflection-only override
overdrawheatmapMeasured contributor layer count
lightComplexityheatmapLight overlap (v1 analytic counter)
shaderCostheatmapShader-cost estimate (not native GPU counters)

See Built-in Views · Overlap & light diagnostics · Shader cost.

Add a TSL node, or use createCustomDebugView() with a stable id when view instances may be recreated:

import { float, vec4 } from "three/tsl"
import { createCustomDebugView, DEFAULT_DEBUG_VIEWS } from "threejs-debug-view"
const fresnelView = createCustomDebugView({
id: "shader:fresnel",
label: "Fresnel",
node: vec4(float(1), float(0), float(0), float(1)),
})
const views = [...DEFAULT_DEBUG_VIEWS, fresnelView]
// Pass `views` into createDebugRenderPlan() — or into R3F DebugViews when using the adapter.

Custom Debug Views · Presentation routing

GateCommandWhat it checks
Typecheckpnpm typecheckTypeScript across library + demo
Unit testspnpm testVitest (render plans, views, helpers)
Library buildpnpm buildESM dist/ + declaration emit
npm surfacepnpm pack:checkTarball contains only publishable files; bundle badge
Docs buildpnpm docs:buildThis Starlight site compiles
Full verifypnpm verifyAll of the above
E2E demopnpm test:e2ePlaywright against the Vite demo (WebGPU required)

Deployment · Contributing gates in the repo README