diff --git a/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs b/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs index 03f1c953..10ffb38a 100644 --- a/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs +++ b/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs @@ -884,26 +884,17 @@ namespace Toolbox.Library if ((sourcePixel & 0x8000) == 0x8000) { a = 0xFF; - r = (byte)((sourcePixel & 0x7C00) >> 10); - g = (byte)((sourcePixel & 0x3E0) >> 5); - b = (byte)(sourcePixel & 0x1F); - - r = (byte)((r << (8 - 5)) | (r >> (10 - 8))); - g = (byte)((g << (8 - 5)) | (g >> (10 - 8))); - b = (byte)((b << (8 - 5)) | (b >> (10 - 8))); + r = Expand5to8((sourcePixel >> 10) & 0x1F); + g = Expand5to8((sourcePixel >> 5) & 0x1F); + b = Expand5to8(sourcePixel & 0x1F); } //Alpha bits else { - a = (byte)((sourcePixel & 0x7000) >> 12); - r = (byte)((sourcePixel & 0xF00) >> 8); - g = (byte)((sourcePixel & 0xF0) >> 4); - b = (byte)(sourcePixel & 0xF); - - a = (byte)((a << (8 - 3)) | (a << (8 - 6)) | (a >> (9 - 8))); - r = (byte)((r << (8 - 4)) | r); - g = (byte)((g << (8 - 4)) | g); - b = (byte)((b << (8 - 4)) | b); + a = Expand3to8(sourcePixel >> 12); + r = Expand4to8((sourcePixel >> 8) & 0x0F); + g = Expand4to8((sourcePixel >> 4) & 0x0F); + b = Expand4to8(sourcePixel & 0x0F); } dest[destOffset + 0] = b; @@ -911,6 +902,23 @@ namespace Toolbox.Library dest[destOffset + 2] = r; dest[destOffset + 3] = a; } + + //From noclip https://github.com/magcius/noclip.website/blob/e5c302ff52ad72429e5d0dc64062420546010831/src/gx/gx_texture.ts + private static byte Expand5to8(int n) + { + return (byte)((n << (8 - 5)) | (n >> (10 - 8))); + } + + private static byte Expand4to8(int n) + { + return (byte)((n << 4) | n); + } + + private static byte Expand3to8(int n) + { + return (byte)((n << (8 - 3)) | (n << (8 - 6)) | (n >> (9 - 8))); + } + #endregion public static Tuple EncodeFromBitmap(System.Drawing.Bitmap bitmap, TextureFormats Format, PaletteFormats PaletteFormat = PaletteFormats.RGB565) diff --git a/Toolbox/KclMaterialPresets/Mario Kart 8.json b/Toolbox/KclMaterialPresets/Mario Kart 8.json new file mode 100644 index 00000000..7ed3fae1 --- /dev/null +++ b/Toolbox/KclMaterialPresets/Mario Kart 8.json @@ -0,0 +1,31 @@ +{ + "GameTitle": "Mario Kart 8 Wii U / Deluxe", + "PrismThickness": 30.0, + "SphereRadius": 25.0, + "MaterialPresets": { + "0": "Road", + "2": "Road (Bumpy)", + "4": "Road (Slippery)", + "6": "Road (Offroad Sand)", + "9": "Road (Slippery Effect Only)", + "10": "Road (Booster)", + "16": "Latiku", + "31": "Glider", + "32": "Road (Foamy Sound)", + "40": "Road (Offroad, clicking Sound)", + "56": "Unsolid", + "60": "Water (Drown reset)", + "64": "Road (Rocky Sound)", + "81": "Wall" + "129": "Road (3DS MP Piano)" + "134": "Road (RoyalR Offroad Grass)" + "161": "Road (3DS MP Xylophone)" + "193": "Road (3DS MP Vibraphone)" + "227": "Road (SNES RR road)" + "297": "Road (MKS Offroad Grass)" + "500": "Road (Water Wall)" + "4096": "Road (Stunt)" + "4106": "Road (Booster + Stunt)" + "4108": "Road (Stunt + Glider)" + } +} \ No newline at end of file diff --git a/Toolbox/KclMaterialPresets/Mario Odyssey.json b/Toolbox/KclMaterialPresets/Mario Odyssey.json new file mode 100644 index 00000000..12dcf596 --- /dev/null +++ b/Toolbox/KclMaterialPresets/Mario Odyssey.json @@ -0,0 +1,7 @@ +{ + "GameTitle": "Mario Odyssey", + "PrismThickness": 40.0, + "SphereRadius": 0.0, + "MaterialPresets": { + } +} \ No newline at end of file diff --git a/Toolbox/KclMaterialPresets/Splatoon 1.json b/Toolbox/KclMaterialPresets/Splatoon 1.json new file mode 100644 index 00000000..241502c0 --- /dev/null +++ b/Toolbox/KclMaterialPresets/Splatoon 1.json @@ -0,0 +1,8 @@ +{ + "GameTitle": "Splatoon 1", + "PrismThickness": 30.0, + "SphereRadius": 25.0, + "MaterialPresets": { + "0": "Unknown", + } +} \ No newline at end of file diff --git a/Toolbox/KclMaterialPresets/Splatoon 2.json b/Toolbox/KclMaterialPresets/Splatoon 2.json new file mode 100644 index 00000000..b7377e19 --- /dev/null +++ b/Toolbox/KclMaterialPresets/Splatoon 2.json @@ -0,0 +1,8 @@ +{ + "GameTitle": "Splatoon 2", + "PrismThickness": 30.0, + "SphereRadius": 25.0, + "MaterialPresets": { + "0": "Unknown", + } +} \ No newline at end of file diff --git a/Toolbox/Toolbox.csproj b/Toolbox/Toolbox.csproj index 0d79113e..72505daf 100644 --- a/Toolbox/Toolbox.csproj +++ b/Toolbox/Toolbox.csproj @@ -183,6 +183,18 @@ Resources.resx True + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest +