Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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 ES 2.0中应用高斯模糊时如何修复奇怪的瑕疵_C++_Qt_Opengl Es_Framebuffer_Gaussianblur - Fatal编程技术网

C++ 在OpenGL ES 2.0中应用高斯模糊时如何修复奇怪的瑕疵

C++ 在OpenGL ES 2.0中应用高斯模糊时如何修复奇怪的瑕疵,c++,qt,opengl-es,framebuffer,gaussianblur,C++,Qt,Opengl Es,Framebuffer,Gaussianblur,我在OpenGLES2.0中使用QT应用高斯模糊进行bloom效果时,会出现奇怪的伪影,如下所示。左侧是启用bloom效果,右侧是禁用效果: 奇怪的是,这种伪影只有在我渲染某些线条时才会发生,如下图所示。值得一提的是,这些线实际上是以恒定像素宽度渲染到屏幕上的四边形。没有任何其他对象有任何可见的伪影,只有预期的高斯模糊,更可怕的是,我渲染的大多数其他线条看起来都很好。你可以在左边的图片中看到,左边的青色线没有任何奇怪的伪影 以下是我组合的着色器: 顶点着色器: #ifdef GL_ES prec

我在OpenGLES2.0中使用QT应用高斯模糊进行bloom效果时,会出现奇怪的伪影,如下所示。左侧是启用bloom效果,右侧是禁用效果:

奇怪的是,这种伪影只有在我渲染某些线条时才会发生,如下图所示。值得一提的是,这些线实际上是以恒定像素宽度渲染到屏幕上的四边形。没有任何其他对象有任何可见的伪影,只有预期的高斯模糊,更可怕的是,我渲染的大多数其他线条看起来都很好。你可以在左边的图片中看到,左边的青色线没有任何奇怪的伪影

以下是我组合的着色器:

顶点着色器:

#ifdef GL_ES
precision mediump int;
precision mediump float;
#endif

attribute vec3 aPos;
attribute vec2 aTexCoords;

varying vec2 blurTextureCoords[11];
varying vec2 texCoords;

uniform vec2 screenRes; // image width
uniform int effectType;

void main(void){

    // Set GL position
    gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); 
    texCoords = aTexCoords;


    if(effectType == 2){
        // Horizontal blur
        vec2 centerTexCoords = vec2(aPos.x, aPos.y)*0.5 + 0.5; // Coordinates of center of texture
        float pixelSize = 1.0 / screenRes.x;

        // Fill out texture coord array
        for(int i=-5; i<=5; i++){
            float i_float = float(i);
            blurTextureCoords[i+5] = centerTexCoords + vec2(pixelSize * i_float, 0.0);
        }
    }
    else if(effectType == 3){
        // Vertical blur
        vec2 centerTexCoords = vec2(aPos.x, aPos.y)*0.5 + 0.5; // Coordinates of center of texture
        float pixelSize = 1.0 / screenRes.y;

        // Fill out texture coord array
        for(int i=-5; i<=5; i++){
            float i_float = float(i);
            blurTextureCoords[i+5] = centerTexCoords + vec2(0.0, pixelSize * i_float);
        }
    }
}

我在代码的其他部分找不到任何奇怪的东西,而且只有这些特定的行被弄乱了,这真的很奇怪。有什么想法吗?

解决了这个问题!我需要将采样纹理坐标的颜色值钳制在0和1之间,因为我使用的是HDR,这些值会使高斯模糊效果饱和

#ifdef GL_ES
precision mediump int;
precision mediump float;
#endif

varying vec2 blurTextureCoords[11];
varying vec2 texCoords;

uniform sampler2D screenTexture;
uniform sampler2D sceneTexture;
uniform int effectType;

void main(void){
    vec4 color = texture2D(screenTexture, texCoords);

    // Different effects
    if(effectType == 2 || effectType == 3){
        // Blur
        gl_FragColor = vec4(0.0);
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[0]) * 0.0093;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[1]) * 0.028002;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[2]) * 0.065984;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[3]) * 0.121703;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[4]) * 0.175713;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[5]) * 0.198596;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[6]) * 0.175713;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[7]) * 0.121703;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[8]) * 0.065984;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[9]) * 0.028002;
        gl_FragColor += texture2D(screenTexture, blurTextureCoords[10]) * 0.0093;
    }
    else{
        gl_FragColor = color;
    }
}