PDA

View Full Version : render order + alpha blending



chronozphere
07-03-2007, 07:38 PM
Hi all.

I have implemented billboarding in my engine and now i want to test it by creating a small piece of land with grass billboards on it.
But this wasn't as easy as i thought. :(

As Usual i'll provide a picture:

http://img231.imageshack.us/img231/8973/billboardoverlapproblemwl8.jpg

Most of the texture used for this billboard is transparent.
When rendered, the transparent pixel Z coords are written to the zbuffer. so when an billboard is rendered behind this one, a whole corner is cut away by the alpha-ed part of another billboard. :(

Can i prevent alpha-ed pixels from being added to the zbuffer??
Or is there an other sollution? :?

Does anyone have better grass/tree billboard textures because this one sucks. A good tutorial might be even better. :)

Thanx in advance.

Clootie
07-03-2007, 11:04 PM
You could use alpha test to kill pixels that should not be rendered at all. But probably this will not solve your problem as non-transparent parts still put their Z-coordinates (which is constant as I understand) in Z-buffer. It will be more correctly to render background first and when your flower/grass decals with Z-test enabled and Z-write disabled (and probably with alpha test still enabled).

LP
08-03-2007, 04:14 AM
The solution is what you put as the topic of this thread: to order your billboards by depth. Just sort them by their z value and draw from back to front. This will only work for billboards that are oriented towards the camera though.

Huehnerschaender
08-03-2007, 08:50 AM
I had the same problems when working on my grassengine.

Ordering by Z-Buffer would help here, but the more grass-billboards you have, the more CPU-Power you need to order the billboards (you have to order every frame!). So if its just <100 then no problem, but with thousands it will decrease your performance a lot!

I "solved" this problem just by setting Alpharef to 254 befor rendering the grass and resetting Alpharef to 1 after rendering.

This of course can cause other artifacts, but for my needs it was ok.

chronozphere
08-03-2007, 05:01 PM
Thanks for the alphatesting tip. that's what i was looking for :)

I've read on MSDN that from back-to-front rendering is computational expensive, because of the many zbuffer/framebuffer manipulations required, so i'm not very keen on fixing it that way.

But i still have crappy looking billboards. When i set alpharef to 255 and the comparison function to greaterequal then my billboards look more like heads of lettuce. :(

Does anyone know how to make good billboards/textures??
I like to know some good texture resources but tutorials are probably better if anyone knows one. :?

tpascal
09-03-2007, 03:36 PM
I've read on MSDN that from back-to-front rendering is computational expensive, because of the many zbuffer/framebuffer manipulations required, so i'm not very keen on fixing it that way.


Drawing back-to-front with the zbuffer enabled has no sense coz the pixel rejection will never happen; so if you are going to sort the traingles your self then dissable the zbuffer.

You only need to sort the visible alphablended triangles, and draw them after the opaques ones.

I think people at some point need to sort triangles by texture or by stages anyway, so including the alphablend attrib in the sorting criteria is not big deal.