Shadow Pass Switch and Nanite - Source Code Question

From my research, the shadow pass switch material node doesn’t work with Nanite meshes. But I need the functionality it offers.

I have a tree with leaves on it. I want to place my foliage as instanced mesh but I don’t want leaves. So my previous solution was to disable just the leaves shadow casting in the material section in the static mesh actor. That no longer works with Nanite foliage, neither does the shadow pass switch.

So now comes my delve into source code. I wanted to figure out why this isn’t working. First, I found the hlsl of what the shadow pass switch was doing. It was just calling a function called “GetShadowReplaceState”

I then found that function in the source code. It just checks if “SHADOW_DEPTH_SHADER” Is defined in whatever render pass is currently happening on the material.

I found the spots where this was being defined in the shadow depth Vertex and pixel shading code, but from what I have researched and understand now, a Nanite mesh doesn’t pass through these same render passes?

So now my current problem. If it doesn’t pass through these passes, which passes does it use, where are those located in source, and is there a definition there that defines it’s a shadow pass that could be used in place of checking with the current definition of “SHADOW_DEPTH_SHADER”?

Bumping this topic as it is the only discussion I have found on this issue.

I cannot get the Shadow Pass Switch to work on meshes that have Nanite enabled and would like to find a work-around. Specifically I am using a material to occlude objects between the player and the camera, however I want the shadows to remain. When nanite is disabled on the mesh, all works as intended. However enabling nanite causes a “spotlight” effect where the ocluded material allows light to pass through it. This is the same behaviour the nanite-disabled mesh would have if the Shadow Pass Switch did not exist and was instead bypassed.

Video of Problem - The squares on left are nanite disabled, squares on right are nanite enabled. Other then nanite change the squares are exactly the same.

This is what my material looks like which is using the Shadow Pass Switch.