gzliner.blogg.se

Galford palette swap
Galford palette swap








galford palette swap

The swap texture, with the color at index 25 set to blue. If we want to swap this color, then in the swap texture we need to set the pixel at index 25 to the color we want the outline to be: blue. The outline color is the last one on the palette-the one with a red value of 25. Let's say we want to replace the outline/eye color (black) on the sprite with the color blue. Here are the red color values of the sprite palette's colors: This means that the swap texture will need to be 256 pixels wide, because that's how many different values the red component can take. The big question is, how do we link the color from the sprite texture to the color from the swap texture? The answer is, we'll use the red (R) component from the RGB color to index the swap texture. Instead, we will use an additional texture, which will contain the replacement colors. We would definitely like to avoid any conditional statements entirely, in fact. However, this doesn't scale well for many colors, and is quite an expensive operation.

Galford palette swap code#

Now, let's think about how we could swap these colors inside a shader.Įach color has a unique RGB value associated with it, so it's tempting to write shader code that says, "if the texture color is equal to this RGB value, replace it with that RGB value". There are quite a few colors on this texture. Here's the example texture we're going to use to demonstrate the shader: I downloaded this texture from, and edited it slightly. (The other characters all use the same sprite, but have been similarly recolored.) Click Hit Effect to make the characters all flash white briefly. Use the color pickers to recolor the top character. You can check out the Unity demo, or the WebGL version (25MB+), to see the final result in action. In this tutorial, we'll create a simple color swapping shader that can recolor sprites on the fly. The shader makes it much easier to add variety to a game, allows the player to customise their character, and can be used to add special effects to the sprites, such as making them flash when the character takes damage.Īlthough we're using Unity for the demo and source code here, the basic principle will work in many game engines and programming languages.










Galford palette swap