Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
/// </summary>
/// <summary>
/// A light mapped cell right under the VOB's bottom (its own 2 m cell or a neighbor, the floor level or one below).
/// </summary>
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.
Expand Down