Jump to content
  • Advertisement
Sign in to follow this  
remigius

[MDX] 'Billboard' alpha / zbuffer problem

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

Hello, I'm working on a little program to learn how to create some effects in DirectX. For this demo, I was planning to create a forest of trees, but at the moment rendering even one tree is a challenge :/ For the trees I just created 6 quads with my tree texture and incrementally rotated them 60 degrees. I needed the 6 quads because I don't want to change the cull mode and only 4 quads looked messy with my changing lighting. Anyway, now I am having some problems with alpha blending and z-buffering. When the camera is in the right position, part of the tree is occluded by nothing because a quad was rendered before the quad behind it. Hopefully this image makes the problem more clear: From my search on these boards and google, this happens quite a lot and the most common solution is to disable Z-Buffering on alpha blending objects. I figured render order sorting wouldn't help me here, because the tree's quads all have the same location. So I disabled the Z-buffer for the trees, butwhen I do this, the trees will show trough other objects when they are in fact behind those and thus should not be rendered... To solve this problem I decided I did need some render order sorting, so I implemented a simple sorter for my render list, so it will render objects far away from the camera first. The render list is sorted ok, but when I try it this happens: So basically all trees that are further from the camera than the tent are not rendered. I tripplechecked my code, but they are still in the render list and just should be rendered. The only thing I can think of which could be causing these problems it that I had to enable the Z-Buffer for the tent to prevent flikkering/depth fighting between the ten and the terrain. The strange thing is though that the terrain, sky plan and tent all use Z-buffering (I can enable and disable this per scene object)... So if it is really the Z-buffered tent that is causing these problems, why isn't the terrain causing any problems?? Does anyone have any idea what could be groing wrong? Or better yet, does anyone know an alternative for this? I did read a bit about alpha testing instead of alpha blending, but it seems a bit of a workaround than a true solution. I was thinking that I could implement some special render code for the trees that will render the quad that is most perpendicular to the camera 'look vector' last, so the 'background quads' are already rendered and the effect is less noticable. Could work, but it seems like a rediculous amount of work for this... The last I could think of would be rotating a single quad to face the camera, but this looks crap when moving the camera :/ Anyone? :)

Share this post


Link to post
Share on other sites
Advertisement
Ok, I finally got it working... sort of. The problem was that the terrain was occluding the trees. I added a switch that allows me to override the render order, so the terrain and the sky will always be rendered first:



Still, if anyone could offer a more robust and/or easier method to get the same or a similar effect, please feel free to post it here :)

Share this post


Link to post
Share on other sites
When using just one quad, exactly why did it look off? Some lighting problems could simply be solved by setting the normals of the quad correctly, and then letting the lighting engine produce a slightly rounded looking shading. If you want to create a forrest this would cut down a lot on your geometry and also on the drain caused by filling in so many alpha textured objects.

Share this post


Link to post
Share on other sites
Quote:

From my search on these boards and google, this happens quite a lot and the most common solution is to disable Z-Buffering on alpha blending objects

You typically want to disable Z-WRITES, but you still want to leave Z reading enabled.

Share this post


Link to post
Share on other sites
Quote:
Original post by intrest86
When using just one quad, exactly why did it look off? Some lighting problems could simply be solved by setting the normals of the quad correctly, and then letting the lighting engine produce a slightly rounded looking shading. If you want to create a forrest this would cut down a lot on your geometry and also on the drain caused by filling in so many alpha textured objects.


Well, maybe it's just me, but it looks too obivous that the quads are being rotated. Plus I kinda dislike using a technique I first saw in the original Wolfenstein ;) Perhaps with proper lighting convincing results could be produces, but I think I'll stay with my 6 quads for now and see how it goes.


Quote:

You typically want to disable Z-WRITES, but you still want to leave Z reading enabled.


Again my problem is basic reading :) Thanks DrunkenHyena, this seemed to remove the problem with the tree quads overlapping and occluding eachother. Still, I need to draw the terrain and sky (with ZWrite enabled) before the trees, otherwise they will overlap the trees. Is this normal, or am I doing something else wrong?

Share this post


Link to post
Share on other sites
Well, alpha blending is a really dificult task in rendering images usaing a Zbuffer. There is a rellative simple way to resolve some of these problems.

You must render the opac and trnasparent objects separatly. Activate the zwrite and the ztest and render the opac objects. Then, disable the zwrite and render the transparent objects. This way, opac objects are rendered well and transparent objects are well ocluded by opac objects. The problem is that trnasparrent object do not oclud each other. The solution is to sort the qauds back to front.
Unfortenatly, you have a big problem. Your quads do intercept each others. You cannot resolve this by just sorting the quads. One possible problem is, maybe, to render 12 quads instead of 6. In another words, you cut each quad by its center. This way, you remove the interception and you can sort them. Unfornetaly, this my be a very intensicve task for your pc if not done well.

A god way to resolve the problem is to use the alpha testing. In fact, an alpha tested quad is an opac quad and you don't need any fancy tecquine to render them and, contrary to what you did say, it's a good solution and not only an work around. In fact, you can have less problems, more perfomance and even better results with it. You can have better results becase alpha test does create solid edges and creates complex forms. Alpha blending just blurs the edges. If you have good textures for trees, maybe alpha testing if better for you.

Share this post


Link to post
Share on other sites
Well, alpha blending is a really dificult task in rendering images usaing a Zbuffer. There is a rellative simple way to resolve some of these problems.

You must render the opac and trnasparent objects separatly. Activate the zwrite and the ztest and render the opac objects. Then, disable the zwrite and render the transparent objects. This way, opac objects are rendered well and transparent objects are well ocluded by opac objects. The problem is that trnasparrent object do not oclud each other. The solution is to sort the qauds back to front.
Unfortenatly, you have a big problem. Your quads do intercept each others. You cannot resolve this by just sorting the quads. One possible problem is, maybe, to render 12 quads instead of 6. In another words, you cut each quad by its center. This way, you remove the interception and you can sort them. Unfornetaly, this my be a very intensicve task for your pc if not done well.

A god way to resolve the problem is to use the alpha testing. In fact, an alpha tested quad is an opac quad and you don't need any fancy tecquine to render them and, contrary to what you did say, it's a good solution and not only an work around. In fact, you can have less problems, more perfomance and even better results with it. You can have better results becase alpha test does create solid edges and creates complex forms. Alpha blending just blurs the edges. If you have good textures for trees, maybe alpha testing if better for you.

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!