【发布时间】:2019-06-26 16:24:27
【问题描述】:
我尝试绘制贴花和背景两种纹理,但只有贴花的 alpha 部分变为白色。
我只是尝试了以下。
- 绘制 2 个纹理(背景和贴花)
- 添加 glBlendFunc 以应用贴花 alpha 值
#version 330 core
in vec2 UV;
out vec3 color;
uniform sampler2D background;
in vec3 decalCoord;
uniform sampler2D decal;
void main(){
vec3 BGTex = texture( background, UV ).rgb;
vec3 DecalTex = texture(decal, decalCoord.xy).rgba;
color =
vec4(BGTex,1.0) + // Background texture is DDS DXT1 (I wonder if DXT1 is the cause?)
vec4(DecalTex,0.0); // Decal texture is DDS DXT3 for alpha
}
// Set below...
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
我可以正常绘图,但存在以下问题。 -贴花的alpha部分不能透明。
这是一个可以在片段着色器中解决的问题吗? 那么,我应该如何重写代码呢?
纹理是DDS,其中一个是DXT1类型(背景。因为这个纹理不需要alpha),另一个是DXT3类型(贴花)。也是这个原因吗?(都需要是DXT3类型的?)
另外,我应该寻找另一种贴花的方法吗?
【问题讨论】:
-
rgba不适合 vec3。
标签: c++ opengl glsl shader blending