Skip to content

feat: every lamp and fire in reach casts a cached shadow (GD3D11-like) - no more light through walls - #559

Open
BoroBongo wants to merge 2 commits into
feature/pcvr-shadows-lightingfrom
feature/pcvr-cached-lamp-shadows
Open

BoroBongo wants to merge 2 commits into
feature/pcvr-shadows-lightingfrom
feature/pcvr-cached-lamp-shadows

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

Every lamp and fire in reach casts a shadow from walls and VOBs, like in GD3D11. Candles inside houses no longer light the street, and distant buildings no longer show red patches through their walls.

Stacked on #555 (base feature/pcvr-shadows-lighting), so the diff shows only the cache.

  • LightShadowCacheDomain (owned by StationaryLightsService): a 16 bit Texture2DArray, 256 lights × 6 faces of 128×128 (48 MB). Every pooled lamp/fire in reach gets its surroundings drawn once into its six faces: the distance to the nearest wall or VOB. Lights baked into lightmaps and moving spell lights are excluded.
  • GothicLightCache pass in Lit-World, Lit-AlphaToCoverage and Lit-SingleMesh (GothicShadowCaster.hlsl with GOTHIC_LIGHT_CACHE): writes the distance to the light. It has its own LightMode, so URP never draws it.
  • Lookup (StationaryLighting.hlsl, StationaryLightContribution): the light's slot is packed into its color alpha (indoor + 2 × (slot + 1)), and the world shader compares distances with a 2×2 bilinear filter. A light without a slot falls back to the roof rule of feat: PC shadows - sun/moon, lamps, torch and spells, the hero's own shadow, SSAO, darker nights (GD3D11-like) #555. PC only: Quest's shaders compile it away.
  • On only with the "Shadows" option on and URP's additional-light shadows (quality High). It follows the option at once, also while standing still.

Decision record: Docs/adr/2026-11-23-cached-lamp-shadows.md. Technical: Docs/world-lighting.md → "Shadows and darkness".

Why

URP draws every shadow casting light again in every frame, six times, and takes about 40 at most. With 40 the frame rate tanked, and all other lamps lit through walls. GD3D11 keeps a light's shadow map and draws it again only when something changes; URP has no such cache (HDRP has).

How to test manually

PCVR build, quality High, Shadows on. G2, Khorinis at night:

  • Walk the alleys around the market: no orange or red patches on outside walls from candles/fires inside houses; distant buildings have no light bleeding through.
  • Doorways of lit houses and passages: the light inside stops at the doorway.
  • Lamps on house walls light the wall below them (not cut off).
  • Walk through the city: no hitches when new lamps come into reach.
  • Shadows → off: the cache switches off too (the roof rule still keeps candles off the outside walls).
  • Quest build: looks as before.

Tested so far:

  • In the editor: the cache content checked by reading the faces back from the GPU and comparing them with raycasts from 5 lamps (89–99% of 400 directions match), plus before/after screenshots at the same spot.
  • In a PC build with the keyboard/mouse VR simulator.
  • Not tested with a headset yet, and nothing on Quest 2 or Quest 3 standalone.

Save/load

Nothing saved. The cache is rebuilt after loading (about a second).

Known gaps / follow-ups

  • An opened door keeps the closed door's shadow until something else makes its lamps draw again. VOBs without a collider cast no cached shadow.
  • 128 texels per face: softer than URP's near shadows. Bigger faces for big fires could come later.
  • 48 MB of video memory on PC.

BoroBongo and others added 2 commits November 23, 2026 02:12
…) - candles in houses no longer light the street and distant walls

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pass keeps Lit/World SRP batched

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant