Skip to content

Commit

Permalink
Fix terrain lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 3, 2024
1 parent f522b95 commit 13568d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
31 changes: 2 additions & 29 deletions CentrED/Map/LandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,6 @@ public void UpdateId(ushort newId)
}
}

public void UpdateRightCorner(float z)
{
if (AlwaysFlat(Tile.Id) || Application.CEDGame.MapManager.FlatView)
return;

Vertices[1].Position.Z = z * TILE_Z_SCALE;
UpdateId(Tile.Id); //Reassign same Id, to reconsider art vs tex
}
public void UpdateLeftCorner(float z)
{
if (AlwaysFlat(Tile.Id) || Application.CEDGame.MapManager.FlatView)
return;

Vertices[2].Position.Z = z * TILE_Z_SCALE;
UpdateId(Tile.Id);
}

public void UpdateBottomCorner(float z)
{
if (AlwaysFlat(Tile.Id) || Application.CEDGame.MapManager.FlatView)
return;

Vertices[3].Position.Z = z * TILE_Z_SCALE;
UpdateId(Tile.Id);
}

private Vector4 GetCornerZ()
{
var client = Application.CEDClient;
Expand Down Expand Up @@ -224,9 +198,8 @@ private bool CalculateNormals(out Vector3[] normals)
var isStretched = false;
isStretched |= CalculateNormal(LandTile, t10, t21, t12, t01, out normals[0]);
isStretched |= CalculateNormal(t21 ?? LandTile, t20, t31, t22, LandTile, out normals[1]);
isStretched |= CalculateNormal(t22 ?? LandTile, t21, t32, t23, t12, out normals[2]);
isStretched |= CalculateNormal(t12 ?? LandTile, LandTile, t22, t13, t02, out normals[3]);

isStretched |= CalculateNormal(t12 ?? LandTile, LandTile, t22, t13, t02, out normals[2]);
isStretched |= CalculateNormal(t22 ?? LandTile, t21, t32, t23, t12, out normals[3]);
return isStretched;
}

Expand Down
12 changes: 6 additions & 6 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ public MapManager(GraphicsDevice gd)
var landBlock = block.LandBlock;
ushort minTileX = (ushort)(landBlock.X * 8);
ushort minTileY = (ushort)(landBlock.Y * 8);
for (ushort x = minTileX; x < minTileX + 8; x++)
for (ushort x = minTileX ; x < minTileX + 8; x++)
{
if(x == 0 || minTileY == 0) continue;

var newZ = landBlock.Tiles[LandBlock.GetTileIndex(x, minTileY)].Z;
LandTiles?[x - 1, minTileY - 1]?.UpdateBottomCorner(newZ);
LandTiles?[x, minTileY - 1]?.UpdateLeftCorner(newZ);
LandTiles?[x - 1, minTileY - 1]?.Update();
LandTiles?[x - 1, minTileY - 2]?.Update();
}
for (ushort y = minTileY; y < minTileY + 8; y++)
for (ushort y = minTileY ; y < minTileY + 8; y++)
{
if(y == 0 || minTileX == 0) continue;

var newZ = landBlock.Tiles[LandBlock.GetTileIndex(minTileX, y)].Z;
LandTiles?[minTileX - 1, y - 1]?.UpdateBottomCorner(newZ);
LandTiles?[minTileX - 1, y]?.UpdateRightCorner(newZ);
LandTiles?[minTileX - 1, y - 1]?.Update();
LandTiles?[minTileX - 2, y - 1]?.Update();
}
UpdateLights();
};
Expand Down

0 comments on commit 13568d9

Please sign in to comment.