Disabling Z-write for Alpha pixels
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
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.
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
Thanks!
Marvin
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
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
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement