Using Per Instance Custom Data On Instanced Static Mesh

4.25 introduces means to add custom data to the instance buffer and it is technically only available in the vertex shader. However, you can use the VertexInterpolator node to convert the incoming f...

Updated almost 4 years ago Edit Page Revisions

4.25 introduces means to add custom data to the instance buffer and it is technically only available in the vertex shader. However, you can use the VertexInterpolator node to convert the incoming float from the PerInstanceCustomData material node back into a format readable by the pixel shader.

The example below shows Actor BP with a Hierarchical Instanced Static Mesh component, including some instances with some scale variance for the sake of clarity. Also using the new Set Custom Data Value node to pass the instance index to the material. It requires a float (added a small value to it, in order to negate any precision errors).

Most importantly here, Num Custom Data Floats in the HISM component is set to 1, as it currently crashes in UE 4.25 Preview 7 if you try to set a custom data value where one has not been reserved.

Once in the material, simply grab the PerInstanceCustomData at data index 0, pass it through the VertexInterpolator and debug the value to the instance surface, producing the result seen in the final image. So now you can encode instance indices directly into materials without any subclassing / engine hacks, allowing you to use them for additional texture lookups and all of that good stuff.

File:PerInstanceCustomData.jpg

Source

Post`` ``on`` ``the`` ``official`` ``forums