I feel like an absolute idiot for asking this. But how exactly do safely draw the depth of a fragment featuring a Masked ( Alpha 1) texture on it's surface?

So far I've literally been doing a depth test on truly opaque geometry.

enter image description here

Here's a logarithic Z-bufer from GTA. And yes... it's strange that I know that and how to do it... but not a alpha mask depth.

EDIT: From this, it looks like it's actually possible to write solid texture data to the depth buffer, and ignore the binary transparency.

Here's an image that's an example of the problem I would like to solve.

enter image description here


In the case of a masked texture, only fully opaque pixels should update the depth buffer. Any pixel that is partially or completely transparent should not update the depth buffer. Updating the depth buffer will prevent pixels of greater depth from being drawn/calculated, and pixels with alpha need to blend with pixels in the background. If no blending occurs, then you update the depth buffer, otherwise skip it.

  • \$\begingroup\$ Alright, so if you're using a shader to mask a texture, you can still submit the geometry normally, and the hardware will handle the depth pass for you then? \$\endgroup\$ – moonshineTheleocat Jul 5 '16 at 1:36
  • \$\begingroup\$ Unless you are doing something unusual, that should be the case, yes. Either way, it sounds like I misunderstood your original question. I had understood that you were trying to render the depth buffer as pixels, and were asking how you would render the depth buffer for visualization purposes. The depth pass is normally done as a separate pass. The depth of each of the pixels you are rendering is tested ahead of time, and a fragment shader should only called on pixels that are actually being rendered. \$\endgroup\$ – Tom K Jul 5 '16 at 2:49
  • \$\begingroup\$ I'm missing something here then... I edited the OP to show an example of the issue I'm getting. But I am running a deferred renderer, and trying to keep the over draw down as much as possible. A good portion of my scene uses these "Cutout" style transparencies to save on geometry and to stylize. \$\endgroup\$ – moonshineTheleocat Jul 5 '16 at 8:02
  • \$\begingroup\$ Alright, I got it all figured out now. I was missing some details that weren't being explained in the documentation. DX 10 and 11 do not have alpha testing. It must be implemented by the shader by testing via clip from the pixel shader stage. Which in turn stops early Z-testing, and uses the de-facto Z test for that object. \$\endgroup\$ – moonshineTheleocat Jul 6 '16 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.