Is there *any* tool to unswizzle textures (from Switch games)?

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,089
Country
United States
I had thought to do some processing on the textures in a game recently, but ran into a really annoying problem right from the start. While I could extract the textures easily enough, they were swizzled for the Switch (or specifically for Tegra of course.) Interestingly enough it seems to be insanely hard to actually find anything out there to unswizzle Switch textures -- which is extremely strange because the actual mechanisms are well known with a lot of open source implementations in a lot of different projects. As I googled around I found several open source projects -- all of which have no releases and you're supposed to compile yourself with your fingers crossed as developers seem to have just tossed the code up then forgotten about it (so it may or may not even work with modern implementations.) I don't really know how to do that with most of them (I'm not a programmer) and if it doesn't just build from make in Linux/MSYS2/etc I can't do much with it. Especially one I ran into that is made in Rust, which I don't even know how to work with at all. Interestingly I see that there is code enough that stuff like Switch Toolbox can come with their own separate swizzle DLLs, so in theory at least such a thing could easily translate to a program designed to actually do that. Naturally Switch Toolbox won't actually let a user manually unswizzle a texture of course. (That would be too easy!) One post I ran across even tells people to write their own program to send the texture data to the code for unswizzling (I definitely can't do that!)

Of course a lot of tutorials deal with swizzling textures for the Switch. Most just use an old Noesis plugin which, interestingly enough, can swizzle textures, but refuses to unswizzle them even though it has a command specifically to do so. The swizzle command the tutorials reference is -ue4texungob. There is a -ue4texgob command too which you would think would mean the opposite. However, it means the same thing according to the --help reference. Interestingly, if you use -ue4texgob it just does nothing to a swizzled texture (not only does it not unswizzle, but the output is exactly the same as the original -- if it actually were swizzling it should produce a newly swizzled texture even more crazy than before, so instead it's apparently just doing nothing.)

So far the only mechanism I've been able to find is there is a program called "rawtex" which is designed to work with raw texture files. Unfortunately, the author seems to not be interested in doing any further development on it and never even bothered to make command line versions of either other unswizzle version (why they did a separate specific version instead of just having command line parameters is beyond me) and the software is very limited and can't really batch process Switch files (only PS4 since that's the only command line version they made for unswizzling.) Also, it doesn't work with non-raw files like PNGs/etc. In fact, I couldn't figure out how to produce an appropriate raw file for it to use on purpose. I was working with a Unity game, so I was able to just extract the texture raw via Unity Asset Studio and that worked, but if I tried something like saving the PNG as a raw image file via image viewer or editor the program couldn't work on it (or at least if it could I couldn't figure out how since even manually specifying resolution and format didn't work.) That's obviously a problem with anything where you can't extract the source raw like that such as basically anything else.

Is there really not just any simple program out there that can just simply take a PNG/whatever and unswizzle it -- preferably without jumping through a bunch of hoops to get there? If it could do both that would be especially great since the Noesis plugin is only intended to work with Unreal asset files so is a real pita to use.
 
Last edited by Nazosan,

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,265
Trophies
3
XP
12,026
Country
Poland
Is there really not just any simple program out there that can just simply take a PNG/whatever and unswizzle it
PNG? No, because after converting to PNG you're losing all informations needed to unswizzle it. Unswizzling MUST be done on raw texture with correct parameters since it is done on smallest block possible for used type of texture. For DXT1 is 8 bytes, for BC2-BC7 it is 16 bytes, for RGBA/BGRA is 4 bytes, etc. With PNG you are losing this info because of forced conversion to max 4 bytes block (32-bit).

Beside that BC textures are sometimes bigger than what game is using to get correct unswizzling. So your tool after converting to PNG may cut pixels to match what is provided in header, but this will make swizzled image broken.

If you will convert back PNG to BC to get correct unswizzling, you will get worse quality since BC textures are lossy.

And btw. PS4 command line version of rawtex is also not ideal. For example it crashes when trying to unswizzle BGRA8 image, GUI version doesn't have this issue.
 
Last edited by masagrator,

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,089
Country
United States
Oh I see. Somehow in all my searching about how swizzling works I never saw anyone say that. I was under the impression it was about the arrangement of the pixels themselves, but from what you're saying it's actually to do with how the data itself is arranged then?

Thanks for the info.
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,265
Trophies
3
XP
12,026
Country
Poland
Oh I see. Somehow in all my searching about how swizzling works I never saw anyone say that. I was under the impression it was about the arrangement of the pixels themselves, but from what you're saying it's actually to do with how the data itself is arranged then?

Thanks for the info.
Yup.
There is also an issue with block height. Textures with bigger height dimensions are treated differently. Some textures to simplify calculation of that are including in header power of 2 to how calculate block width.

here is a modified by me source code of fadEx that has proper C++ code calculating unswizzling. Issue is it doesn't calculate automatically correct height block since it takes hardcoded information from nltx texture. But it correctly rounds up width and height automatically.

https://github.com/masagrator/NXGameScripts/blob/main/Shin Hayarigami/nltxEx.cpp

It supports unswizzling 4 bytes, 8 bytes and 16 bytes blocks. After figuring out how block height is proportional to texture height (and I don't remember now if data block that equals to 1 pixel is a part of this issue) it could be used for making universal unswizzler.
 
Last edited by masagrator,

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,089
Country
United States
There is only one thing that still confuses me though. It seems the actual swizzling itself can be done on a PNG. In the past I had used this tutorial on importing textures into SMT5 on the Switch: https://gamebanana.com/tuts/14519 In the process you create a swizzled PNG which you import into Unreal and cook into a uasset to pak into a mod. So I'm guessing what it comes down to is the format itself can still be swizzled on its own which, I guess, means that it's more a deficiency in the various tools exporting the images that they lose such data in the process? Unreal is recompressing the imported PNGs as DDS internally (you select DXT1 or 3 depending) so I presume it must understand the swizzled import and properly handle it (unswizzle and reswizzle? I don't know.)

But regardless, now at least I know why I can't just get a plain PNG extract of a texture to edit from Unreal Asset Studio or UABE[A]. It seems RAW is necessary.

Ironically I found out I can't actually do the texture editing on the game I wanted anyway, but it's useful to learn this stuff for other games in the future.
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,265
Trophies
3
XP
12,026
Country
Poland
This trick with UE4 is what I have mentioned about converting back PNG to original texture format.
You can do that, but you must remember that DXT/BC textures are lossy.
 

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,089
Country
United States
Yeah. I wish I could avoid the lossiness, but there's only so much that can be done when you're modding a game's assets and don't have access to the original data. Honestly, when I look at textures extracted from these games it almost pains me how much quality even BC7 seems to lose. I actually have successfully used RGBA (maybe I should be using BGRA instead?) textures in some games as the engines just accept whatever they recognize, but of course that isn't ideal and does have a very slightly noticeable loading hitch in some cases even.

When I do a texture mod I keep my editing data in my editor's original format around and export fresh after each edit instead of editing the lossy output.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Xdqwerty @ Xdqwerty: good night