Opengl ES 3.0 中的多重纹理和标签
Multitexturing and labels in Opengl ES 3.0
我想使用多重纹理在对象上绘制数字。但最终图像更亮,如:
是否可以从多重纹理中排除白色并使数字更暗?
这是我的片段着色器:
#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);
}
我试过这样做:
GLES30.glEnable(GLES30.GL_BLEND);
GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE);
GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
...
GLES30.glDisable(GLES30.GL_BLEND);
但这并没有解决问题
感谢您的任何 answer/comment!
解法:
根据 Rabbid76 的建议,我应用了这个:
outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);
结果:
mix
number_texture
的颜色加了一个白色,而不是加一个常量:
outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);
实际上这与:
outColor = baseColor * (numberColor * 0.5 + 0.5);
我想使用多重纹理在对象上绘制数字。但最终图像更亮,如:
是否可以从多重纹理中排除白色并使数字更暗?
这是我的片段着色器:
#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);
}
我试过这样做:
GLES30.glEnable(GLES30.GL_BLEND);
GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE);
GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
...
GLES30.glDisable(GLES30.GL_BLEND);
但这并没有解决问题
感谢您的任何 answer/comment!
解法: 根据 Rabbid76 的建议,我应用了这个:
outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);
结果:
mix
number_texture
的颜色加了一个白色,而不是加一个常量:
outColor = baseColor * mix(numberColor, vec4(1.0), 0.5);
实际上这与:
outColor = baseColor * (numberColor * 0.5 + 0.5);