Repository navigation
fix: bind shadow resources in picking and terrain passes - #11109
charlieforward9 wants to merge 3 commits into
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues remain. SummarySupplies shadow textures to picking, collision, and terrain height-map draws.
The previous, unnumbered test-coverage finding is addressed. No new actionable issues were found. Reviews (4) · Last reviewed commit: "test: release the shadow test WebGL cont..." · Reviewed by Greptile |
athomct
left a comment
There was a problem hiding this comment.
Reviewed at bb09a44.
This PR makes a shadow light safe for the passes that do not render shadows. LightingEffect now sets useInPicking, skips the shadow-map render when isPicking is true, and returns {didRender: true} so that CollisionFilterEffect forwards it to the collision pass. TerrainPass.renderHeightMap now keeps the other effects instead of effects: []. The fix works. I reproduced the bug on current master (0741d21) with a small user-facing probe: with a shadow DirectionalLight, pickObject on a plain ScatterplotLayer returns null. Without the shadow, or with this PR, it returns the layer. I ran the two PR test files in headless Chromium on WebGL at the PR head (8 passed). Then I merged the PR into master and ran them with the nearby tests (core effects, collision filter, terrain, pick-layers). All pass: 52 passed and 31 skipped on WebGL, and 62 passed and 2 skipped for the terrain tests on WebGPU. The new terrain test fails on master source (terrain height map draws with both samplers: expected false to be true). The shadow shader module has GLSL only, so I tested the shadow paths on WebGL only. I also did a mutation check. These mutations each make the PR tests fail: remove useInPicking, remove return {didRender: true}, put back effects: [] in renderHeightMap, or remove the isPicking guard. Thank you for the focused test.
Findings
-
should-fix —
test/modules/core/effects/lighting-effect.spec.ts:5-6
The branch does not merge with current master. Master added anAmbientLightimport on the same lines (#11171). The conflict is only in the imports.
Suggested change: rebase and keep both imports:import {test, expect, vi} from 'vitest'; import {AmbientLight, LightingEffect} from '@deck.gl/core';
With this change, all the tests above pass on the merged tree.
-
nit —
modules/extensions/src/terrain/terrain-effect.ts:164
No test covers theeffect !== thisfilter. When I removed it, the full suite stayed green. Today it is harmless, because the shader module binds the dummy height map inWRITE_HEIGHT_MAPmode. But a reader cannot see why the filter is there.
Suggested change: add a one-line comment, like the one inpreRenderfor the cover pass. For example: "Do not bind the height map while this pass writes it."
Verdict
Approve, after the rebase in finding 1. The fix is small and correct, and the tests guard each part of it.
Probe test
import {expect, test} from 'vitest';
import {Deck, DirectionalLight, LightingEffect} from '@deck.gl/core';
import {ScatterplotLayer} from '@deck.gl/layers';
async function pickCenter(shadow: boolean) {
let resolveFrame: () => void;
const frame = new Promise<void>(resolve => (resolveFrame = resolve));
let gl: WebGL2RenderingContext | undefined;
const deck = new Deck({
width: 128,
height: 128,
useDevicePixels: false,
initialViewState: {longitude: 0, latitude: 0, zoom: 12},
layers: [
new ScatterplotLayer({
id: 'point',
data: [[0, 0]],
getPosition: p => p,
radiusUnits: 'pixels',
getRadius: 10,
pickable: true
})
],
effects: [
new LightingEffect({light: new DirectionalLight({direction: [1, 1, -1], _shadow: shadow})})
],
onAfterRender: ({gl: context}) => {
gl = context;
resolveFrame();
}
});
try {
await frame;
return deck.pickObject({x: 64, y: 64})?.layer?.id ?? null;
} finally {
deck.finalize();
gl?.getExtension('WEBGL_lose_context')?.loseContext();
}
}
// master: withoutShadow=point, withShadow=null. This PR: both are 'point'.
test('a shadow light does not break picking', async () => {
expect(await pickCenter(false)).toBe('point');
expect(await pickCenter(true)).toBe('point');
});
Background
A shadow light installs a shader plugin used by every draw. Picking, label collision, and terrain height-map passes can leave its samplers unbound, causing missing draws.
Change List
Note
Low Risk
Low risk fix ensuring existing shadow map bindings are supplied to auxiliary render passes without modifying core rendering behavior.
Overview
Ensures
LightingEffectsupplies required shadow map texture bindings during picking, collision, and terrain height-map passes.LightingEffectnow marks itself active for picking passes (useInPicking = true) without redundantly re-rendering shadow maps, and returns its render status frompreRender. In addition,TerrainEffectandTerrainPassnow forward active effects to the height-map pass instead of clearing them, preventing unbound shadow samplers during terrain draws.Reviewed by Cursor Bugbot for commit bb09a44. Bugbot is set up for automated code reviews on this repo. Configure here.