How to pass dynamic array parameters (Float or Vector) to materials?

Hi, thanks for the reply! I probably didn’t make myself clear sorry. I am aware Material Parameter Collections are the standard way to pass global scalars and vectors, however they are not a simple way to pass arrays of global scalars and vectors. Sure, with the standard way you can in theory pass a lot of values and consider it is “an array” but for each value you need one node in your Material graph

So let say I need to update an array of 50 global vectors each frame, I need to have this huge part of my material graph (or material function) dedicated to just having my 50 parameters: so probably there will be 50 collection parameter nodes, each representing a specific Vector in my Material Parameter Collection. Then to iterate over this array you most likely need some HLSL node as there aren’t any support for array logic in Unreal’s material. This would make you want to make a custom HLSL node with 50 inputs and connect each collection parameter node into these inputs.

This is very long to make and mostly unsustainable.

The hack I am talking about is a way to avoid this unsustainable material graph part, I found it here: Using Arrays in Materials - Development / Rendering - Epic Developer Community Forums (unrealengine.com)
It is mostly working, it is using the direct definition of how the parameter collection layout is made in HLSL so that you can iterate over part of it directly. It still is a “hack” though because the index of the parameter collection you are using can change according to the graph the material is being compiled against possibly making suddenly your custom hlsl node impossible to compile in certain contexts…

What I am searching would be either something like what “PhysicsFieldTargets” is doing in the Engine’s source (like maybe if we could add parameters to the View Uniform Buffer maybe without needing to modify the source?) or simply some “Material::SetVectorArray” like Unity is providing for instance?

1 Like