Repository navigation
feat(render3d): add point and spot light shadow maps - #726
Merged
Merged
Conversation
…gh the PBR path The first version of the local shadows carried its own light types and lighting model, which disagreed with LightRig (no 1/pi in the diffuse term, a different near-field clamp, Range required), its ready-made pipelines ignored per-draw transforms and used a constant albedo, and its WGSL hard-coded @group(1), which collides with LightGroup. SpotShadowMap and PointShadowMap now update from the rig's SpotLight and PointLight (far plane = Range, or the config's Far when Range is 0). The WGSL only samples visibility, at LocalShadowGroup (= ShadowGroup, 3), with SpotShadowWGSLForGroup and PointShadowWGSLForGroup to move it. LightWGSL gains shade_pbr_visibility, which scales directional light 0, point light 0 and spot light 0, and ShadePointVisibility mirrors it. LitPBRSpotShadowWGSL and LitPBRPointShadowWGSL (NewLitPBRSpotShadowPipeline, NewLitPBRPointShadowPipeline, LitPBRPipelineOptions.SpotShadowLayout and PointShadowLayout) are LitPBRWGSL with the map bound. Casters follow DirectionalShadowMap: BeginShadowPass(dev, target) and BeginFacePass(dev, target, face), DrawCaster returns false when the pass or face is full or Update has not run. Each point face owns its slots, so partial or reordered face refreshes never exhaust the buffer. MaxCasters is capped at MaxLocalShadowCasters and checked against MaxBufferSize. Doc comments are unwrapped.
Rewrite the render3d.md section in both languages for the LightRig-based API, list the new group 3 options next to skinning, add the package overview paragraph, and update the changelog fragment and the design note.
houko
force-pushed
the
feat/render3d-local-shadows-255
branch
from
November 24, 2026 18:09
17ec932 to
c34cb7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shadows for the first spot light and the first point light of a
LightRiginpackages/game/render3d.SpotShadowMap,SpotShadowConfig): a depth-onlyFormatDepth32Floatperspective map updated from the rig'sSpotLight(fovY = 2 * OuterConeAngle, far plane =Range, orFarwhenRangeis 0), with hard and 3×3 PCF filtering, depth and normal bias, and 256-byte dynamic-offset caster slots.PointShadowMap,PointShadowConfig): the six 90° cube faces packed into one 3×2 depth atlas, updated from the rig'sPointLight, with per-face viewport/scissor isolation, analytic perspective depth in the shader, and per-tile UV clamping so PCF never bleeds across tiles. Each face owns its caster slots, so faces can be refreshed in any order or skipped.LitPBRSpotShadowWGSL/LitPBRPointShadowWGSL(NewLitPBRSpotShadowPipeline,NewLitPBRPointShadowPipeline, orLitPBRPipelineOptions.SpotShadowLayout/PointShadowLayout) areLitPBRWGSLwith the map atLocalShadowGroup(=ShadowGroup, 3): per-draw model matrix and material fromPBRDrawUniform, and the shadowed light shaded exactly like the rest of the rig.shade_pbr_visibilityinLightWGSLandShadePointVisibilityscale directional light 0, point light 0 and spot light 0.SpotShadowWGSL/PointShadowWGSLexpose onlysample_spot_shadow/sample_point_shadow;SpotShadowWGSLForGroup/PointShadowWGSLForGroupmove the bindings so a shader can bind both (tested at groups 3 and 2 next to the camera and light rig).DrawCaster(pass, mesh, model) boollikeDirectionalShadowMap, returning false when the pass or face is full orUpdatehas not run;MaxCasterscapped atMaxLocalShadowCastersand checked against the device'sMaxBufferSize.EvaluateSpotShadow,EvaluatePointShadow,PointShadowSelectFace, zero-allocation uniform encoding,Retaineddevice-loss restoration, scope disposal, and golden renders (local_shadow_spot.png,local_shadow_point.png).docs/en|zh/render3d.md, the package overview indoc.go,changelog.d/render3d-local-shadows-255.md, and the design note.Review follow-up
Rebased onto main, which added
LightRigspot lights, the directional shadow at group 3, and new render3d doc sections. The first version used its own light types and lighting (no 1/π diffuse term, a different attenuation clamp,Rangerequired), ready-made pipelines without a model matrix and with a constant albedo, and@group(1), which collides withLightGroup. All of that now goes through the rig and the shared PBR path, as described above.Verification
gofmtcleango tool nsgo test ./render3d(325 passed: GPU-vs-CPU pixel checks againstShadePointVisibility, goldens,fullandNoGPUComputeprofiles, device-loss restore, caster slot limits, spot+point composition)go tool nsgo check -target linux,web ./render3dgo tool nsgo test .(3372 passed)go run ./tools/changelog checkScreenshots
Golden renders (128×96, software renderer):
packages/game/render3d/testdata/golden/local_shadow_spot.pngpackages/game/render3d/testdata/golden/local_shadow_point.pngCloses #255