Color, Pixel Art, & Perfectionism


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:

  1. the original palette - the palette that is used to color the sprites
  2. the new palette - the palette that will replace the original colors
  3. the universal palette - I want the ability for the player to choose to have either a normal GameBoy Color aesthetic where each sprite can only have a 4-color palette (one of which is usually transparent) or original GameBoy feel where the entire thing is only 4 colors. If the universal palette is to be used, this is the palette that is used rather than the new palette.
  4. a trigger to use either the new or universal palette

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:

  • all possible shaders in the game (stored in a json format); these shaders can be re-used
  • all possible palettes in the game (also stored in a json format); these palettes can be re-used
  • a universal trigger that sets if the whole game uses one 4-color palette (stored as.. you guessed it - a boolean)

There are a few main methods in this autoload:

  • set_base_palette - each of your sprites should be designed in one common palette. In my case, I use a 4-color grayscale base. If you need to guarantee all of your shaders use the same base, you can call this method and it will change the base palette in each shader in the json.
  • trigger_universal - this will turn on/off the use of the universal palette and then set each shader to obey this request.
  • set_universal_palette - does the same as base palette but for the universal palette.


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.

Leave a comment

Log in with itch.io to leave a comment.