When creating a standard instanced static mesh using an actor, there are both Min Draw Distance
and Nanite Pixel Programmable Distance
settings in the details panel. These sort of work but there are issues. The biggest issue is that this only works on blueprint actors, as these descriptors don’t seem to be exposed to PCG or the foliage tool static mesh spawners.
The Min Draw Distance setting can theoretically be used to spawn two meshes in the same spot - one being drawn near and the other being drawn far. By setting the Min Draw distance of the far proxy (ie opaque mesh) as the same as the max for the nearby hero asset (ie masked mesh), they can seamlessly swap at the desired distance.
The Nanite Pixel Programmable Distance disables any pixel programs (such as opacity masking) beyond a certain distance.
Spawning an actor in PCG with a max Nanite Pixel Programmable Distance set does seem to work, but is not appropriate for foliage and many other cases. It also doesn’t seem to impact the shadow pass properly in my test (mesh still appeared masked in shadows after switching opaque in main).
The Min Draw Distance setting didn’t seem to work properly with actors spawned in PCG.
Hopefully these descriptors can be exposed to PCG and the foliage tool and also hopefully LOD style features (such as swapping meshes, materials, shadow casting) by distance is added to nanite in the future. Using nanite shouldn’t mean losing legitimate optimization options that LODs provided. For example, nanite draws into VSM at unlimited distance, which can lead to many small objects being rendered to shadow depths needlessly. LODs easily allow shadows to be disabled by screen-size.
In the meantime, the best I can come up with for foliage is to use the distance or screen size in the material to lerp opacity to 1. This is still more expensive than a truly opaque material, but I’ve found a masked material with an opacity of 1 to be measurably less expensive than a partially or fully masked mesh - so it is better than nothing.
Also consider the shadow pass when using CSM or VSM. You can make your mesh opacity=1 using the shadow pass switch. This might save some time when drawing the shadow depths.
Another descriptor that is unfortunately missing from the PCG mesh spawner is the checkbox for “Draw in Main Pass.” You can use this to disable shadow casting on the mesh, but then spawn a shadow casting proxy mesh (invisible in the main pass but not the depth pass) in the same location with a fully opaque material and even simpler geometry if you like.