Repository navigation
feat(core): fit shadow maps to DirectionalLight _shadowBounds (5/5) - #10913
charlieforward9 wants to merge 6 commits into
Conversation
A shadow light fits its shadow map to everything in view. Zoomed out or steeply pitched, that spans kilometers: small casters get a few blocky texels each, and the deep light frustum pushes their depth difference below the shadow test's threshold, so their shadows fade out. DirectionalLight accepts an experimental _shadowBounds box. Its shadow map is fitted to the part of the bounds in view, falling back to the view fit when they don't overlap. The shadow shader now returns no shadow outside the light's frustum instead of sampling the clamped map edge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
[Medium impact] The change affects shadow rendering in the bounded directional-light workflow. The PR should not merge until the existing globe bounds issue is addressed. Findings
SummaryAdds experimental
Reviews (6) · Last reviewed commit: "Merge branch 'fix/shadow-module-keep-bin..." · Reviewed by Greptile |
The shadow map covers a light-aligned box around the bounds, so geometry just outside them can still cast and receive shadows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hadow-bounds # Conflicts: # test/modules/core/effects/lighting-effect.spec.ts
# Conflicts: # test/modules/core/shaderlib/shadow/shadow.spec.ts # test/render/test-cases/effects.spec.ts
Comments Outside DiffThese findings could not be posted inline.
|
| for (const x of [min[0], max[0]]) { | ||
| for (const y of [min[1], max[1]]) { | ||
| for (const z of [min[2] ?? 0, max[2] ?? 0]) { | ||
| corners.push(viewport.projectPosition([x, y, z])); |
There was a problem hiding this comment.
Shadows disappear inside globe bounds
getBoundsCorners projects only the eight corners of _shadowBounds, but a globe's curved surface can extend beyond those projected points. For example, bounds [[-20, 30, 0], [20, 31, 100]] extend farther along negative common-space Y at longitude 0 than at either longitude edge. With light direction [0, 0, -1] and a view covering that area, the fitted box excludes the middle of the bounds, so objects there lose their shadows.
Include the curved surface's extrema when fitting globe bounds, or explicitly limit this option to supported projections.
There was a problem hiding this comment.
This PR targets the branch of #10903, which is closed and replaced by #11109. Please rebase this PR on master, or on #11109, and change the base to match.
I agree with the greptile comment on shadow.ts:242. In GlobeView, the eight projected corners do not include the curved surface between them. Please add points on the surface between the corners, or document that _shadowBounds is for planar views only.
The greptile comment on getFrustumCorners (z >= 0 in GlobeView) is from #10893, not from this PR. The shadow loss in the southern hemisphere is already on master: casters outside the fitted box are not in the shadow map, so those receivers get no correct shadow there either. The new early return only removes the clamp-to-edge streaks. You do not need to handle this in this PR.
Edited after a second check: the southern-hemisphere shadow loss is already on master.
| const corners: number[][] = []; | ||
| for (const x of [min[0], max[0]]) { | ||
| for (const y of [min[1], max[1]]) { | ||
| for (const z of [min[2] ?? 0, max[2] ?? 0]) { |
There was a problem hiding this comment.
?? 0 accepts 2D bounds such as [[minLng, minLat], [maxLng, maxLat]]. With the default direction [0, 0, -1], all eight corners have the same light depth. near then equals far, so clipLightBox returns the view box and the bounds do nothing, with no warning. With a light at an angle, casters taller than the flat box fall outside the near plane and lose their shadows. Please require three values in ShadowBounds, or give flat bounds a minimum height.
| let idCount = 0; | ||
|
|
||
| /** Axis-aligned box in world coordinates: `[[minX, minY, minZ], [maxX, maxY, maxZ]]` */ | ||
| export type ShadowBounds = [number[], number[]]; |
There was a problem hiding this comment.
Please type this as [[number, number, number], [number, number, number]]. Then the type rejects flat 2D bounds.
Part 5 of 5 of the shadow fixes, follows #10903.
A shadow light fits its shadow map to everything in view. When the view spans kilometers (zoomed out, or steeply pitched), small casters such as trees get a few shadow-map texels each and the light frustum is kilometers deep. The shadow test uses a fixed threshold on normalized depth (
smoothstep(0.001, 0.01, ...)), so shadows of objects a few meters tall fade out and the rest are blocky. #10893 fixes the fit above ~70° pitch but can't help here: the view itself is that large. Apps often know where their casters are, so this lets them say so:Change List
DirectionalLight: experimental_shadowBounds,[[minX, minY, minZ], [maxX, maxY, maxZ]]in world coordinatesshadowshader: no shadow outside the light's frustum, instead of sampling the clamped edgeShadowBoundstypeshadow-effect-bounds: 5 m columns at zoom 17, pitch 70, crisp with bounds