feat(shadow): baked + dynamic per-receiver shadow projection#31
Merged
Conversation
…per mesh" This reverts commit 0fb2166.
…t full silhouettes
Replaces the per-face per-caster-hull approach with per-triangle projection that 3D-clips each caster tri against the receiver plane half-space before projecting to the face's 2D plane. Fixes the case where tris straddle the plane (top of a tall pole occluding an apple): the previous algorithm dropped below-plane vertices and the hull collapsed to a line, missing the shadow entirely. bench/real-shadow.html runs a Möller-Trumbore raytracer alongside the fast algorithm as ground truth, with a per-face yellow→blue coverage overlay and TP/FP/FN diff readout. Source of truth for future shadow-algorithm work.
# Conflicts: # packages/polycss/src/api/createPolyScene.ts
Stack of four scene-shadow optimisations: - Mount each per-face shadow SVG once and toggle display:none instead of recreating per frame; eliminates ~150 createElement/removeChild + ~600 setAttribute mutations per drag tick - Pre-build per-caster-polygon items (world-space verts + 3D AABB) once per frame; project the 8 AABB corners onto each face plane and bbox-cull against the face outline before the per-tri Sutherland-Hodgman loop - Round path coordinates to 1 decimal (sub-pixel for receiver-plane CSS px); ~30% smaller path strings to parse/raster - Drop the per-path stroke; the implicit AA seam bleed was not visually load-bearing in any tested scene Real-shadow drag bench (apple + electric pole, ?norayt): - script ms/frame: 29.6 -> 12.6 (-57%) - frame_time_p95_ms: 33.3 -> 25.0 (-25%) - frame_time_p99_ms: 39.9 -> 33.7 (-15%) - compositorMain ms/frame: 14.9 -> 7.3 (-51%) - paint/prePaint/layout/style all -64..-79%
Per-caster cached per-polygon data (world-space vertices and 3D AABB) is invariant under light direction. Previously rebuilt every emitSceneReceiverShadows call (once per frame during drag). Now cached on the MeshEntry and invalidated only on geometry/position change. Real-shadow drag bench: script -5%, raster -4%, compositorMain -4%, gpuViz -2%.
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
matrix3d, drops back-facing polys from the DOM (no opacity gating), and re-emits leaves on light change without redrawing the atlas. Mirrored acrosspolycss,react, andvue.display:nonetoggling, per-caster AABB pre-cull, lowered path coord precision, dropped path stroke, and cached caster world-vertices/AABB across light updates.Performance
Real-shadow drag bench (apple + electric-pole,
?norayt), versus the pre-perf-stack baseline of the same projection algorithm:Visual baseline preserved: 12 of 16 multi-angle / multi-light screenshots are byte-identical to the projection-only baseline; the rest differ by ≤340 bytes of sub-pixel AA in PNG entropy.
Test plan
pnpm test— 563 tests across all four packages, all greenpnpm build— packages + website built locally; tsup DTS gate passesbench/results/baselines/shadows/vsbench/results/optI/)bench/real-shadow.htmlwithout?norayt): TP/FP/FN diff stays within the documented per-tri-clip envelope