Tint a sprite red

I've had good success in tinting sprites a certain color by using this code:

_sprite.Draw( _texture,
 new Rectangle( 0, 0, (int)_width, (int)_height ),
 new Vector3( 0.0f, 0.0f, 0.0f ),
 new Vector3( (int)_left, (int)_top, 0.0f ),
 Color.FromArgb( 255, 255, 128, 128 ) ); // Reddish tint

The problem is, black parts of the sprite don't change at all, which is really bad, because some of my sprites are silhouettes; and are therefore completely black - and they aren't effected by the red tint at all.

I need a way to tint the while thing red; black parts included. And because parts of the sprite are transparent, I can't just draw a transparent red box over the whole sprite. Any suggestions




Answer this question

Tint a sprite red

  • matii

    You can use a more complex thing: Use Texture Shaders

    //YOUR FX FILE:
    float4 TintRed( float2 inTexCoord : POSITION, float2 inTexelSize : PSIZE ) : COLOR
    {
    return float4(1,0,0,1) // your red color, but you can create more complex things
    }


    Now it is just use D3DXCompileShader( "TintRed", "tx_1", 0, &TintRedFunction, NULL, NULL ); // TintRed Function is a LPD3DXBUFFER, convert it to a LPD3DXTEXTURESHADER.

    Finally use D3DXFillTextureTX to apply your shader to a texture and then use it.

  • Sean Bales

    Actually, I came up with my own answer. Make the sprite completely white, and normally draw it with RGB of 0,0,0 so that it still appears black.

  • justMaveric

    Brandon Amoroso wrote:

    I need a way to tint the while thing red; black parts included. And because parts of the sprite are transparent, I can't just draw a transparent red box over the whole sprite. Any suggestions



    You should be able to multiply the red box's transparency by the sprite's alpha. That should do the trick.

    (Though the solution of using white seems simpler and therefore better.)

  • Tint a sprite red