viewer: expose depth snapshot channel - #646
Conversation
|
This is the better-shaped of your two, and one part of it is a genuinely good catch that I want to acknowledge properly: you're right that I'm still going to close it, for two reasons. The first is the same as on #644: nothing consumes a depth capture. Both snapshot callers want one WebP for a thumbnail, and no plan on our side asks for depth. Adding The second is specific to this diff, and it's the one I'd fix first if a consumer appeared. The depth blob goes through the unchanged Two smaller notes:
None of this is wasted. If you're interested in the consumer end, I'd rather talk about that first — open an issue describing what you want depth for and what precision it needs, and we can design the channel around it instead of guessing. The ortho finding should go in that issue; it's worth not losing. |
What does this PR do?
Adds an optional
channel: 'rgb' | 'depth'toSnapshotPipeline.capture, defaulting to the existing RGB behavior.The depth channel reuses the snapshot pipeline's existing scene pass, render target, crop, GPU readback, and encoder. It emits near geometry as white and far/background pixels as black. Orthographic cameras use the hardware depth attachment directly because Three's current
getLinearDepthNode()always applies perspective conversion.This makes aligned RGB/depth evidence available to viewer consumers without maintaining a second capture implementation.
How to test
packages/viewer, runbun run build.packages/viewer, runbun run testand confirm all 102 tests pass.bunx biome check packages/viewer/src/lib/snapshot-pipeline.ts packages/viewer/src/lib/snapshot-pipeline.test.ts packages/viewer/src/index.tsfrom the repository root.Screenshots / screen recording
Not applicable: this adds a capture API channel and does not change the live viewer UI.
Checklist
mainbranchNote
Low Risk
Additive API with default RGB behavior unchanged; depth path is isolated but touches the shared snapshot render/dispose flow.
Overview
Adds an optional
channel: 'rgb' | 'depth'argument toSnapshotPipeline.capture(default'rgb'), so consumers can request aligned depth evidence through the same render target, crop modes, and WebP readback path as existing snapshots.For
'depth', a dedicated TSL pipeline outputs inverted depth (near white, far/background black) with color transforms disabled.snapshotCameraDepthNodepicks raw depth for orthographic cameras and linear depth for perspective, avoiding Three’s perspective-onlygetLinearDepthNode()on ortho shots. The publicSnapshotCaptureChanneltype documents the encoding;snapshotCameraDepthNodeis covered by a small unit test.Reviewed by Cursor Bugbot for commit 3671362. Bugbot is set up for automated code reviews on this repo. Configure here.