Alpha Blending issue
Hi guys & gals
i have a texture having black borders and contain some colors details in the middle part of the texture. i have this texture on my mesh and do alpha blending so that the black part become transparent while colored part of the texture remain the same. the code for alpha blending is like this
device.renderstate.alphablendenable = true;
device.renderstate.destinationblend = blend.one;
device.renderstate.sourceblend = blend.one;
this code causes the black part of the texture completely transparent which i want while colored part of the texture is also get transparent which i dont want at all. can any one plz help me out
What you're doing is an additive blend (dst = 1, src = 1).
This makes black fully transparent because black = 0, and anything + 0 is unchanged.
You want to use src = alpha, dst = inv_alpha (a.k.a 1-alpha)
This makes black fully transparent because black = 0, and anything + 0 is unchanged.
You want to use src = alpha, dst = inv_alpha (a.k.a 1-alpha)
BTW the generic formula for blending is
final colour = current colour * dst + texture colour * src
where final colour is the colour of a pixel after the draw,
current colour is the pixel before the draw,
and texture colour is the colour the pixel would become if blending wasnt enabled.
So if src and dst are both 1 then final colour = current + texture (which is additive blending, it just adds the colours).
Alpha blending works by making final colour = current*(1-alpha) + texture*alpha
This way if alpha = 75% (0.75), you get final colour = current*0.25 + texture*0.75
final colour = current colour * dst + texture colour * src
where final colour is the colour of a pixel after the draw,
current colour is the pixel before the draw,
and texture colour is the colour the pixel would become if blending wasnt enabled.
So if src and dst are both 1 then final colour = current + texture (which is additive blending, it just adds the colours).
Alpha blending works by making final colour = current*(1-alpha) + texture*alpha
This way if alpha = 75% (0.75), you get final colour = current*0.25 + texture*0.75
Since you are using color key mode, not alpha channel, don't forget to also set the color key to black when loading the texture. There is a tutorial right here.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement