Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite.SetColor issue  (Read 2388 times)

0 Members and 1 Guest are viewing this topic.

CJ_COIMBRA

  • Full Member
  • ***
  • Posts: 112
    • ICQ Messenger - 13077864
    • View Profile
    • http://www.cjcoimbra.com
    • Email
Sprite.SetColor issue
« 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


Colors that I want to achieve after using SetColor (the characters are irrelevant please ignore them)
 

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

Thanks.
CJ

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Sprite.SetColor issue
« Reply #1 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);
}
 
« Last Edit: August 21, 2013, 04:58:01 pm by fallahn »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Sprite.SetColor issue
« Reply #2 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.
Back to C++ gamedev with SFML in May 2023

CJ_COIMBRA

  • Full Member
  • ***
  • Posts: 112
    • ICQ Messenger - 13077864
    • View Profile
    • http://www.cjcoimbra.com
    • Email
Re: Sprite.SetColor issue
« Reply #3 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.
CJ

 

anything