Just as the title says, if I make a p5 sketch with
WEBGL enabled and all that, and I make a shader and try to give it a uniform variable called
uAmbientColor, I am unable to use it correctly.
Regard this humble sketch:
Inside it, you will find
basic.frag, which defines
uniform vec3 uAmbient. In
sketch.js, I set things up so that I use a simple test shader I wrote and draw a square on the screen. The square should be yellow because I have
theShader.setUniform("uAmbient", [1, 1, 0]);
in the sketch file and I have
gl_FragColor = vec4(uAmbient, 1.0)
in the fragment shader.
If you change the name of the variable to
sketch.js, the square looks black instead of yellow, and nothing you can do with the numbers passed into that function seems to make any difference.
I even went as far as to try turning
uAmbientColor into a float and adding two additional floats, so that in my shader I had
uniform float uAmbientColor; // r for red uniform float uAmbientColog; // g for green uniform float uAmbientColob; // b for blue // ... // gl_FragColor = vec4(uAmbientColor, uAmbientColog, uAmbientColob, 1.0);
in the fragment shader, and then I had
theShader.setUniform("uAmbientColor", 1); theShader.setUniform("uAmbientColog", 1); theShader.setUniform("uAmbientColob", 1);
in my sketch file. The result was a cyan square, which is consistent with the 1 I’m trying to pass into the R, G, and B channels only making it through to the G and B and being replaced with a 0 in R.
I’m baffled. What might be causing this?