I have created a fragment shader for sprites.
This shader provides a different way of coloring (tinting) sprites then
multiply. After tinting, the colors are always darker and you loose the highlights in the artwork.
So I am looking for something similar that translates colors into a vidid looking image that doesn’t dim out highlights. It basically pushes the gamma of each rgb channel in a different direction to get a vivid color grading.
The shader takes the input texture pixel and calculates a luma from it.
This luma value is then changed into a color value with one vec4 constant that I called gamma.
The rgb values of this constant manipulate the separate channels and the alpha alters the master gamma.
Based on a tutorial that @Pkeod made in the book of shaders although I think I took it in a different direction.
/*This shader provides a different way of coloring (tinting) sprites then
multiply.
Basically it takes a constant vec4, called gamma and pushes the gamma
of each channel separately to turn a grayscale sprite into vivid colors.
Theo Ybema
*/
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
// uniform lowp vec4 tint;
// Not using tint anymore!
uniform lowp vec4 gamma;
void main()
{
lowp vec4 tex_in = texture2D(texture_sampler, var_texcoord0.xy);
lowp float luma = 0.2126 * tex_in.r + 0.7152 * tex_in.g + 0.0722 * tex_in.b;
lowp vec4 tex_out = vec4(0.0);
luma = pow(luma, gamma.a);
tex_out.r = pow(luma,gamma.r);
tex_out.g = pow(luma,gamma.g);
tex_out.b = pow(luma,gamma.b);
gl_FragColor = vec4(tex_out.rgb,tex_in.a);
}
For me this works great. But I also have a question: I can’t get the same shader to work for GUI nodes. I get it working, by using the color constant as gamma, because GUI nodes don’t have set_constant. But the colors all wash out to white. So, is there something different about gui shaders?