• Advertisement
Sign in to follow this  

Alpha Blending issue

This topic is 4216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement