Reputation: 2158
I have a very simple shader that uses a custom shader program. I'm sending down the camera transformation, the world transformation as uniforms, which all work. I'm also sending down a uniform color the same way, but it doesn't seem to affect the color on the screen. Using set()
it only comes out black like the color isn't being set correctly.
Code from the libgdx shader:
protected final int u_projTrans = register(new Uniform("u_projTrans"));
protected final int u_worldTrans = register(new Uniform("u_worldTrans"));
protected final int u_color = register(new Uniform("u_color"));
@Override
public void begin(Camera camera, RenderContext context) {
program.begin();
context.setDepthTest(GL20.GL_LEQUAL, 0f, 1f);
context.setDepthMask(true);
set(u_projTrans, camera.combined);
}
@Override
public void render(Renderable renderable) {
set(u_worldTrans, renderable.worldTransform);
set(u_color, 1, 1, 1); // binding, but no change in color
// program.setUniformf("u_color", 1, 1, 1); // works
renderable.meshPart.render(program);
}
Looking at the above code, I bind u_projTrans in the begin() function and I bind u_worldTrans in the render() function. I know those are both working based on the image I see.
Vertex shader:
attribute vec3 a_position;
uniform mat4 u_projTrans;
uniform mat4 u_worldTrans;
void main() {
gl_Position = u_projTrans * u_worldTrans * vec4(a_position, 1.0);
}
Fragment shader:
uniform vec3 u_color;
void main() {
gl_FragColor = vec4(u_color, 1); // hard-coding this to a color works, so the value in u_color seems to be (0,0,0)
}
When I try to set the color uniform it says it's correctly binding, but I just don't get any change in color like the value is set to (0,0,0). However, using program.setUniformf()
works. Using set()
I'm binding it exactly as I am for the others so I don't know what's different besides sending it down as a vec3
instead of a mat4
.
Does anyone know why the values I pass in set(u_color, 1, 1, 1)
don't make it down to the shader?
Upvotes: 0
Views: 884
Reputation: 93882
When you call set(u_color, 1, 1, 1);
you are using the set(Uniform, int, int int)
method. What you want is the set(Uniform, float, float, float)
method so use set(u_color, 1f, 1f, 1f)
instead.
Upvotes: 1