I'm trying to develop a GLSL shader that uses two sampler2Ds, but I'm having some issues.
Fragment shader:
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform sampler2D u_texture;
uniform sampler2D my_second_texture;
void main() {
vec4 original_color = texture2D(u_texture, v_texCoord0);
gl_FragColor = original_color;
}
This shader should output an unaltered u_texture.
Drawing code:
spritebatch.begin();
spritebatch.setShader(my_shader);
my_shader.setUniformi("my_second_texture", 1);
Gdx.gl20.glActiveTexture(1);
my_second_texture.bind(1); //Around here is where things go wrong, I think...
Gdx.gl20.glActiveTexture(0);
Gdx.gl.glClearColor(bg_color.r, bg_color.g, bg_color.b, bg_color.a);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
spritebatch.setTransformMatrix(new Matrix4());
spritebatch.setColor(1, 1, 1, 1);
spritebatch.draw(my_first_texture, -960, -540, 1920, 1080, 0, 0, 1920, 1080, false, true);
spritebatch.end();
The result on the screen is my_second_texture stretched across the whole screen. The expected result is an unaltered my_first_texture on the screen. (For the curious: The ultimate goal is a palette swap shader.)
How can I make a shader that properly uses two sampler2Ds, using GLSL and LibGDX?
#version
directive? – genpfaultmy_first_texture
uniform tou_texture
. github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/… Consider to base your shader on this shader github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/… – Xoppa