Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Opengl:通过拾取颜色使纹理背景透明_C++_Opengl_Glsl_Fragment Shader - Fatal编程技术网

C++ Opengl:通过拾取颜色使纹理背景透明

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 <

我有一个在OpenGL中作为2D纹理的树的图片。我想删除背景(天蓝色),或者更确切地说,使该部分透明。如何在片段着色器中执行此操作。我想到的最接近的方法是移除高于阈值的纹理像素。例如

#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;

}

该解决方案有什么问题?它不会像您描述的那样工作,因为它会丢弃低于阈值的像素。正如你现在写的问题,你只需要在比较中翻转符号。