[Bug] PostProcessEffect disables depth testing for 3D layers: render buffers have no depth attachment
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 77/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- computer-graphics, frontend
Research direction
Start in modules/core/src/lib/deck-renderer.ts at DeckRenderer._resizeRenderBuffers and inspect how the framebuffer for renderBuffers[0] is created and resized. Then find the existing render tests for post-process effects and add coverage for occlusion between overlapping 3D layers with an effect active. Done means the nearer layer still occludes the farther one, including after a canvas resize.
Written by the indexing model from the issue text.
Description
Description
When a PostProcessEffect is active, 3D layers lose depth testing. A far object draws over a near object when the far layer draws second.
The cause is in DeckRenderer._resizeRenderBuffers (modules/core/src/lib/deck-renderer.ts). When there is a post-process effect, LayersPass draws into renderBuffers[0]. That framebuffer has a color attachment only:
this.device.createFramebuffer({
id: `deck-renderbuffer-${i}`,
colorAttachments: [texture]
})
With no depth attachment, the depth test has nothing to test against. The effect does not need to change any pixel. A pass that returns its input color unchanged is sufficient to cause the problem.
Motivation
We render a 3D vehicle model with ScenegraphLayer in an OrbitView, and we added a tone-mapping pass as a PostProcessEffect. When the pass was on, rings and rails behind the hull showed through the hull. Any 3D scene that uses a post-process effect (for example, a color grade, tone mapping or a screen-space effect from @luma.gl/effects) has the same problem.
Flavors
- Script tag (
dist.min.js) - React (
@deck.gl/react)
Expected Behavior
A post-process effect changes only the colors of the final frame. Occlusion between 3D layers stays the same as without the effect.
Steps to Reproduce
Two extruded boxes in an OrbitView. The red box is nearer to the camera. The blue box is behind it and draws second. Open the page as is, then with ?postfx.
- No effects: the red box hides the lower part of the blue box (correct).
?postfx: the blue box draws over the red box (incorrect).
repro.html (deck.gl 9.4.1 from unpkg)
<!doctype html>
<html><head><meta charset="utf-8">
<script src="https://unpkg.com/[email protected]/dist.min.js"></script>
<style>html,body{margin:0;height:100%;background:#fff}</style></head>
<body><script>
const {Deck, OrbitView, SolidPolygonLayer, PostProcessEffect, COORDINATE_SYSTEM} = deck;
const identity = {
name: 'identity',
fs: `vec4 identity_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) { return color; }`,
passes: [{filter: true}]
};
const square = (x, y, s) => [[x - s, y - s], [x + s, y - s], [x + s, y + s], [x - s, y + s]];
// Red box is nearer the camera; blue box is behind it, drawn second.
const layers = [
new SolidPolygonLayer({id: 'near-red', data: [square(0, -30, 20)], getPolygon: d => d,
extruded: true, getElevation: 40, getFillColor: [220, 40, 40], coordinateSystem: COORDINATE_SYSTEM.CARTESIAN}),
new SolidPolygonLayer({id: 'far-blue', data: [square(0, 30, 20)], getPolygon: d => d,
extruded: true, getElevation: 40, getFillColor: [40, 80, 220], coordinateSystem: COORDINATE_SYSTEM.CARTESIAN})
];
const params = new URLSearchParams(location.search);
new Deck({
views: new OrbitView(),
initialViewState: {target: [0, 0, 20], rotationX: 20, rotationOrbit: 0, zoom: 1.5},
controller: true,
layers,
effects: params.has('postfx') ? [new PostProcessEffect(identity, {})] : [],
// ?fix: the proposed change, applied from outside.
onDeviceInitialized: device => {
if (!params.has('fix')) return;
const create = device.createFramebuffer.bind(device);
device.createFramebuffer = props =>
create(props.id?.startsWith('deck-renderbuffer') ? {...props, depthStencilAttachment: 'depth16unorm'} : props);
}
});
</script></body></html>
Proposed fix
Give the render buffers a depth attachment:
this.device.createFramebuffer({
id: `deck-renderbuffer-${i}`,
colorAttachments: [texture],
depthStencilAttachment: 'depth16unorm'
})
We tested this with the ?postfx&fix flags in the repro above. Occlusion is correct again, and it stays correct after a canvas resize. Framebuffer.resize() clones the depth attachment with the color attachment, and LayersPass already clears depth when it clears the canvas.
Open points for a PR:
- Only
renderBuffers[0]receives layer draws.renderBuffers[1]holds only the output of the passes, so it may not need a depth attachment. depth16unormcan be too coarse for large scenes.depth24plusis a possible alternative, and it is the usual choice on WebGPU.
I can open a PR with this change and a render test.
Environment
- Framework version: deck.gl 9.4.1 (also 9.3.7). The same code is on
mastertoday. - Browser: Chrome (Chromium, ANGLE Metal)
- OS: macOS
Logs
No console errors or warnings.
- Dominant language
- TypeScript
- Stars
- 14.8k
- Forks
- 2.3k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 230
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/deck.gl
-
[Bug] Tile3DLayer selects no tiles until the camera moves when tileset.json loads right after a layer updatePossibly taken @lee3Q claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
[Bug] SplitterWidget calls onDragStart on drag end; Deck._getViews writes into the app's views arrayPossibly taken @04jennet-coder claimed this 20 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
[Bug] WMSLayer positions EPSG:4326 images as CARTESIANPossibly taken @athomct claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
[Bug] MapLibreOverlay under React StrictMode: 'WebGL context already attached to device' because the attach path omits _reuseDevicesPossibly taken @jsve claimed this 84 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
visgl/deck.gl#10681 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug] GoogleMapsOverlay crashes when a vector map is temporarily zero-widthPossibly taken @Juice-de-Orange claimed this 51 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
visgl/deck.gl#10596 · 1 comment · 15 reactions ·
Maintainers usually reply within 1 day
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day