Skip to content

perf: the world and its VOBs are SRP batched again (SetPass 3100 -> 190 with shadows) - #558

Merged
JaXt0r merged 3 commits into
developfrom
fix/world-srp-batcher
Nov 24, 2026
Merged

JaXt0r merged 3 commits into
developfrom
fix/world-srp-batcher

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

The world and its VOBs are drawn with Unity's SRP batcher again. Fewer CPU draw costs on every platform (Quest too).

  • Lit/World wasn't SRP batcher compatible: _FocusBrightness was a material property outside the UnityPerMaterial buffer (ShaderUtil.GetSRPBatcherCompatibilityCode reported it). It's inside now.
  • VOBs standing in light mapped areas (houses, caves) got their lightmap tint through a MaterialPropertyBlock. The SRP batcher skips every renderer with one: ~1900 VOBs in Khorinis. The tint now goes into the renderer's own materials. Every renderer has its own materials already, because StationaryLightsService.UpdateRenderer writes its light indices there too (measured: 4762 materials for 4771 renderers).

Measured in the editor in Khorinis with the shadows of #555 on: SetPass calls went from 3100 to 190, and the opaque pass from 86 ms CPU / 44 ms GPU to 5 / 9.5 ms (sum of 4 profiler blocks). Without shadows the gain is smaller, but it's the same mistake.

Why

Found while chasing the frame rate drop of the PC shadows (#555). Every shadow pass draws the world again, and unbatched that tanked the frame rate. It's a fix on its own, independent of the shadows, so it goes first.

How to test manually

  • G2, Khorinis: VOBs in houses (Abuyin's carpets, Coragon's tavern) are lit like before, neither black nor bright
  • G1, Old Mine: the scaffolds and stairs are as dark as the walls around them (the lightmap tint still applies)
  • Point at an item or NPC: the highlight still brightens it (_FocusBrightness)
  • Optional: Frame Debugger / Profiler shows "SRP Batch" for the world, far fewer SetPass calls

Tested in the editor (G2 Khorinis, 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 3.

Save/load

Nothing saved. The tint is set when a VOB loads, like before.

Known gaps / follow-ups

…htness was outside UnityPerMaterial and ~1900 VOBs had a MaterialPropertyBlock

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…marks get their own material (review #558)

- DynamicMaterialService copies the original material for the highlight, so _VobLightTint and the lamp indices stay
- StationaryLightsService writes per-renderer values only into owned materials (never the shared LoadingMaterial)
- untextured color materials are per renderer (texture cached per color), so one VOB's lights no longer light all
- architecture.md P4 and world-lighting.md: SRP batcher rule, no MaterialPropertyBlock on world/VOB renderers

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BoroBongo

Copy link
Copy Markdown
Contributor Author

Review (architecture-reviewer + gothic-reviewer x2) on 6b652d2

Verdicts: architecture fits with concerns, gothic run 1 and run 2 approve with changes. The main finding, from all 3 runs: the focus highlight dropped the world-light tint (a chest in a cave lit up to full day while focused).

Fixed in fdfd9ca, follow-ups in #563.

Finding Answer
Focus highlight drops _VobLightTint (arch Major, gothic runs 1+2) Fixed: DynamicMaterialService copies the original material (new Material(mat) { shader = dynamic }), so the tint, light indices and fatness stay. The comment at the old line 112 was updated too.
"Each renderer has its own materials" is assumed, not owned (arch Minor) Fixed: GetOwnedMaterials (one place) is used by ApplyWorldLight and UpdateRenderer. It skips Constants.LoadingMaterial, and ApplyWorldLight checks HasProperty. The untextured color materials are now per renderer (the texture is cached per color), not filtered out. Filtering them would have taken lamp light off the X marks.
P4 / world-lighting.md disagree with the code (arch Minor) Fixed: P4 now states the SRP batcher rule, and world-lighting.md has a _VobLightTint row.
SRP batcher EditMode test (arch Minor, later) Follow-up #563
Null world light leaves the old tint (gothic Low) Follow-up #563
Barrier / GothicUI / Thunder / Bink incompatible (info) Follow-up #563 (check whether it matters)
Q: measured on Quest? Editor only (SetPass 3100 -> 190); Quest measurement is in #563

Compiled in the Editor with no errors; the runtime check (a focused chest in the Old Mine) is still to be done by playtesting.

@BoroBongo

Copy link
Copy Markdown
Contributor Author

Editor test of the review fixes (G2, a save in Khorinis harbour at night): a world-lit barrel (_VobLightTint 0.07, 1 lamp) keeps tint 0.07 and its lamp while it is focused. Before the fix, the focus copy lost both. No exceptions in the session.

@JaXt0r
JaXt0r merged commit 02e6dec into develop Nov 24, 2026
@JaXt0r
JaXt0r deleted the fix/world-srp-batcher branch November 24, 2026 21:44
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.

2 participants