Shader array properties

How can we pass an array to a shader via setProperty?
I see on some documentation that array is available now, but the only topic I found about shader array is this one, which is quite old.

It seems that array properties is not support currently.

Do we have any confirm about that?
It’s pretty annoying to create a lot of variable to workaround this.

can this not be done by defining an array and then using Material.setProperty(customArray, arraydata) ?

I did not try that.
I will do a quick test and let you know.

Apparently this seems working, will do a deep test later.

Glad to hear it’s working for you! When you get a chance, would you mind marking the answer as the solution?

One more thing to add on to my previous answer by the way… this isn’t a direct answer to your question. I’m just giving you an extra tidbit.

If you use the material.setProperty function, one of the possible arguments that it can take is render pass… If you don’t supply it with a render pass, it will apply your property change to all passes… which might not be a problem if you’re only using this material one time in one place… But if you were trying to use the same material in multiple areas and you don’t want to set the same property value on all of the instances of your material At the same time, make sure that you are adding the render pass with your parameters. Typically it’s just going to be render pass zero for the specific node you are trying to work with… (Unless you are adding multiple render passes on your shader… you would know if you were doing that. That is a very deliberate choice.) Anyway… Just thought I’d let you know that you can set properties on multiple instances of the same material independently. :slight_smile:

I am not quite sure what do you mean.
We are currently using this shader to create dynamic light effect on 2d sprites, so we are updating it very often. Also every sprite has it’s own material.

Sure.

First of all declare your array on the shader.
Unfortunately with UBO we may create only vec4 array, so we may have to “pack” the data.

uniform test{
  vec4  light2d[16];
}

After that we have to create our vec4 array:

let lightData:Vec4[] = [];
for ( let t:number = 0; t<16; t++ ) {
        lightData.push(new Vec4());
        ....
}

this.uberMaterial.setProperty('light2d', lightData);