grunt-lucas / porytiles

Overworld tileset compiler for Pokémon Generation 3 decompilation projects
MIT License
30 stars 3 forks source link

Wrong palettes+tiles in metatiles when trying to reuse general primary tiles in a custom secondary tileset #46

Closed SPMoo66 closed 4 months ago

SPMoo66 commented 4 months ago

After decompiling the general primary tileset for use with a custom secondary tileset it seems that any generated metatiles that should be reusing existing general tiles/palettes may be incorrect. All metatiles using custom palettes/tiles seem to be created correctly. I am using dual-layer tiles, if that helps at all.

Command used to decompile general primary tileset: porytiles decompile-primary -o $HOME/general $HOME/pokeemerald-expansion/data/tilesets/primary/general $HOME/pokeemerald-expansion/include/constants/metatile_behaviors.h

Command being used to compile the secondary tileset: porytiles compile-secondary -dual-layer -Wall -o $HOME/pokeemerald-expansion/data/tilesets/secondary/snow $HOME/porytiles-snow $HOME/general $HOME/pokeemerald-expansion/include/constants/metatile_behaviors.h

Here are the bottom/middle/top images used in compilation bottom middle top

Environment (please complete the following information):

grunt-lucas commented 4 months ago

This is perfect, thanks. Should be everything I need to attempt a reproduction. I am pretty busy for the next week or so, but after that I will definitely make time to look in to this. I want to do a 1.0.0 release this year (it's been in beta forever), and fixing bugs is my top priority for that release.

Just looking at what you are doing, I have a suspicion I know what the problem is. It may not be a bug per se, but it's definitely a really nasty "gotcha" that users should not have to deal with. So either way, there's potential for improvement here.

grunt-lucas commented 4 months ago

@SPMoo66 Ok looking more carefully at your post. When you decompile the primary general tileset to make changes, you need to recompile it, and import that recompiled primary general as a new tileset in Porymap. So you'll effectively have two primary general sets. The vanilla one, and a recompiled-with-porytiles one. Then you have to make sure that any map in Porymap that is compiled via Porytiles, and which uses one of your custom secondary sets (like the snow one), are using the recompiled-with-porytiles general set, not the original vanilla one. Otherwise you're going to get in to all kinds of trouble.

Porytiles completely reorders tiles.png and the .pal files. So when you compile a custom secondary set, it will be "linked" to the recompiled-with-porytiles primary set, not the vanilla one. If you try to use the vanilla one in Porymap, the tile and palette references won't line up and that's what causes the artifacting.

I know this isn't very well explained at the moment, sorry for the confusion. I am still trying to fill out more of the wiki pages, and eventually have some kind of video tutorial series.

Please go ahead and give the above steps a try. If that fixes your problem, I'll close this issue. But I've opened a new feature issue to track some possible improvements, since I don't think what Porytiles is doing here is a good user experience.

SPMoo66 commented 4 months ago

Recompiling the tileset as you recommend fixed the artifacting, but I did have an issue with dual vs triple layer and had to manually edit all the decompiled images. It appears that the default decompile command is for triple-layer tilesets and it doesn't seem like the -dual-layer argument works for decompile as it does for compiling. If you just take the decompiled tileset and recompile as dual-layer you get a tileset with a bunch of the transparency color covering up the tiles. I was able to fix this temporarily by blowing away all the transparency colors on the middle and top images, but I imagine this wouldn't be what you want users to be doing. If I did just miss something simple in recompiling the tileset, please let me know.

I'm assuming that recompiling a decompiled tileset works well for triple-layer tilesets, but I didn't test it myself.

grunt-lucas commented 4 months ago

@SPMoo66 The decompile command automatically detects the compiled layer type and adjusts accordingly. When it decompiles a dual-layer set, in places where there was no tile information at all (e.g. the middle tile of a SPLIT metatile), it generates a tile with all pixels set to alpha=0.

This problem you described, was it when you decompiled the vanilla primary set? And recompiled it? The reason you probably had this issue is because, annoyingly, different palettes in the original vanilla primary general set use different transparency colors. The Porytiles decompiler is technically OK with this, it assumes you know what you're doing when you go to recompile things. But Porytiles compilation only supports a single transparency color, which means you either have to manually fix up the tileset (like you did), or supply the decompiler with -normalize-transparency, which will change all transparency in the original tileset to the 255 0 255 magenta color.

Go ahead and try decompiling again, this time with -normalize-transparency. See if it fixes everything, and then we can finally mark this closed :)

grunt-lucas commented 4 months ago

Oh also, the compiler allows you to adjust which color is treated as transparency via the -transparency-color option. This works fine for some vanilla sets, which sometimes use 0,0,0 or 24,41,82 for transparency. However, many tend to mix and match transparency colors across the palettes. So it's usually better to just decompile with -normalize-transparency[=<RGB>] to change all transparency to a color of your choice

SPMoo66 commented 4 months ago

Adding -normalize-transparency worked perfectly. Thank you so much for all of the help!

grunt-lucas commented 4 months ago

Awesome! I'll close this issue. But I opened #47 to track improvements to some of the rough edges you discovered. Thanks!