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 = this.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.setShader(this.shader);
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 !