Skip to content

feat: PC shadows - sun/moon, lamps, torch and spells, the hero's own shadow, SSAO, darker nights (GD3D11-like) - #555

Open
BoroBongo wants to merge 14 commits into
developfrom
feature/pcvr-shadows-lighting
Open

BoroBongo wants to merge 14 commits into
developfrom
feature/pcvr-shadows-lighting

Conversation

@BoroBongo

@BoroBongo BoroBongo commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Dynamic shadows and moodier lighting on PC, in the spirit of GD3D11 (the D3D11 renderer mod for the original games). Gothic's baked look stays; there is no overhaul. Quest is unchanged: its quality level (URP-Performant) has no shadows and no SSAO, and the shaders compile those parts away there.

This PR now also contains #556 (the hero's torch and spell shadows, highlighted NPCs keep their shadow), the hero's own shadow, the roof rule for indoor lights, the "Shadow range" option and the frame rate fixes from the first playtests. #558 (SRP batcher) is merged in, so merge #558 first. The cached shadows for all other lamps come in a stacked PR on top of this one.

Sun and moon

  • A "Sun" directional light is URP's main light, used for its shadow map. It rises at 6:00, is highest at 12:00 (60°, the path is tilted) and sets at 18:00. At night the moon takes its place on the same path with a weaker shadow, faded out at the horizon. Shadows reach 150 m.
  • The sun moves every game second (SunUpdateInterval: Production + default "every game second"), so shadows glide instead of jumping once per game minute.
  • _SunDirection was Euler angles, not a direction. N·L of objects/NPCs was effectively a switch on normal.x. It is now the real light direction.

Shaders (Lit-World, Lit-AlphaToCoverage, Lit-SingleMesh)

  • ShadowCaster passes. They apply the same wind, alpha cut (plants, fences) and NPC fatness as the main pass. Cull Off, because Gothic's polygons are one-sided. The -Dynamic shaders (highlighted NPCs/items) got one too, so a highlighted NPC keeps its shadow.
  • Receiving shadows, GD3D11 style. The shadow darkens only the sun's part of the light: Gothic's baked light on sun-facing outdoor polygons and VOBs (not light mapped ones), and the sun term of objects/NPCs. Lightmaps, ambient light and fires stay as they are.
  • DepthOnly/DepthNormals passes. URP's SSAO (HighFidelity renderer) finally sees the world. It darkens the baked/ambient light and affects the sun and lights less.
  • Light clamp. The light sum stops at 1, like Gothic's 8-bit vertex light, so overlapping lamp pools no longer burn out.
  • SRP batcher. Every Lit/World pass has the same material buffer (perf: the world and its VOBs are SRP batched again (SetPass 3100 -> 190 with shadows) #558). Without it every shadow pass drew the world chunk by chunk.

Lamps, fires, torch and spells

  • Shadow casting lights. The pooled lights closest to the camera (option "Shadow range": 4 within 20 m up to 12 within 50 m; spell lights first; not lights baked into lightmaps) become shadow casting URP point lights. A street lamp throws its iron cage onto the ground, and NPCs and the hero cast shadows in it. The pool marks them (slot w < 0) and skips them; the shaders light them through URP with the cube shadow.
  • The hero's torch, the Light spell and spell projectiles cast shadows (up to 4 moving lights). The near plane keeps the torch's stick and the hand out.
  • GothicShadowLightsFeature (renderer feature on URP-HighFidelity-Renderer) finds their index among URP's additional lights every frame. URP's 8 per-object lights cut a lamp's light off at a world chunk's edge. It no longer resolves the lights service in edit mode (exceptions in the Render Graph).
  • Unity lights enabled only within 40 m (and the shadow casting ones). URP takes 256 visible lights and the city has ~770, so turning the head pushed a lamp out and its light vanished. The pool still lights the world beyond 40 m.
  • Light order per renderer. Renderers list their stationary lights shadow casting first, then closest; slot order left the market's lamps out.
  • Roof rule. A light with a light mapped ceiling 2–8 m above it (house, cave, sewer) doesn't light outdoor surfaces. The candles in a house glowed on its outside walls.
  • Brightness. Lamps/fires are a bit stronger: falloff 1 - (d/R)², strength 1.4.

The hero's shadow (VR). The hero's body casts its shadow (sun, moon, lamps, torch). The head is scaled away so the camera doesn't see into it; a shadow-only copy of it follows the head bone, so the shadow has a head and the camera never draws it.

Darkness

  • Nights. The world gets 50% of the night sky's light, so lamps pop.
  • Mines and other indoor worlds. Darker (0.12).
  • Rain and thunderstorms. The world drops to 70% and the sun's shadow to 35%.
  • Outdoor lamps/fires dim by day: 100% at night, 20% at noon. "Outdoor" means no light mapped ceiling 2–8 m above the light.

Options (Immersion, 8 languages)

  • "Shadows": off / hard / medium / soft (default soft). It applies to the sun and the point lights.
  • "Shadow range": a slider for how many lamps get a shadow (default 0.75, about 10 lamps within 40 m).

Frame rate. 40 shadow lamps (the first slider range) and the unbatched world tanked the frame rate in the first playtest. Now: max 12 lamps, additional-light shadow atlas 4096, sun shadows 150 m, world SRP batched. In the editor in Khorinis: SetPass calls 3100 → 190, opaque pass 86 ms CPU / 44 ms GPU → 5 / 9.5 ms, sun shadows 9.5 / 3.7 → 4.4 / 1.2 ms, lamp shadows 9.8 / 4.6 → 3.2 / 1.4 ms (sums of 4 profiler blocks). The PC build ran smoothly after it.

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

Why

How to test manually

PCVR build (quality High / URP-HighFidelity, the Standalone default). In the Editor, switch to quality "High" first; the Editor uses Low.

  • G2, Khorinis market by day (e.g. a save around 12:00): the lamp posts, tables, NPCs and houses cast shadows on the street. Trees and fences cast leafy, see-through shadows, and swaying trees take their shadows with them.
  • Look down in the sun: the hero's body casts a shadow with a head; the head itself is never in view.
  • Wait or sleep until the afternoon: the shadows grow longer and move smoothly (no jumps).
  • Night (23:00–2:00) on the market: the world is dark, the street lamps throw the pattern of their iron cage onto the street, and tables/NPCs cast lamp shadows. Turn the head around in steps: no lamp light vanishes.
  • Night, light a torch / cast Light: walls and NPCs cast moving shadows. Throw a fireball past a wall: its light casts a shadow.
  • Highlight an NPC (point at it): it keeps its shadow.
  • Night, next to a house with candles inside: its outside walls don't glow orange.
  • Several lamps next to each other: no burnt-out orange, the light stays at the lamp's color.
  • Same place at noon: the lamps don't glow on shaded walls; fireplaces inside houses still burn.
  • G1 Old Mine / any mine: dark, lit by the lamps (lightmaps), fires and the torch.
  • Rain/thunderstorm: the world is darker and the sun's shadows weaker.
  • Immersion → Shadows: off (no shadows), hard, medium, soft. Each one changes at once.
  • Immersion → Shadow range: all the way down / up, and the number of lamps with shadows changes at once.
  • Frame rate in the city at night stays smooth (Shadow range at max).
  • Corners/under tables: soft ambient occlusion (subtle).
  • Quest build: looks as before, with no performance change.
  • G1 (e.g. near Orry at the Old Camp's gate by day): sun shadows on the palisade and ground.

Tested so far: in the editor (G2 Khorinis day and night, quality High) and 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

No new saved state. The sun follows the loaded game time; both options live in Gothic.ini.

Known gaps / follow-ups

  • Lamps beyond the shadow range have no shadow; only the roof rule stops a house's candles. The stacked PR adds cached shadows for all of them.
  • No shadows from lights baked into lightmaps (e.g. most mine lamps).
  • Not done: height fog, god rays, bloom/tonemapping, water reflections. GD3D11 has them; possible next steps.
  • GPU cost in the headset isn't measured yet. Slower PCs: Shadows → hard/off, Shadow range down.
  • Screenshots: GitHub's CLI can't upload them; see the comments.

…d a Shadows option (PC)

- Gothic's lit shaders (world, VOBs, plants, NPCs, items) cast shadows (ShadowCaster passes with the same wind, alpha cut and fatness as the main pass) and receive them. The shadow darkens only the sun's light, GD3D11-like: Gothic's baked light of sun-facing outdoor surfaces and the sun part of objects; lightmaps, ambient and fires stay.
- A "Sun" directional light (SkyService) is URP's main light: it rises at 6, is highest at 12 (60 degrees, the path tilted), sets at 18; at night the moon takes its place with a weaker shadow, faded out at the horizon. It moves every game second, so the shadows glide. _SunDirection was Euler angles, not a direction - N·L of objects was a switch on the normal's x.
- DepthOnly/DepthNormals passes: URP's SSAO (HighFidelity renderer) finally sees the world; it darkens the baked/ambient light, less the sun and fires.
- Immersion option Shadows: off / hard / medium / soft (default), 8 languages.
- SunUpdateInterval defaults to every game second; InitSky no longer adds a sun listener per world load.
Quest: the Performant asset has no shadows and no SSAO - nothing changes there.
…round), darker nights, rain darkens the world

- The 6 lights closest to the camera (lamps, fires; not the lightmap-baked ones) become shadow casting URP point lights (StationaryLightsService, Shadows option). The shaders light them through URP with their cube shadow - a lamp's iron cage throws its ornament onto the street. GothicShadowLightsFeature tells the shaders their index among URP's additional lights every frame: URP's 8 per-object lights cut a lamp's light off at a world chunk's edge.
- Only Unity lights within 40 m stay enabled: the city has ~770, URP takes 256 visible ones - turning the head pushed a lamp out and its light vanished. The pool still lights the world beyond.
- Renderers sort their stationary lights: shadow casting first, then the closest (slot order left the market's lamps out).
- Lamps/fires a bit stronger with a 1-(d/R)² falloff; the light sum stops at 1 like Gothic's 8 bit vertex light, pools next to each other no longer burn out orange.
- Nights are darker (the world gets half of the night sky's light), indoor worlds (mines) darker, rain/thunderstorms darken the world and weaken the sun's shadow.
…on shaded walls at noon

Gothic's lights burn all day, but its bright vertex light hid them. Ours are stronger and the sun's shadow leaves 40%, so lamps glowed on shaded walls at noon. Lights outside of houses and caves (no light mapped polygons within 3 m) follow the day light: full at night, 20% at noon - their pool slot and Unity light (objects, NPCs, lamp shadows). Fireplaces inside, mines and the hero's torch stay.
…orinis' street lamps next to light mapped walls dim by day too

Light mapped polygons within 3 m made a light indoors: the market's street lamps stand next to light mapped walls and stairs (and the sewers run below), they kept glowing at noon. Now a light mapped polygon 2-8 m right above the light (roof, cave or sewer ceiling) makes it indoors.
@BoroBongo

Copy link
Copy Markdown
Contributor Author

How this PR was made: AI-assisted development log

This PR was written by Claude Code (Claude Opus) in one live session with BoroBongo. BoroBongo steered and played along in the Editor's Game view and reacted to what he saw; the agent wrote the code, tested it in the running game through the Unity MCP and took the screenshots.

The prompt

"I want you to work a bit harder on shadows and better graphics in general... we have a few issues for this, so lean on them. I have a beefy PCVR machine and Unity has a lot of room to make the game look gorgeous... we already have lights, but adding dynamic shadows will be awesome immersion... I leave it to you to improve the visuals beyond shadows and lights too - just not a total overhaul, I want nice graphics but more in the style of what d3d11.dll creates in 'normal' Gothic (as a plugin/mod)... and play with subagents."

Later: "run it and test it in the game and give me screenshots - you have different saves during the day and at night."

1. Research (two parallel subagents)

  • Explore agent, our renderer:
    • URP assets per quality level: Standalone = HighFidelity; the Editor runs Low.
    • The custom shaders had no ShadowCaster/Depth passes.
    • Shadow and SSAO settings existed but had no effect.
    • The world had no directional light, and _SunDirection held Euler angles, not a direction.
  • General-purpose agent, GD3D11 (local install + GitHub sources):
    • Feature list with defaults, e.g. 3 cascades / 2048 px, 40% light left in shadow, HBAO+, god rays, height fog.
    • Key insight: GD3D11 layers the shadow over Gothic's baked vertex light rather than replacing it. Every shader change here follows that rule.

2. Testing setup (Unity MCP, no headset)

  • The local DeveloperConfig loads a save directly: no menu, no videos, XR Device Simulator.
    • Khorinis market at 12:42 (day).
    • Xardas' tower at 0:20 (night).
  • Quality: switched to High at runtime, since the Editor uses Low.
  • Game time: set via the DI container (GameTimeService.SetTime) for day, 15:00, 23:30 and 2:00.
  • Player turns: by rotating the XR rig root.
  • Inspection: lights, light counts, renderer light lists and shader globals read via execute_code. Baseline screenshots taken before any change.

3. Iterations driven by what we saw

Observation Cause found Fix
Shadows "vanished" after toggling SSAO Asynchronous shader compilation of new variant combinations (cyan frames gave it away), not a real conflict None needed; builds precompile variants
Shadows move "rigidly" Sun updated once per game minute Every game second (14×/s, 1/240° steps)
Lamp light and shadow vanish when turning the head ~770 Unity lights in the city, 254 in view: URP's 256 visible-light cap Unity lights only within 40 m; the pool lights the world beyond
Lamp light cut off with a straight edge on the street World chunk boundary: URP's 8 per-object lights didn't include the lamp GothicShadowLightsFeature: shaders get the lamps' URP light index per frame
Lamps "like a supernova", burnt orange Overlapping pools summed above 1 Light sum clamped to 1 (Gothic's 8-bit vertex light)
Lamps too weak Linear falloff 1 - (d/R)², ×1.4
Night could be darker Night sky light ~0.43 World gets 50% at night; mines darker; rain darkens
Lamp glows red at noon Gothic lamps burn all day; ours are stronger Outdoor lights dim by day (20% at noon)
One lamp still glowed by day "Indoor" test: light mapped walls and stairs within 3 m; the sewers run below the market Indoor = light mapped ceiling above the light

Black carpets at Abuyin's stall turned out to be the same "lightmap nearby" heuristic. That is a separate PR: #554.

4. Verification

  • Every step compiled and was checked for shader errors via MCP.
  • EditMode tests: 87/87 on this branch, including CoreArchitectureTest.
  • Screenshot series at day, 15:00, 23:30 and 2:00, plus 20° head turns around the lamps.
  • Not done: headset performance. Please check the GPU frame time in PCVR.

Screenshots are on BoroBongo's machine (Temp/GraphicsShots/) and get attached by hand, since the GitHub CLI can't upload images. The key ones:

  • base_city_day vs v1_city_day_b: before/after sun shadows.
  • v2_city_15h_ao: long afternoon shadows.
  • v6_rot0..v6_rot80: lamp cage shadows while turning.
  • v9_2am: middle of the night.
  • v12_day_lamp_outdoor: lamps dimmed by day, carpets fixed.

@BoroBongo

Copy link
Copy Markdown
Contributor Author

Screenshots from MCP here:
v1_city_day_b
v6_rot0
v6_rot20
v6_rot40
v6_rot60
v6_rot80
v9_2am
v12_day_lamp_outdoor
base_city_day

…adows; highlighted NPCs and objects keep theirs

- ClaimHeroLight takes the hero light's Unity light (torch, Light spell): it casts a cube shadow (near plane 0.2 m, so the torch's stick doesn't hide its flame), its slot is marked (w < 0) and the shaders light it through URP like the lamps.
- Spell projectiles (VRSpellThrow) register their light as a dynamic shadow light: a flying fireball now lights the walls it passes (before only NPCs and objects) and throws shadows. Up to 4 dynamic shadow lights; destroyed ones drop out.
- Spell effect lights (VisualFxLight: summoning, fire rain) come before the lamps among the pooled shadow lights.
- 12 shadow lights at most (feature and shader).
- Lit/SingleMesh-Dynamic and Lit/AlphaToCoverage-Dynamic (highlight on hover, fading) got a ShadowCaster pass - a highlighted NPC lost its shadow.
- The Shadows option switches them too.
BoroBongo and others added 7 commits November 23, 2026 02:09
…htness was outside UnityPerMaterial and ~1900 VOBs had a MaterialPropertyBlock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ps/fires within 40 m cast shadows

Lights beyond the shadow casting ones have no shadow: a candle in a house lit the house's outside walls like a spotlight. A light under a light mapped ceiling (house, cave, sewer) is indoor (slot color alpha 1) and skips outdoor surfaces (vertex lit polygons, VOBs outside light mapped areas). 10 instead of 6 lamps/fires within 40 m cast shadows (16 shadow lights at most incl. the hero light and projectiles).
… m); the hero's head casts a shadow the camera never sees

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m), additional shadow atlas 4096, sun shadows 150 m; every Lit/World pass SRP batched

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hero body shadow, Shadow range option, SRP batcher rule

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BoroBongo BoroBongo changed the title feat: dynamic sun/moon and lamp shadows, SSAO, darker nights - GD3D11-like lighting on PC feat: PC shadows - sun/moon, lamps, torch and spells, the hero's own shadow, SSAO, darker nights (GD3D11-like) Nov 23, 2026
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