Skip to content
Open
Show file tree
Hide file tree
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 @@ -490,7 +490,7 @@ private void PrepareItems()
Yaw = ToTrAngle(instance.RotationY),
Pitch = ToTrAngle(instance.RotationX),
Roll = ToTrAngle(-instance.Roll),
Color = new Vector4(instance.Color.X, instance.Color.Y, instance.Color.Z, 1.0f),
Color = new Vector4(instance.Color.X * 0.5f, instance.Color.Y * 0.5f, instance.Color.Z * 0.5f, 1.0f), // Normalize to 0...1 range
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability and to avoid repeating the normalization factor per-component, consider constructing this as new Vector4(instance.Color * 0.5f, 1.0f) (or a shared normalization helper) instead of multiplying X/Y/Z separately.

Suggested change
Color = new Vector4(instance.Color.X * 0.5f, instance.Color.Y * 0.5f, instance.Color.Z * 0.5f, 1.0f), // Normalize to 0...1 range
Color = new Vector4(instance.Color * 0.5f, 1.0f), // Normalize to 0...1 range

Copilot uses AI. Check for mistakes.
OCB = instance.Ocb,
Flags = unchecked((ushort)flags),
LuaName = instance.LuaName ?? string.Empty
Expand Down
22 changes: 11 additions & 11 deletions TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private Vector3 CalculateLightForCustomVertex(Room room, Vector3 position, Vecto
output += RoomGeometry.CalculateLightForVertex(room, light, position, normal, false, false);
}

return Vector3.Max(output, new Vector3()) * (1.0f / 128.0f);
// Normalize to 0...1 range
return Vector3.Max(output, new Vector3()) * (1.0f / 255.0f);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CalculateLightForCustomVertex still doesn’t reliably normalize into the 0..1 range: ambientColor is commonly passed as room.Properties.AmbientLight * 128, and AmbientLight is stored in a 0..2 range (so the max input here is 256). Dividing by 255 can therefore yield values > 1.0 even before adding other lights (e.g. 256/255 ≈ 1.0039), and it’s also inconsistent with the rest of the file which normalizes via * 0.5f (i.e. effectively /256). Consider switching to a consistent /256 factor (or 0.5f / 128.0f) and clamping to Vector3.One if TombEngine strictly expects 0..1.

Suggested change
return Vector3.Max(output, new Vector3()) * (1.0f / 255.0f);
output = Vector3.Max(output, Vector3.Zero);
return Vector3.Clamp(output * (1.0f / 256.0f), Vector3.Zero, Vector3.One);

Copilot uses AI. Check for mistakes.
}

private TombEngineRoom BuildRoom(Room room)
Expand Down Expand Up @@ -167,7 +168,7 @@ private TombEngineRoom BuildRoom(Room room)
newRoom.AlternateKind = AlternateKind.BaseRoom;

// Store ambient intensity
newRoom.AmbientLight = room.Properties.AmbientLight;
newRoom.AmbientLight = room.Properties.AmbientLight * 0.5f; // Normalize to 0...1 range

// Room flags
if (room.Properties.FlagHorizon)
Expand Down Expand Up @@ -474,12 +475,12 @@ private TombEngineRoom BuildRoom(Room room)
// Apply Shade factor
color *= shade;
// Apply Instance Color
color *= staticMesh.Color;
color *= staticMesh.Color * 0.5f; // Normalize to 0...1 range
}
else
{
color = CalculateLightForCustomVertex(room, position, normal, false, staticMesh.Color * 128);
//Apply Shade factor
// Apply Shade factor
color *= shade;
}

Expand Down Expand Up @@ -623,8 +624,7 @@ private TombEngineRoom BuildRoom(Room room)
}
else
{
var color = room.Properties.AmbientLight;
trVertex.Color = color;
trVertex.Color = room.Properties.AmbientLight * 0.5f; // Normalize to 0...1 range
}

// HACK: Find a vertex with same coordinates and merge with it.
Expand Down Expand Up @@ -904,10 +904,10 @@ private TombEngineRoom BuildRoom(Room room)
Scale = instance.Scale,
ObjectID = checked((ushort)instance.WadObjectId.TypeId),
Flags = (ushort)(0x0007), // FIXME: later let user choose if solid (0x0007) or soft (0x0005)!
Color = new Vector4(instance.Color.X, instance.Color.Y, instance.Color.Z, 1.0f),
HitPoints = 0,
Color = new Vector4(instance.Color.X * 0.5f, instance.Color.Y * 0.5f, instance.Color.Z * 0.5f, 1.0f), // Normalize to 0...1 range
HitPoints = 0,
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a tab-indented line here (HitPoints = 0,) which is visually misaligned with surrounding entries (spaces) and will keep showing up as noisy diffs depending on editor settings. Re-indent this line consistently with the rest of the object initializer.

Suggested change
HitPoints = 0,
HitPoints = 0,

Copilot uses AI. Check for mistakes.
LuaName = instance.LuaName ?? string.Empty
}) ;
});
}

ConvertLights(room, newRoom);
Expand All @@ -921,7 +921,7 @@ private static int GetOrAddVertex(Room room, Dictionary<int, int> roomVerticesDi
var trVertex = new TombEngineVertex();

trVertex.Position = new Vector3(Position.X, -(Position.Y + room.WorldPos.Y), Position.Z);
trVertex.Color = color;
trVertex.Color = color * 0.5f; // Normalize to 0...1 range
trVertex.IsOnPortal = false;
Comment on lines 923 to 925
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalization is applied in multiple places via hard-coded * 0.5f factors (vertex colors, ambient light, instance colors, light colors). To reduce the risk of future inconsistencies (like the current /255 vs *0.5f mismatch), consider centralizing this into a small helper/constant (e.g., NormalizeTeColor(...)).

Copilot uses AI. Check for mistakes.
trVertex.IndexInPoly = index;

Expand Down Expand Up @@ -955,7 +955,7 @@ private void ConvertLights(Room room, TombEngineRoom newRoom)
(int)Math.Round(newRoom.Info.X + light.Position.X),
(int)-Math.Round(light.Position.Y + room.WorldPos.Y),
(int)Math.Round(newRoom.Info.Z + light.Position.Z)),
Color = light.Color,
Color = light.Color * 0.5f, // Normalize to 0...1 range
Intensity = light.Intensity
};

Expand Down
Loading