A question about occlusion and materials that 'discard' pixels

This is kind of an academic question since I am getting the behaviour I want but not entirely sure why… :slight_smile: I just want to check something isn’t happening behind my back, so to speak.

Anyway, let’s say I have a large mesh, and I’m applying a material that discards some of the pixels. The material is set to be opaque, but it’s using ‘clip(-1.0)’ for certain pixels.

Anyway, when I was testing with this, I was kind of expecting that the occlusion engine would be using the mesh as is, and thus would make objects behind this mesh not visible, despite the fact that some pixels are being discarded and can be seen through.

But it seems not - thankfully, I can still see through the discarded pixels on the mesh to objects behind.

Is the engine doing something implicitly here? Is it turning my material into a translucent one and rendering this object in another pass or turning off occlusion for the object that it’s applied to? I’m just wondering what’s going on even though it’s doing what I want it to do.


Because if you clip pixels, they probably are not written to depth buffer. So when another object (behind this object) gets drawn, the depth test will succeed and will render correctly.

It could be. I am not an expert in this area. Have you looked at the source code and see what happens there?

That makes sense, but I was thinking there might be an occlusion pass earlier in the pipeline? On the CPU side even? For example, if you use world position offset in a material you are warned that vertex offsets won’t be accounted for in occlusion culling. so you might have unexpected occlusions in a case like that…which I guessed suggested some culling earlier on in the pipe.

Both of the realtime occlusion methods used in UE4 right now are based on the depth buffer (occlusion query and HZB) so they handle masked materials correctly. However, they have one frame of latency which is something we would like to avoid. When you come around a corner, meshes will pop into view sometimes.

The precomputed visibility that you probably won’t need to use doesn’t support masked though because the occlusion tests are done on the CPU. It treats any masked materials as completely transparent for correctness.

Thank you!