Failed to setParameter with Array for a material in a custom shader

Hi guys,

I’ve tried my best to search a way sending an uniform-array to my custom shader, using the material.setParameter. With all failed silently, leaving a black background there.

Here’s my script:

var _colors = [
     1.0, 1.0, 1.0, 1.0 ,

// initialize code called once per entity
MagicSky.prototype.initialize = function() {
    Object.assign(this, {
        time: 0,
        shader: null,
        material: null,
    var app =;
    var model = this.entity.model.model;
    var gd = app.graphicsDevice;

    var fragmentShader = "precision " + gd.precision + " float;\n";
    fragmentShader = fragmentShader + this.fs.resource;
    var shaderDefinition = {
        attributes: {
            aPosition: pc.SEMANTIC_POSITION,
        vshader: this.vs.resource,
        fshader: fragmentShader
    this.shader = new pc.Shader(gd, shaderDefinition);
    this.material = new pc.Material();
    this.material.setParameter('u_colors', _colors);
    model.meshInstances[0].material = this.material;  

and fragment shader:

uniform float u_colors[4];

void main(void)
    gl_FragColor = vec4(u_colors[0], u_colors[1], u_colors[2], u_colors[3]);

I just couldn’t figure how the exact way I should pass an array as the uniform to the shader.
Any Ideas ?

Really Thanks !

Perhaps a bug exists somewhere ? I googled a post and found a similar issue was exposed about a month ago:

Maybe related ? I’d like to know the progress

uniform float u_colors[4];


uniform vec4 u_colors;

The engine needs to be flexible enough to support both representations though. Seems like it doesn’t.

Do you mean accept both array and vector as argument?

I wouldn’t mind if setParameter could still stick to arrays as per standard (typed arrays i think? Or both?), and not necessariliy have to use pc.Vec?? data types etc which leads to a lot of unnecessary parameter type reflections . Best case is to quickly be able to setParameter with minimal performance overhead. However, when translating to vec3/vec4/mat/int[],float[] reprepsentations, it should be able to parse that array into the respective data type in GLSL. It seems the float variableName[] reprepsentations has issues with it, like what it’s shown in this example.

Oh, are you going to pass arrays to shader? That’s the point then.