Opacity Mask Shadow with Pixel Depth Problem


I’m trying to achieve the same result of Uncharted 4 with the foliage so that the camera doesn’t clip with it. I did a material with a pixel depth node (even try the perInstanceFadeAmount with a different problem). The result I want is there as the foliage is dithering as the camera get close but the problem is there’s no shadow. As soon as I remove the pixel depth part the shadow is there? Is there a problem with using pixel depth and the shadow pass of the directional light?

the third image is the material function with the pixel depth and I multiply that to the opacity mask of the foliage

Any idea on the problem?


It seems like the shadow depth pixel shader is also multiplying the opacity mask by the pixel depth from the point of view of the light, and this is completely clipping the shadow away.

Instead of modifying the opacity mask, if you use the pixel depth to say tint the foliage a different color, does that work with the shadows? If so we’ll have to find a way to exclude the pixel depth addition for the shadow depth pixel shader.

  • Jack

Yes the shadow is there if I plug it in the base color.

So what is the solution to that?


You can add a Custom node to your material with the text “IsShadowDepthShader()” in it. That will return 1 when rendering shadow depths and 0 otherwise. You should only apply your pixel depth fade when not in the shadow depth pixel shader.

FWIW that function is defined in Common.usf and is declared like this, and seems to have been added to solve this exact problem:

// Experimental way to allow adjusting the OpacityMask for shadow map rendering of masked materials.
// Can be accessed with a Custom material node. If this turns out to be very useful we can expose as MaterialFunction
// and potentially expose other queries as well (e.g. SkeletalMesh, HitProxy, ).
// @return 0:no, 1:yes
float IsShadowDepthShader()
	return 1;
	return 0;

Great it works!