Hello,
We are using Nanite + VSM. Our trees are rendered with Masked Materials. We see that the trees are a performance hit in the VSM system.
As a test, we swapped the trees to an Opaque material, and we see that the performance is significantly improved.
We would like to automate this material swap at runtime, so that during the Shadow Pass the trees render as Opaque, and during the Base Pass render as Masked.
Is there a way to switch materials for the Shadow Pass?
We do not wish to use a proxy mesh for the tree shadows.
And we do need Masked for Base Pass (we’ve already optimized the meshes to tightly fit the masked alpha). And full Opaque for Base Pass is not feasible.
Thanks in advance!
Hello,
Thank you for reaching out.
I’ve been assigned this issue, and we will be looking into a shadowing technique that meets these requirements for you.
Hello,
Thank you for your patience. We are still looing into your questions.
Hello,
Have you tried using the Material Expression Shadow Pass Switch to optimize your shadow pass for the Material?
[Image Removed]
Changing Materials between passes is not supported in the engine.
Please let us know if this helps.
Hi Stephen,
Thank you very much for the proposal !
The approach that you have suggested works quite well, and does help a lot.
However, we went a bit further and ended up using something that gives us better performance than the Shadow Pass Switch Material modification.
It requires an engine change. I will post this here in case it helps anybody 
In NaniteCullRaster.cpp, in function FRenderer::PrepareRasterizerPasses, inside CacheRasterizerPass lambda.
Detect when it’s preparing the rasterize pass for shadows, and if so, remove the pixel discard flag. Simplified code idea:
if (RenderFlags & NANITE_RENDER_FLAG_IS_SHADOW_PASS) { MaterialBitFlags &= ~NANITE_MATERIAL_FLAG_PIXEL_DISCARD; // Remove bit flag }
If you want per-Material granularity. You can add a per-Material option, store it into RasterPipeline at BuildNaniteMaterialBins function at PrimitiveSceneInfo.cpp, and this way you can read it at FRenderer::PrepareRasterizerPasses and turn off the flag only for certain Materials that have this option enabled.
I think we have both found a couple successful alternatives that can help other studios, depending on whether they want to modify the engine or not! 
Thank you again Stephen!
Hello,
Thank you for sharing your solution.
Can we close your case? You can always re-open it if you need additional assistance with the same issue.
Yes, of course, we can close it. Thanks for everything !!! 