How to set uniform matrix array

How do I set the following shader uniform:

uniform mat4 matrix_object_face_to_world[6];

material.setParameter seems to only take data of type number, number[] and Texture according to the docs

1 Like

Hi @mabu,

Check this post on how to pass an array to a shader:

1 Like

I’m not getting it to work so far.

I see that https://github.com/playcanvas/engine/blob/bb5aa65caa880ab546ce9de456ef5bc195533f74/src/graphics/shader-input.js

only seems to account for vector arrays but not matrix arrays. How is that type deducted by the engine?

I assume gl.getActiveAttrib returns gl.FLOAT_MAT4 for a matrix array, but it seems that https://github.com/playcanvas/engine/blob/bb5aa65caa880ab546ce9de456ef5bc195533f74/src/graphics/constants.js would need to add a UNIFORMTYPE_MAT4ARRAY type (and same for other matrix dimensions) to support setting matrix arrays by adding “[0]” to the variable name. Or am I missing something?

1 Like

@mvaligursky and idea?

as an example, here’s how we use skinning matrices (in case uniforms are used to supply them to vertex shaders)

and this is how JS is setting those up:

data are allocated this way

I think maybe sth related to 16 elements, because of matrix4x4, precisely dont sure

It looks like you’re using a vec4 array rather than a mat4 array and then assemble a mat4 in the shader. Does that mean it’s not possible to use mat4 array uniforms directly?

it works for matrix as well, for example shadow cascade matrixes in code

    code += "uniform mat4 light" + i + "_shadowMatrixPalette[4];\n";
    this.shadowMatrixPaletteId[i] = scope.resolve(light + "_shadowMatrixPalette[0]");
    this._shadowMatrixPalette = new Float32Array(4 * 16);   // always 4
    this.shadowMatrixPaletteId[cnt].setValue(directional._shadowMatrixPalette);
1 Like