Early Z Pass switch?

In the material graph there is a node called ShadowPassSwitch that can be used to specify different logic in the shadow passes.

Is there a way to do the same thing for the Early Z / depth pass?

I have expensive pixel shader logic that determines both the color / normals and opacity mask of my objects, and there is a lot of empty / masked space in them. I want to be able to define a simplified version of the shader for the depth pre pass to avoid then running the main shader for each pixel

I think that depth passes are depth only passes. In other words, the shader should only be executing instructions that are relevant for depth testing. These are World Position, Opacity/Mask, Pixel Depth Offset and Displacement. I don’t think you should have to manually optimize this, and a quick peek at the shader source code supports this.

Normal maps and base color should be skipped automatically. Opacity however, cannot be skipped in a depth pass automatically or manually.

1 Like

i was just googling aswell and snooping around in renderdoc (i’m totally new to that one and it does not give me stepped visual representation i need to understand this). apparently ue4.x has a material switch to compute opacity in the early z-pass. i reckon this would update the depth buffer.

in theory you draw whatever anyway. if a pixel is alpha masked aka empty it would write it’s depth and flag like a stencil bit and continue to draw polygons. if the next one is in front it will simply overwrite depth to be more in front. if it’s in the back it will check the bit and it will update to it’s own depth if it’s 0.

the depth write will always occur if a change is happening. front or back. so… the depth pass will have the same overdraw. for sure will not execute the whole surface shader.