Pixel shader access to z-buffer's next pixel in queue
Hello, friends!
I am writing a fragment shader which uses transparency features and Z-Buffer.
I have convex model object (with obtrusive parts) for example cat body, partly transparent with opaque colored areas. And when I use 'ZWrite On', transparent patches overlaps colored, as they are not transparent for the same object parts and pixels (limbs), and colored parts cannot be seen through transparent parts of the same object. As I understand it is because of ZWrite enabled, and it renders pixels with Alpha = 0 in top of z-buffer (in front of camera). What I need is somehow to get my transparent pixels really transparent until next pixels in z buffer, but in the same time I don't need to be possible to see through whole object. I need only next pixel in z-buffer, behind that which I want make transparent. For example, when I turn off ZWrite, it's possible to see through all the mesh and very rear colored areas become visible in front, which is supposed to be behind and not visible.
Pictures for clearify:
Ear is transparent (alpha = 0) and it overlaps green colored rear body
ZWrite Off - which ruins all the idea, but in the same time partly solves problem with transparency
And I'll repeat, to appoint my desire - I need somehow to get access to Z-Buffer, and when rendering pixel, make it fallback to next pixel in z array in a case when I want to make it transparent. Or somewhat like this. Setting pixel to alpha = 0 in this case as it seems doesn't solve an issue.
So, do you, guys, have an ideas? Are there some workarounds for this? Thank you very much for you anwers!
Answer by huyakinemota · Oct 13, 2017 at 04:13 AM
this problem is solved by adding shader param: AlphaToMask On