From 1e75697dc82ea25494f27ea5ab74c7ad878372c9 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 22 Nov 2026 20:29:59 +0000 Subject: [PATCH] fix: carpets and other VOBs on the street next to houses are no longer black - only a VOB standing on light mapped ground takes the lightmap's light ApplyWorldLight took the nearest light mapped cells up to 8 m around a VOB, also above it. Abuyin's carpets in Khorinis lie on the vertex lit street under a house's light mapped overhang: they got the overhang's black lightmap. Like the engine (the ground polygon's light), the VOB now needs light mapped cells right under its bottom; worlds lit mostly by lightmaps (mines) keep the old search. --- .../Services/World/StationaryLightsService.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs b/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs index c3d4fcc2b..256e5441c 100644 --- a/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs +++ b/Assets/Gothic-Core/Scripts/Services/World/StationaryLightsService.cs @@ -373,6 +373,15 @@ public void ApplyWorldLight(GameObject vobGo) foreach (var renderer in renderers) bounds.Encapsulate(renderer.bounds); + // Like the engine's VOB light (the ground polygon's light): only a VOB standing on light mapped ground takes + // it. Abuyin's carpets in Khorinis lie on the vertex lit street under a house's light mapped overhang - the + // nearest cells (up to 8 m, also above) were the overhang's black lightmap, the carpets turned black. + if (!_isMostlyLightmapped && !HasLightmappedFloor(bounds)) + { + LogVobWorldLightSkip(vobGo, "not standing on light mapped ground"); + return; + } + var light = SampleWorldLight(bounds); LogVobWorldLight(vobGo, bounds, light); if (!light.HasValue) @@ -429,6 +438,22 @@ private void LogVobWorldLight(GameObject vobGo, Bounds bounds, Color? light) /// The average lightmap light of the light mapped cells around the bounds' center and bottom (3x3x3 cells each), /// null if there are none - outdoors the sun lights the VOB. /// + /// + /// A light mapped cell right under the VOB's bottom (its own 2 m cell or a neighbor, the floor level or one below). + /// + private bool HasLightmappedFloor(Bounds bounds) + { + var bottom = new Vector3(bounds.center.x, bounds.min.y, bounds.center.z); + for (var x = -1; x <= 1; x++) + for (var y = -1; y <= 0; y++) + for (var z = -1; z <= 1; z++) + { + if (_lightmapCells.ContainsKey(ToCell(bottom + new Vector3(x, y, z) * _cellSize))) + return true; + } + return false; + } + public Color? SampleWorldLight(Bounds bounds) { // Ring by ring (2 m cells) up to _vobLightMaxRings - a bridge over a chasm has its walls a few meters away.