alpha blending and z sorting

Started by
9 comments, last by GameDev.net 18 years, 7 months ago
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
----------Thale Cres
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
yeah i tryed with alpha testing, and sure it works but gives bad looking edges :/
----------Thale Cres
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.
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 :(
----------Thale Cres
Try rendering the transparent objects after the opaque ones, with alphablending and zbuffer enabled and zwrite disabled.
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
----------Thale Cres
Maybe you just have to play with blend modes a bit..
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.

This topic is closed to new replies.

Advertisement