Posted January 14, 2022 by MPStudios-Old
I have a big problem when it comes to life - I am a horrible perfectionist and hate being wrong on something. I so often get sidetracked on the small things that aren't the most important thing. One of these things for me is COLOR and PIXEL ART. How do I avoid this issue? Well, in previous projects (that I'm pretty sure I haven't published), I've implemented palette swapping. I am a big fan of GameBoy technical limits and I love the style the color limit creates. I have implemented a shader that does this. I've included all of the code above in an image. How it works will be explained below.
Palette Swap Shader
The shader contains four inputs:
The first two should be set by the creator, and the other two are to be set by the system when the user chooses the settings they want. (In reality, the system can/should set the first one too.) The fragment method in the shader goes through the following steps.
Lines 11-12 --> Get the original color and alpha value for each pixel in the sprite.
Lines 15-21 --> Get the size of the palettes we're working with, and prepare to loop through the palettes line by line. NOTE: If I were to use a larger palette, this might be a bit slow, but because I'm using small palettes, I'm not concerned.
Lines 22-32 --> Get the UV position we are at in the palettes. Get the proper color for the original palette, the new palette, and the universal palette. If the original color matches a given color in the original palette, we set it to the associated color in the new/universal palette (which one depends if the universal trigger is on).
Lines 36-38 --> Set the color to this new final color and set the alpha properly (just to avoid potential issues).
The Palettes Autoload
I have an autoload (just a gdscript called palettes.gd) that contains the following information:
There are a few main methods in this autoload:
Thankfully for now, I can just have generic colors and not worry about anything. I just have to add the shader to every element of the game that I have so far. Luckily, that's less than 20 (maybe less than 10) classes. Hopefully it doesn't take me too long. I will add photos to this devlog once the whole system is finished.
UPDATE (1/15/2022) - I've added images to demonstrate the system I've added.