• Advertisement
Sign in to follow this  

alpha blending and z sorting

This topic is 4521 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, im having some problems with alpha blending. been looking around for solutions but cant find any. say i got two objects, a and b, where a is behind b. b is (partially) transparent. now if b is rendered before a, the z-buffer clipping thinks that a doesnt need to be rendered, and therefore the transparents parts of b just shows me the background instead of a. if i turn off z-clipping a is rendered above b which is even worse. now to solve this i implemented simple zsorting based on objects (ie i sort the objects, not the faces) but it didnt help much since objects is often too complicated (example the ground which can have a pit with objects in it). so my question is, do i need to create some complicated zsorting-by-face stuff (which seems like something that would be really slow to me) or is there any better solution to my problem? thanx in advance /chot

Share this post


Link to post
Share on other sites
Advertisement
I believe alpha testing would work for you. Basically it tests the transparency value of each pixel - you can set the test to allow the pixel to be written only if it is not transparent.

I use OpenGL so I'm not sure exactly what code you need. Perhaps google/this might help?
msdn page

Share this post


Link to post
Share on other sites
yeah i tryed with alpha testing, and sure it works but gives bad looking edges :/

Share this post


Link to post
Share on other sites
Maybe you could edit your object texture so that the border around the transparent region has some semi-transparent pixels, to blend the border edge with the background when it is rendered.

Share this post


Link to post
Share on other sites
well they do have such a texture, the problem with alphatesting is that its digital, either a pixel is drawn or not, it doesnt blend :(

Share this post


Link to post
Share on other sites
Try rendering the transparent objects after the opaque ones, with alphablending and zbuffer enabled and zwrite disabled.

Share this post


Link to post
Share on other sites
well thats kind of what im doing now, but still if two transparent object occlude each other there migth be some strange effects :(
currently im drawing the solid objects first then the transparent, and the transparent is zsorted. it works but as i said sometimes gives strange results

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Maybe you just have to play with blend modes a bit..

Share this post


Link to post
Share on other sites
If two transparent objects occlude each other or a single transparent object occludes itself, then you can't sort by object. You have to sort the faces. Even sorting the faces doesn't work if two transparent faces intersect.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
soon or later you will need to sort your faces anyway, for example every book will tell you should group your faces by textures to minimize the texture stage changes. If you are going to do a realtime like-a-game app you will found later that you need at some point to do some proccesing to every faces before rendering (checking frustum, distance from camera, etc) so in fact there are a lot things to do for every frame, sorting your faces are not big deal.

Currently that is what i am doing, sorting my faces by at least texture,distance (some other stages changes can be including in the sorting if needed), you should google a quicksort rutine, it is very fast.

tp.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The last anonymous poster is WAY WRONG for today's hardware. NEVER work triangle-by-triangle. In many cases, you can get a decent sort by first rendering the back faces, then the front faces of your transparent models (by setting the culling, of course). Disabling Z-write for some of your transparent models can make the sorting errors less obvious.

Share this post


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

  • Advertisement