javaopengl-esglslshaderopengl-es-3.0

Multitexturing and labels in Opengl ES 3.0


I want to draw numbers on an object using multitexturing. But the final image is lighter, like:

enter image description here

Is it possible to exclude white color from multitexure and make the digit darker?

Here's the my fragment shader:

#version 300 es
precision mediump float;
in vec2 v_textureCoord;
out vec4 outColor;
uniform sampler2D base_texture;
uniform sampler2D number_texture;
void main() {
    // wall texture
    vec4 baseColor = texture(base_texture, v_textureCoord);
    // texture with digit
    vec4 numberColor = texture(number_texture, v_textureCoord);
    // resulting pixel color based on two textures 
    outColor = baseColor * (numberColor + 0.5);
}

I tried to do this:

GLES30.glEnable(GLES30.GL_BLEND);
GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE);
GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
...
GLES30.glDisable(GLES30.GL_BLEND);

But this did not solve the problem.

Thank you for any answer/comment!

Solution: On Rabbid76 advice, I applied this:

outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);

Result:

enter image description here


Solution

  • mix the color of number_texture by a white color, rather than adding a constnant:

    outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);
    

    Actually that is the same as:

    outColor = baseColor * (numberColor * 0.5 + 0.5);