Cocos2d: warning: Uniform not found: u_color

Playing with shaders, in cocos 3.13.1 JS, i see millions of that lines in console, regardless of the platform (osx,android and ios).

#cocos2d: warning: Uniform not found: u_color

Can i get rid of this somehow?

what i tired so far:
shader.setUniformFloat(“u_color”, …)

or in vertex shader:
uniform float u_color;

nothing seems to work, somehow i am afraid that this logging would cost performance, or that that what leads to this logging could be avoided, to save cycles.

Any ideas? Thank you in advance,
steff

You need to set Uniform again if you change the Texture of Sprite.

Also, you need “uniform float u_color;” in your vertex shader.

On the other hand, Why your color is float? Should’t it be Vec4 ?

Mert

thank you for your input, you are right with the vec4, this was a typo in my post.
I added a “uniform vec4 u_color;” line to the vertex shader, and after constructing my scene, on the shader state i am setting state.setUniformVec4(“u_color”, cc.math.vec4(0, 0, 0, 1.0));

But: i still see the u_color warnings in the console coming like a waterfall.

Also, i am not using a u_color in my shaders, but i would not mind adding one line, if it would help.
Just want to get rid of the console warnings.

Anything else i could try?

If you are not using u_color, remove it from shader and dont set it as Uniform.

Thank you again, now i am coming back to my initial post, just for clarification:
I see the warnings without mentioning a u_color anywhere in my code.

to reproduce:
create a JS project:

cocos new uniformwarningstest -p com.ati.uniformwarningstest -l js -d .

modify the Layer:

var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
this._super();

	this._layer3D = new cc.Layer();
	this.addChild(this._layer3D, 2);

	this._model = new jsb.Sprite3D(res.model);
	this._uvmap = cc.textureCache.addImage(res.HelloWorld_png);
	this._model.setTexture(this._uvmap);
	this._layer3D.addChild(this._model);
	
	this._model.setRotation3D(cc.math.vec3(0, 0, 0));
    this._model.setPosition3D(cc.math.vec3(0, 0, 0));
    this._model.setScale(15.0);	
    
	var shader = new cc.GLProgram(res.sh_vert, res.sh_frag);
	var state = cc.GLProgramState.create(shader);
	
	this._model.setGLProgramState(state);
	
	this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 75, cc.winSize.width / cc.winSize.height, .1, 200);
    this._camera.setCameraFlag(2);
    this._layer3D.addChild(this._camera);      
    this._layer3D.setCameraMask(2);
    this._camera.setPosition3D(cc.math.vec3(0, 0, 30));
    
    this._camera.lookAt(cc.math.vec3(0, 0, 0));
	return true;
}});

with those minimalistic shaders:

attribute vec4 a_position; attribute vec2 a_texCoord; attribute vec3 a_normal; attribute vec2 a_texCoord1;

void main(void) {
gl_Position = CC_MVPMatrix * a_position;
}

and frag:

void main (void)
{
gl_FragColor = vec4(0.3,0.3,0.3,0.6);
}

run this, in osx, android or ios, and see console dumping out this line over and over:

cocos2d: warning: Uniform not found: u_color

no “u_color” mentioned anywhere.
but i can see my model. can it be a problem with the material of in the c3b?

any help out there, please?

thanks. steff

Happen in C++ as well

1 Like