How do I pass an array of values into a shader?

Greetings.

As the title says, I need to pass an array of values, likely floats, into a material shader. The purpose is to use those values to deform the vertices of the mesh. I’ve tried Material Parameter Collections, but that doesn’t seem to be the most practical way to do it (imagine adding dozens of parameters to a collection manually…).

Any suggestions?

Thanks in advance!

Hey dsl -

I may need some clarification here as to why and how you are going to use these values. You are wanting to use world position offset to animate the vertexes of your mesh, but that can be set up with a lerp between two constant 3 values with the alpha set up to either a timed event like a sine wave or a static event like vertex coloring or a combination of the two.

If you can elaborate on what exactly you are trying to achieve I can try to take down an answer for you.

-Eric Ketchum

Hi, thanks for the reply.

Yes, I’ve been trying to use the world offset position, but the problem is that I’m using custom external data to define those exact positions. I haven’t found any way to bring those external values into the material editor. The closest I’ve been able to do is to code those values into a texture and decode them within the editor.

I’ll give an example: imagine a flat plane which you wish to deform with a custom animation created outside UE4. The animation file is somehow read into UE4 and its values must be applied to the vertices. This last step is the reason behind my question.

Isn’t there some kind of “ArrayParameter” node in the material editor? :slight_smile:

Thanks!

Hey dsl -

So there is a way to do what you are wanting to do but it requires some blueprinting in addition to your material setup. In the material you should be able to setup a parameter which makes your array input type, since you are using vertex animation I would assume you are going to be setting up a vector parameter. Now in blueprints you will want to setup a Dynamic Material Instance for the object in the world that is using that material and assign the Dynamic Material to that object in your blueprint. For using the custom animation and changing the vector parameter, you can use Matinee to animate over time and set to play and loop from the blueprint or through play on level load and looping in the Matinee actor.

The one clarification that I want to make is exactly how is your animation getting imported in, because it also sort of sounds like Morph Targets might also solve your problem as well.

-Eric Ketchum

Hey, can I get a simple answer as to whether or not you can pass a dynamic array into a material at this time? This is the only question on the topic, but I’m still unsure.

It seems “dynamic parameter” is only intended for the particle editor, and only deals with up to 4 parameters.

Is there no way to pass in an array? Is my best bet to either use some kind of dynamic texture as a lookup table, or daisy chain 20 parameters by hand?

Hi -

Without changing and adding to the source code base for your project, Materials are not set up currently to take arrays.

Thank You

Eric Ketchum

Can you show with a picture how you pass the array ? the vector parameter just takes one input not an array.