That headline was a little long shot. This post is about shading with shader programs. Here is the case:
In Smacklings, if both players chooses same character, in some cases it might be difficult to tell which one you are controlling.
Solution? Alter the colors of one of the characters. Three different ways comes to mind how to do it. First one is to create two different image asset sets with other having altered colors. Takes twice as much space but gets the job done.
Second option is to use default shader's color alteration abilities. Most of the game engines ship default shader that has a field called color. Usually has a white color assigned to it. Every pixel is then multiplied by that color and by multiplying with white the art is displayed using its original colors. Turn the color-field blue and your art will have blue tint on it. Problem with that solution is that your art becomes darker and it is just tinted.
Third solution is - like you would expect by now - is to write your own shader. With that it is possible do all kinds of tricks with the color. Want to inverse colors? Turn everything gray? Shift the colors? Can do. Color shifting is what we decided to go with.
Theory
Generally we computer guys separate color into three components, Red, Green and Blue. But there is also other representation, HSV. Hue, Saturation and Value. In that case Hue dictates the color of the pixel without caring how dark (Value) it is or how much there is color (Saturation). Hue is represented as an angle ranging from 0 to 360. By pushing that component same amount for every pixel alters their color, but the effect is very different than multiplying with another color.
There wont be tint towards one color. Instead all the colors shift same amount but the end result is based on what color it originally was. Red pixels may become blue, blue pixels green and green pixels red, for example.
The effect is applied on image below.
That technique is pretty common and it shouldn't be too difficult to find a complete shader for your game engine.
0 comments