diff --git a/src/LightManager.Illuminate.cpp b/src/LightManager.Illuminate.cpp index 76c425f..405a3ac 100644 --- a/src/LightManager.Illuminate.cpp +++ b/src/LightManager.Illuminate.cpp @@ -879,34 +879,35 @@ return (cornerLights [0] != 0.0) || (cornerLights [1] != 0.0) || (cornerLights [ void CLightManager::SetObjectLight (bool bAll, bool bDynSegLights) { double fLight = m_fObjectLight / 100.0; - long nLight = D2X (fLight) * 12; //24.0 * 327.68); + // SegmentTool scales light values by about 12. I don't really know why, and haven't found anything + // that explains it in D1/D2 source, but it looks about right when examining in-built levels. + // So leaving it like this for now. + long nLight = D2X (fLight) * 12; undoManager.Begin (__FUNCTION__, udSegments); int nSegments = segmentManager.Count (); for (int si = 0; si < nSegments; si++) { CSegment* pSegment = segmentManager.Segment (si); - if (!bDynSegLights) { - if (bAll || (pSegment->IsTagged ())) + if (bAll || (pSegment->IsTagged ())) { + if (!bDynSegLights) { pSegment->m_info.staticLight = nLight; - } - else { - int l = 0; - int c = 0; - CSide* pSide = pSegment->m_sides; - for (short nSide = 0; nSide < 6; nSide++) { - if (bAll || pSide->IsTagged ()) { - for (short nCorner = 0; nCorner < 4; nCorner++) { - uint h = (uint) pSide [nSide].m_info.uvls [nCorner].l; - if (h || !pSide->IsVisible ()) { - l += h; + } + else { + int l = 0; + int c = 0; + CSide* pSide = pSegment->m_sides; + for (short nSide = 0; nSide < 6; nSide++) { + if (pSide->FaceCount () > 0) { + for (short nCorner = 0; nCorner < pSide->VertexCount (); nCorner++) { + l += pSide [nSide].m_info.uvls [nCorner].l; c++; } } } + pSegment->Backup (); + // Multiply by an extra 2 because of how corner lights are scaled (65536 = 200%) + pSegment->m_info.staticLight = c ? D2X (fLight * (X2D (l) / (double) c)) * 2 * 12 : nLight; } - pSegment->Backup (); - // Segment light values seem to be higher than corner light values - factor of about 12 - pSegment->m_info.staticLight = (int) (c ? fLight * ((double) l / (double) c) * 2 * 12 : nLight); } } undoManager.End (__FUNCTION__);