Skip to content

Commit

Permalink
Improved rendering precision
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Jan 30, 2025
1 parent dc5047d commit 35d401f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
13 changes: 5 additions & 8 deletions CentrED/Map/LandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,11 @@ public void UpdateId(ushort newId)

Texture = spriteInfo.Texture;
var bounds = spriteInfo.UV;


float onePixel = Math.Max(1.0f / Texture.Width, Epsilon.value);

var texX = bounds.X / (float)Texture.Width + onePixel / 2f;
var texY = bounds.Y / (float)Texture.Height + onePixel / 2f;
var texWidth = bounds.Width / (float)Texture.Width - onePixel;
var texHeight = bounds.Height / (float)Texture.Height - onePixel;

var texX = bounds.X / (float)Texture.Width + Epsilon.value;
var texY = bounds.Y / (float)Texture.Height + Epsilon.value;
var texWidth = bounds.Width / (float)Texture.Width - Epsilon.value;
var texHeight = bounds.Height / (float)Texture.Height - Epsilon.value;

var texCoords = new Vector3[4];
var applyLightingFlag = useTexMap ? 0.00001f : 0f;
Expand Down
21 changes: 10 additions & 11 deletions CentrED/Map/StaticObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public void UpdateId(ushort newId)
Texture = spriteInfo.Texture;
TextureBounds = spriteInfo.UV;

float onePixel = Math.Max(1.0f / Texture.Width, Epsilon.value);
var texX = TextureBounds.X / (float)Texture.Width + onePixel / 2f;
var texY = TextureBounds.Y / (float)Texture.Height + onePixel / 2f;
var texWidth = TextureBounds.Width / (float)Texture.Width - onePixel;
var texHeight = TextureBounds.Height / (float)Texture.Height - onePixel;
var texX = TextureBounds.X / (float)Texture.Width;
var texY = TextureBounds.Y / (float)Texture.Height;
var texWidth = TextureBounds.Width / (float)Texture.Width;
var texHeight = TextureBounds.Height / (float)Texture.Height;

Vertices[0].Texture = new Vector3(texX, texY, 0f);
Vertices[1].Texture = new Vector3(texX + texWidth, texY, 0f);
Expand All @@ -84,13 +83,13 @@ public void UpdatePos(ushort newX, ushort newY, sbyte newZ)
var posX = newX * TILE_SIZE;
var posY = newY * TILE_SIZE;
var posZ = flatStatics ? 0 : newZ * TILE_Z_SCALE;

float halfProjectedWidth = TextureBounds.Width * 0.5f * RSQRT2;

var projectedWidth = (TextureBounds.Width / 2f) * RSQRT2;

Vertices[0].Position = new Vector3(posX - projectedWidth, posY + projectedWidth, posZ + TextureBounds.Height);
Vertices[1].Position = new Vector3(posX + projectedWidth, posY - projectedWidth, posZ + TextureBounds.Height);
Vertices[2].Position = new Vector3(posX - projectedWidth, posY + projectedWidth, posZ);
Vertices[3].Position = new Vector3(posX + projectedWidth, posY - projectedWidth, posZ);
Vertices[0].Position = new Vector3(posX - halfProjectedWidth, posY + halfProjectedWidth, posZ + TextureBounds.Height);
Vertices[1].Position = new Vector3(posX + halfProjectedWidth, posY - halfProjectedWidth, posZ + TextureBounds.Height);
Vertices[2].Position = new Vector3(posX - halfProjectedWidth, posY + halfProjectedWidth, posZ);
Vertices[3].Position = new Vector3(posX + halfProjectedWidth, posY - halfProjectedWidth, posZ);
}

public void UpdateHue(ushort newHue)
Expand Down

0 comments on commit 35d401f

Please sign in to comment.