Jump to content
  • Advertisement
Sign in to follow this  
Wicked Ewok

Disabling Z-write for Alpha pixels

This topic is 4776 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 there, I'm rendering a 2D scene using Ortho in a front to back way to optimize the speed at which the program renders since there are a lot of overlapping layers. First, here's a screenshot of what goes wrong: http://www.spaceartist.net/screen5.jpg I'm rendering the background first(the blue water), then I'm rendering the rocks. The rocks overlap a lot, but I would only like the completely 100% opaque surfaces to not be touched again after render. This part works, but the portions of the texture where it is translucent also are never touched again. Since my Z compare is ZFUNC_LESS, when alpha is drawn, the Z is set and subseqeunt rendering on that pixel fails. This results in those blue edge lines you see. The solution is simple if it exists in D3D, which is what I would like to know. I want to disable Z writes for pixels being written that have an alpha value that is less than 255. Is this possible? I do not want to overdraw the whole sprite when alpha is only in the perimeter of the sprite. Thanks! Marvin

Share this post


Link to post
Share on other sites
Advertisement
I don't know of any way to do that, but what most people do to achieve the effect you want is to first render the completely opaque stuff back-to-front (not necessary but improves performance) with Z-Write on, and then sort the transluscent stuff to render front-to-back with Z-Write off as it is no longer needed to write to the Z-Buffer.

Share this post


Link to post
Share on other sites
Hi Kamikaze, yes I believe that is the usual way to render, but essentially, all sprites have alpha on them, but just at the edges(and real fading alpha here, not something I can alpha test away). I would be forced to overdraw on every sprite, which I don't want to do. I think it will really lag on older cards.

Thanks!
Marvin

Share this post


Link to post
Share on other sites
Oh I just had an idea..but I'm not sure if it is supported on other cards:

enable ZWrite
using Alpha test set to exclude pixels with < 255 alpha
Draw to depth buffer only
disable ZWrite
Turn off Alpha test
Draw regularly Front to Back

Will that work guys?

Thanks!
Marv

Share this post


Link to post
Share on other sites
You have to draw twice:

1) draw with Z write, alpha-rejecting all pixels with alpha < 255
2) draw without Z write, alpha-rejecting all pixels with alpha >= 255

Note that this probably won't do what you want, though. For blending, you really need to render far-to-near.

Also, using Z write reduces the effectiveness of early Z and hierarchical Z, so overdraw acceleration (available on most modern graphics cards) won't actually kick in.

Share this post


Link to post
Share on other sites
hplus0603, yes thanks, that works. Since it's a 2D engine performance shouldn't be a problem for modern cards. But are these renderstates even compatible with older cards?

D3DRS_ALPHAREF
D3DRS_COLORWRITEENABLE
D3DRS_ZWRITEENABLE

Would these work on Intel Cards? And if they don't work, then reverting to back to front drawing would still be very slow on older cards:/

Thanks!
Marvin

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!