C++ Opengl:通过拾取颜色使纹理背景透明
我有一个在OpenGL中作为2D纹理的树的图片。我想删除背景(天蓝色),或者更确切地说,使该部分透明。如何在片段着色器中执行此操作。我想到的最接近的方法是移除高于阈值的纹理像素。例如C++ Opengl:通过拾取颜色使纹理背景透明,c++,opengl,glsl,fragment-shader,C++,Opengl,Glsl,Fragment Shader,我有一个在OpenGL中作为2D纹理的树的图片。我想删除背景(天蓝色),或者更确切地说,使该部分透明。如何在片段着色器中执行此操作。我想到的最接近的方法是移除高于阈值的纹理像素。例如 #version 330 in vec2 texCoord; out vec4 outColor; uniform sampler2D theTexture; void main() { vec4 texel = texture(theTexture, texCoord); if(texel.b <
#version 330
in vec2 texCoord;
out vec4 outColor;
uniform sampler2D theTexture;
void main()
{
vec4 texel = texture(theTexture, texCoord);
if(texel.b < threshold)
discard;
outColor = texel;
#版本330
在vec2 texCoord;
外显vec4外显色;
纹理均匀;
void main()
{
vec4 texel=纹理(纹理,texCoord);
如果(纹理b<阈值)
丢弃
outColor=texel;
}该解决方案有什么问题?它不会像您描述的那样工作,因为它会丢弃低于阈值的像素。正如你现在写的问题,你只需要在比较中翻转符号。