Skip to content

Follow-ups: cached lamp shadows (#559 review) #565

Backlog

Description

@BoroBongo

Follow-ups from the review of #559 (cached lamp shadows). The PR fixed these: a CPU time budget instead of 3 lights per frame, the draw list built once per light, chunk bounds cached, collider overflow logged, a comment explaining the projection, and the ADR wording. These were left for later.

Change detection

  • Replace the collider polling with a signal. Today, 4 drawn lights get a physics sphere query every frame, forever. Instead: LightShadowCacheDomain.MarkDirty(Bounds), called where a lazily loaded VOB gets or loses its collider (the VobMeshCullingChanged path). It queues the lights whose sphere intersects. Then CountColliders, ColliderCount and _checkList go away.
  • Counting colliders misses swaps (one removed and one added) and flaps on moving colliders (thrown items, doors), which re-renders again and again and bakes the moving object in. A moving lamp is re-queued at every rebalance, because positions are compared exactly (Vector3 !=). Use a small tolerance (~5 cm).
  • chunk.enabled is a snapshot at draw time. A chunk that is disabled at that moment leaves a permanent hole in the light's shadow. Drop the check, or confirm nothing ever disables chunks.
  • A VOB whose collider is on a parent or child of its renderer casts nothing (TryGetComponent only looks at the collider's own GameObject).

Lifecycle / contracts

  • Dispose(). The atlas (48 MB), _faceTarget, _cmd and _emptyAtlas are only freed by SetEnabled(false) (_cmd and _emptyAtlas never). Call it from the service teardown.
  • One contract in three places: FaceSize (C# const + #define), the face tables (C# + HLSL), the alpha encoding indoor + 2*(slot+1) (encoded in the service, decoded in HLSL), and the 0.05 near plane (copied from the service). Move the encoding into LightShadowCacheDomain.EncodeSlotAlpha, upload FaceSize as a global (or add a test), and share one near-plane constant.
  • Capacity (256): if it is meant to equal the pool size, reference the pool's constant.

Shaders / build

  • The GothicLightCache pass is compiled into Quest builds (instancing x _WIND) but never used there. Wrap it in #if !defined(SHADER_API_MOBILE) or strip it.
  • The UnityPerMaterial CBUFFER is copied into every pass (Lit-World has 5 copies). Use one include per shader so the copies can't drift apart and silently break SRP batching.
  • Lit-AlphaToCoverage-Dynamic uses plain AdditionalStationaryDiffuse, so a focused alpha-tested object is lit through walls (no cache, no shadow). This was already the case before the PR.

Small

  • The "N lights cached" log fires on every queue drain, including check-driven re-renders (a flapping light spams the build log).
  • _passIndices grows for every material seen until the world changes. _renderQueue.RemoveAll allocates a delegate per rebalance.
  • Docs: architecture.md "Where does my code go?" has no row for GPU infrastructure (render textures, command buffers -> Domain/Meshes/<Name>Domain). The ADR doesn't say why a URP renderer feature was not used.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions