From 6b652d29e9960e4325c0b64f9421c748d43b7c5e Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 23 Nov 2026 02:09:36 +0000 Subject: [PATCH] perf: the world and its VOBs are SRP batched - Lit/World's _FocusBrightness was outside UnityPerMaterial and ~1900 VOBs had a MaterialPropertyBlock Co-Authored-By: Claude Opus 5.5 --- .../Services/World/StationaryLightsService.cs | 12 +++++++----- Assets/Gothic-Core/Shaders/Lit-World.shader | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs b/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs index c3d4fcc2b..ea89703d8 100644 --- a/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs +++ b/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs @@ -307,7 +307,6 @@ public void ClearWorldChunks() public bool IsWorldLit(Renderer renderer) => _worldLitRenderers.Contains(renderer); // Lightmap light per cell (ToCell) of the light mapped world polygons, sampled at their centers by WorldMeshBuilder. private readonly Dictionary _lightmapCells = new(); - private MaterialPropertyBlock _vobLightBlock; /// /// The lightmap light of the world's light mapped polygons per cell (rgb summed, w = polygon count). @@ -378,15 +377,18 @@ public void ApplyWorldLight(GameObject vobGo) if (!light.HasValue) return; - _vobLightBlock ??= new MaterialPropertyBlock(); var tint = new Vector4(light.Value.r, light.Value.g, light.Value.b, 1f); foreach (var renderer in renderers) { if (renderer is MeshRenderer meshRenderer && IsWorldChunk(meshRenderer)) continue; - renderer.GetPropertyBlock(_vobLightBlock); - _vobLightBlock.SetVector(_vobLightTintShaderId, tint); - renderer.SetPropertyBlock(_vobLightBlock); + // Into the renderer's own materials (each has its own - UpdateRenderer writes its light indices there + // too), not a MaterialPropertyBlock: the SRP batcher skips renderers with one, ~1900 VOBs in Khorinis + // were drawn one by one. + renderer.GetSharedMaterials(_rendererMaterials); + foreach (var material in _rendererMaterials) + if (material != null) + material.SetVector(_vobLightTintShaderId, tint); _worldLitRenderers.Add(renderer); } } diff --git a/Assets/Gothic-Core/Shaders/Lit-World.shader b/Assets/Gothic-Core/Shaders/Lit-World.shader index 1a0f2d4f2..5cdd9b9ec 100644 --- a/Assets/Gothic-Core/Shaders/Lit-World.shader +++ b/Assets/Gothic-Core/Shaders/Lit-World.shader @@ -31,8 +31,6 @@ Shader "Lit/World" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" - float _FocusBrightness; - struct appdata { float4 vertex : POSITION; @@ -68,6 +66,8 @@ Shader "Lit/World" SAMPLER(sampler_WorldLightmaps); float _WorldLightmapBrightness; + // Every material property in here, the same in every pass - else the SRP batcher skips the world and + // draws it chunk by chunk. CBUFFER_START(UnityPerMaterial) float4 _MainTex_TexelSize; int _StationaryLightCount; @@ -75,6 +75,7 @@ Shader "Lit/World" float4x4 _StationaryLightIndices2; float _WindStrength; float4 _VobLightTint; + float _FocusBrightness; CBUFFER_END #include "GothicIncludes.hlsl"