Changue a single color using shaders

mimusic

Member
This is what's known as "palette swapping," which is the act of taking an image with predefined colors and swapping them out for another set of predefined colors.

A simple (yet not so time-effective) way to do this would be to figure out the RGB of each color in the original sprite you want to swap, and map those to a new colour based on the palette you want. IE:
Code:
//Fragment Shader
rgb = texture2D( gm_BaseTexture, v_vTexturecoord );
if (rgb == rgbOfLightGreen) {
   fragColor = newRgbYouWant1; //This would be the lighter colour you want
} else
if (rgb == rgbOfDarkGreen) {
   fragColor = newRgbYouWant2; //This would be the darker colour you want
}
And the 'newRgbYouWant' values would be determined based on if you want a red yoshi, blue yoshi, etc...

The method I mention is naive and is more to convey what the idea of palette swapping is meant to do. You probably shouldn't use it. I encourage you to look up palette swapping shaders and techniques.

If I were to do this myself, without googling anything, I'd probably lean towards a LUT (lookup table) which allows you to just use texture for your color swapping, instead of having to manually figure out the RGB of every single colour you're swapping in/out. But again, probably best to see what people have already figured out in the way of palette swapping on the GPU.
 
If you just want it to work well and not necessarily to create the paltte swapper yourself, Pixelated Pope has a great asset on itch-io and the marketplace:
https://pixelatedpope.itch.io/retro-palette-swapper

If you want to learn a shading language, you can start with my video tutorials (link in signature). Although I'm not covering a palette swapper. And I don't plan to since if I need one, I'm just going to use Pixelated Popes :)
 

mimusic

Member
@mimusic i figured out the rgb of all colors, but i dont know how to implement them, i already tried

i still dont know the shader language
If you don't have prior experience using shaders, I might instead recommend you take a look at an existing shader-based solution to palette swapping.
While I usually like to advocate for people learning new things and deeply understanding the code they're writing, learning GLSL or another language just to do palette swapping might be a big undertaking.
Might be better to learn some GLSL/Other shader language from somebody else's solution to this problem. There's even an existing (paid) GameMaker asset to do this exact thing.

If you do end up trying to write this yourself, just understand that the core concept of a palette swap is:
  1. Read a color's RGB and determine if it's one of the colors you want to swap
  2. Find the corresponding RGB for replacement
  3. Set the output color to be the replacement
 

Megax60

Member
If you don't have prior experience using shaders, I might instead recommend you take a look at an existing shader-based solution to palette swapping.
While I usually like to advocate for people learning new things and deeply understanding the code they're writing, learning GLSL or another language just to do palette swapping might be a big undertaking.
Might be better to learn some GLSL/Other shader language from somebody else's solution to this problem. There's even an existing (paid) GameMaker asset to do this exact thing.

If you do end up trying to write this yourself, just understand that the core concept of a palette swap is:
  1. Read a color's RGB and determine if it's one of the colors you want to swap
  2. Find the corresponding RGB for replacement
  3. Set the output color to be the replacement
sounds hard to learn, you know what? ill just make tj henry yoshi instead, im just making a stupid game anyway
 
Top