Fixed up textures in UI

This commit is contained in:
Jan Racek
2026-03-26 17:27:10 +01:00
parent 5fffcea6cf
commit a8aa674a9c
2 changed files with 27 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ namespace SplashEdit.RuntimeCode
/// </summary>
public static class PSXUIExporter
{
/// <summary>
/// <summary>
/// Collect all PSXCanvas components and their child UI elements,
/// converting RectTransform coordinates to PS1 pixel space.
/// Also collects and deduplicates custom fonts.
@@ -242,6 +242,8 @@ namespace SplashEdit.RuntimeCode
if (img.PackedTexture != null)
{
PSXTexture2D tex = img.PackedTexture;
// Convert PackingX from VRAM halfwords to texture-pixel U coords.
// 4bpp: 4 pixels per halfword, 8bpp: 2, 16bpp: 1
int expander = 16 / (int)tex.BitDepth;
data.TexpageX = tex.TexpageX;
data.TexpageY = tex.TexpageY;
@@ -249,7 +251,8 @@ namespace SplashEdit.RuntimeCode
data.ClutY = (ushort)tex.ClutPackingY;
data.U0 = (byte)(tex.PackingX * expander);
data.V0 = (byte)tex.PackingY;
data.U1 = (byte)(tex.PackingX * expander + tex.Width * expander / ((int)tex.BitDepth / (int)PSXBPP.TEX_4BIT));
// Width is already in source pixels = texture-pixel units
data.U1 = (byte)(tex.PackingX * expander + tex.Width);
data.V1 = (byte)(tex.PackingY + tex.Height);
data.BitDepthIndex = tex.BitDepth switch
{