Incorrect colour blending when using a pixel shader with XNA

Posted by MazK on Game Development See other posts from Game Development or by MazK
Published on 2013-03-08T03:34:59Z Indexed on 2013/11/05 10:15 UTC
Read the original article Hit count: 546

Filed under:
|
|
|
|

I'm using XNA 4.0 to create a 2D game and while implementing a layer tinting pixel shader I noticed that when the texture's alpha value is anything between 1 or 0 the end result is different than expected.

The tinting works from selecting a colour and setting the amount of tint. This is achieved via the shader which works out first the starting colour (for each r, g, b and a) :

float red = texCoord.r * vertexColour.r;

and then the final tinted colour :

output.r = red + (tintColour.r - red) * tintAmount;

The alpha value isn't tinted and is left as :

output.a = texCoord.a * vertexColour.a;

The picture in the link below shows different backdrops against an energy ball object where it's outer glow hasn't blended as I would like it to. The middle two are incorrect as the second non tinted one should not show a glow against a white BG and the third should be entirely invisible.

The blending function is NonPremultiplied.

enter image description here

Why the alpha value is interfering with the final colour?

© Game Development or respective owner

Related posts about 2d

Related posts about xna-4.0