SFML community forums

Help => Graphics => Topic started by: CJ_COIMBRA on August 21, 2013, 04:24:59 pm

Title: Sprite.SetColor issue
Post by: CJ_COIMBRA on August 21, 2013, 04:24:59 pm
Hi.

I am having a bit of a problem on this situation: I have an animation with a few frames that should be reused with different tints but I couldn“t match any of the colors the designer provided as RGB values. I did some reading on the subject and it seems that SetColor multiplies the current color of the sprite by the provided values.

Sample image to be tinted
(http://www.spacecatstudio.com/tests/impact_00000.png)

Colors that I want to achieve after using SetColor (the characters are irrelevant please ignore them)
 (http://www.spacecatstudio.com/tests/color_chart.jpg)

So how can I get the correct RGB values to use with SetColor in order to get my desired colors?

Thanks.
Title: Re: Sprite.SetColor issue
Post by: fallahn on August 21, 2013, 04:45:34 pm
Have you tried making the original image to be tinted greyscale? Then you should be able to set it to any colour you like. Alternatively this frag shader should work ( although I haven't tested it)


#version120

uniform sampler2D texture;
uniform vec4 tintColour;

void main()
{
        //get greyscale value
        vec4 texColour = texture2D(texture, gl_TexCoord[0].xy);
        float amount = dot(texColour.rgb, vec3(0.299, 0.587, 0.114));
       
        //set pixel to tint multiplied by value
        gl_FragColor = vec4(vec3(tintColour.rgb * value), texColour.a);
}
 
Title: Re: Sprite.SetColor issue
Post by: FRex on August 21, 2013, 04:48:07 pm
Did you try making your image white/gray and setting colors on it instead? That might be better.
In normalized 0..1 color values it's:
original.r * vertex.r = result.r
same for other channels. You have original and result so you can find vertex.
Title: Re: Sprite.SetColor issue
Post by: CJ_COIMBRA on August 23, 2013, 09:23:56 pm
Quote
Did you try making your image white/gray and setting colors on it instead? That might be better.

Thanks for the suggestions. This was the way to go.