Export indexed color as uv-coordinate pixels and a palette lookup texture

It would be nice to be able to export an indexed-colors image to an image with red-green channels representing UV-coordinates alongside an exported texture that those UV coordinates can be used to perform a lookup on.

This video may explain the end-goal easier than I could: Pixel Art Animation. Reinvented - Astortion Devlog - YouTube

For those who just want a summary of the video:
There’s a growing trend of pixel artists using a cool technique for palette swapping that integrates well with modern game engine shader abstractions. The basic idea is to hijack the red and green channels of an image and use them as UV coordinates instead of color data. A shader can then easily grab the r and g channels and use them to look up coordinates on a palette texture. That texture can be swapped or edited, making the palette swap super simple in most game engines. (Generally the alpha channel maintains it’s use, modifying the texture’s color result with transparency.)

I’m not sure Aseprite (or any other graphics editor) has enough information to do this automatically.

While it’s a very interesting technique, it seems to me that these red-green pixels that represent UV coordinates on a texture would need to be placed manually.
As far as I know, with a 3D model you can “unwrap” it to get the surface to create the texture on but a 2D image doesn’t have much information in about drawn shapes so that’s not really an option.

I hope I’m wrong and this magic can be automated but I can’t see any way to achieve it.

@thkwznk , you’re right that it doesn’t have enough info to do a pretty, logical-looking texture (as the video shows,) but it could very easily do a more crude version. It would just take exporting the indexed palette as an image (which it can already do,) then translate each palette index into the UV coordinates, which would be simple mod-wrap math. The palette would need to be square-ified, but I imagine that’s not a far leap from the current palette exporting.

If someone did want the palette to look more logical, the person could maybe just make an even square number of indexed colors in the palette editor, then hand-set each to more logical patterns that kinda match the character or whatever.

I have written a few addons already, so maybe I’ll attempt to do this in lua one of these days. It’ll definitely be a bit more work than my other scripts, though.

What would be the difference between this solution and an image with indexed colors + a palette? :thinking:

Most modern game engines can’t import indexed colors. It’s just not really that standardized. The indexed version also doesn’t work well with modern shader abstractions, so you have to almost bake images or something. It’s a mess.

Doing this newfangled way uses existing image importers and a single, simple shader.

It essentially is indexed colors, just in a more manageable format


I see, in this case, that effort would be worth it since I don’t think a script to generate these will be too complex.