shader_set_uniform_matrix_array

This function sets a shader constant to hold an array of matrix values.

You must previously have gotten the "handle" of the constant using the function shader_get_uniform, and you will have to have previously initialised the array as an array of floating point values, where each successive group of 16 floats holds the contents of a 4x4 matrix.

In the shader you'd define the uniform as follows: 

uniform mat4 u_mTransforms[MAX_TRANSFORMS];

Every group of 16 floats in the array becomes directly accessible as an element of the uniform array, i.e. the first 16 array elements correspond to u_mTransforms[0], the next 16 elements to u_mTransforms[1], etc.

 

 

Syntax:

shader_set_uniform_matrix_array(handle, array);

Argument Type Description
handle Shader Uniform Handle The handle of the shader constant to set.
array Array A previously initialised array of floating point values. Its length should be a multiple of 16, i.e. number_of_matrices * 16.

 

Returns:

N/A

 

Example:

max_transforms = 32;
arr_transform_matrices = array_create(max_transforms * 16);
var _arr_matrix = matrix_build_identity();
var i = 0;
repeat(max_transforms)
{
    array_copy(arr_transform_matrices, i * 16, _arr_matrix, 0, 16);
    i++;
}

shader_set(sh_dynamic_batch);
shader_params = shader_get_uniform(sh_dynamic_batch, "u_mTransforms");
shader_set_uniform_matrix_array(shader_params, arr_transform_matrices);
vertex_submit(vb_batch, pr_trianglelist, texture);
shader_reset();

The above code example shows how to initialise an array of matrices and send it to a shader.

First the maximum number of transforms is defined and an array is created to hold that number of transforms. An identity matrix is then copied to the array to initialise each individual matrix. A shader sh_dynamic_batch that defines a mat4 array uniform named "u_mTransforms" is then set as the current shader and the handle to the uniform is retrieved with shader_get_uniformshader_set_uniform_matrix_array is then called to set the value of that uniform to the given array. Finally, a vertex buffer stored in the variable vb_batch is then submitted.