Jump to content
  • Advertisement
Sign in to follow this  
MikeyO

Questions about alpha blending

This topic is 4860 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

For the life of me I have not been able to figure out a few things involving alpha blending.. First, I don't understand how I can have particles which will go in front of objects that are behind them while also being able to go behind objects that are in front of them, while still being able to fade (using black as they alpha color). It would be nice if particles that should be behind an object would look that way. Secondly, I don't know how to 'fade' objects which uses the alpha component of it's color for blending.. I can only really get it to turn black (but then it looks like a black outline of the particle). Lastly, I don't know how to blend 3d models so that things behind (that are not transparent) are affected by the color. For example, in the following picture, the teapot is in the foreground and is supposed to be transparent, while the torus is behind it and supposed to be affected by the greenish hue of the teapot (since you're looking at the torus through the teapot). Perhaps someone could point me to some tutorial (which I cannot find from google for some reason), or tell me how I can do one or two of the above things. Much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
From that picture,. it looks almost like the torus is in front. My gues is that Z-sorting is shut off. This means that is the torus is drawn after the teapot (regardless of its location in 3D space) it will be drawn over the teapot. The easiest solution is to just draw the tepot after the pot.

The more complicated (though not very) is to just enable a Z-Buffer.

I am assuming you are using directX (by the forum). What version and what language? I may be able to give you a couple code snippets...

Share this post


Link to post
Share on other sites
Well, I'm using Managed DirectX (9, C#), but any source you decide post will be helpful I'm sure :D.

And yes, the Zbuffer is disabled.. I found that if I had it enabled I got some odd results.

Share this post


Link to post
Share on other sites
Alpha blending is draw order dependent - from the sounds of it you've just got this wrong [smile]

When the GPU performs the blending algorithm it will take whatever is currently stored in the render target as the destination colour; which will basically be whatever (if anything) that has already been rendered.

Conceptually you should be rendering all your OPAQUE geometry first - preferablly front-to-back, but it doesn't really matter.

Then you should go back and render all semi-transparent objects in back-to-front order.

Rendering semi-transparent objects correctly requires at least some degree of sorting - ideally on a per-triangle basis, but thats not realistic for realtime applications ([wink]). Usually sorting by the depth of the object and then doing a back-face and front-face pass will look acceptable.

For particle systems it's conventional to use Z-Test but not Z-Write.

hth
Jack

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!