Questions about alpha blending

Started by
4 comments, last by MikeyO 18 years, 8 months ago
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.
Advertisement
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08
http://blog.protonovus.com/
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...
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
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.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Yay, thank you jolly jeffers, that solved my particle issue.

This topic is closed to new replies.

Advertisement