Primitive cull distance getter in materials (InstanceDrawDistanceMinMaxSquared.y)

How can we get the cull distance inside materials? Previously (ie I think 5.5 or 5.4) we could use a custom node, returning GetPrimitiveData().InstanceDrawDistanceMinMaxSquared.y but it is now (5.6.1) useless (I think due to gpu culling and FHierarchicalStaticMeshSceneProxy::GetInstanceDrawDistanceMinMax).

PerInstanceFadeAmount is useless too on nanite meshes.

This is needed to have proper fading of effects and avoid artists the need to input cull distances inside materials as scalar parameters and keep that value in sync with foliage value.

Steps to Reproduce

Hello,

Thank you for reaching out.

I have been assigned this ticket, and we will be looking into how to fetch the Instance Draw Distance from the Material Graph for you.

Hello,

In our tests, we could still use GetPrimitiveData(). Please see the following HLSL that we used in a Custom Material Expression:

#if HAS_PRIMITIVE_UNIFORM_BUFFER
return GetPrimitiveData(Parameters).InstanceDrawDistanceMinMaxSquared.y;
#endif
return 0.f;

You can switch between a fade amount calculated using the above for Nanite and PerInstanceFadeAmmount for non-Nanite by using a Nanite Pass Switch.

Please let us know if this helps.

If you connect that custom mat expression to a DebugScalarValues, the displayed number is valid for a nanite mesh, not for a classic mesh. as you can see in the attached screenshot I modified the initial zipped material to output that custom expression (I modified the return 0.f in return 666.f). The displayed value is 0. So InstanceDrawDistanceMinMaxSquared.y seems to be 0 for a non nanite mesh on my side.

Hello,

This behavior is expected, and is a change in Unreal Engine 5.6.

HISM Components (including Instanced Foliage) will no longer perform GPU-based instance culling for non-Nanite meshes. Instead, they cull before submitting the instances.

Nanite meshes use a different Proxy, and so are unaffected by this change.

This was changed in CL: 38134346

Please let us know if this helps.

I see. Since that value helped us to fade-out of some effects, I think we have to workaround this missing feature.

Hello,

PerInstanceFadeAmount Material Expression will work for non-Nanite geometry, and you can use a Nanite Switch to control which logic is used for Nanite vs non-Nanite.

Please let us know if this helps.