Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.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++ 如何消除捆扎问题?_C++_Opengl - Fatal编程技术网

C++ 如何消除捆扎问题?

C++ 如何消除捆扎问题?,c++,opengl,C++,Opengl,我每次模糊时都会遇到带状问题,我对体积照明进行了径向模糊,我得到了这个 所有的代码似乎都是正确的,我不明白为什么它不起作用。体积照明效果完美,但带状效果令人讨厌 我做了一些研究,了解到抖动可能会消除这个问题,但一定是我在代码中做错了什么,才会发生这种情况。下面是您需要的所有代码 径向模糊片段着色器 #version 330 core out vec4 FragColour; in vec2 _texcoord; uniform float exposure; uniform float d

我每次模糊时都会遇到带状问题,我对体积照明进行了径向模糊,我得到了这个

所有的代码似乎都是正确的,我不明白为什么它不起作用。体积照明效果完美,但带状效果令人讨厌

我做了一些研究,了解到抖动可能会消除这个问题,但一定是我在代码中做错了什么,才会发生这种情况。下面是您需要的所有代码

径向模糊片段着色器

#version 330 core

out vec4 FragColour;
in vec2 _texcoord;

uniform float exposure;
uniform float decay;
uniform float density;
uniform float weight;
uniform vec2 lightPositionOnScreen;
uniform sampler2D lightScatterTexture;
const int NUM_SAMPLES = 128;

void main(void)
{
    vec2 deltaTextCoord = _texcoord - lightPositionOnScreen.xy;
    vec2 textCoo = _texcoord;

    deltaTextCoord *= 1.0 /  float(NUM_SAMPLES) * density;
    float illuminationDecay = 1.0;

    vec2 dir = lightPositionOnScreen - textCoo;
    dir /= NUM_SAMPLES;

    for(int i=0; i < NUM_SAMPLES ; i++)
    {
        textCoo -= deltaTextCoord;

        vec4 sample = texture2D(lightScatterTexture, textCoo );

        sample *= illuminationDecay * weight;

        FragColour += sample;

        textCoo += dir;

        illuminationDecay *= decay;
    }

    FragColour *= exposure;
}
// blur pass
        glBindFramebuffer(GL_FRAMEBUFFER, _light_scatter_blur_fbo); // bind the gbuffer fbo to start the geometry pass
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glclear the gbuffer before rendering to it

                                                            // bind the radial blur shader
        glUseProgram(blur_program);

        // get the light position in screenspace
        glm::mat4 viewProjectionMatrix = projection * view;
        glm::vec4 lightNDCPosition = viewProjectionMatrix * glm::vec4(2.0f, 10.0f, 20.0f, 1);
        lightNDCPosition /= lightNDCPosition.w;
        glm::vec2 lightScreenPosition = glm::vec2((lightNDCPosition.x + 1) * 0.5, (lightNDCPosition.y + 1) * 0.5);

        // set the uniforms for the light scattering
        glUniform1f(_u_exposure, 0.6050f);
        glUniform1f(_u_decay, 0.9f);
        glUniform1f(_u_density, 0.9f);
        glUniform1f(_u_weight, 5.0f);
        glUniform2f(_u_lightScreenPos, lightScreenPosition.x, lightScreenPosition.y); // TODO: Load this in within the constructer!
                                                                                                                        // bind the light scatter texture to radial blur
        glUniform1i(_u_lightScatterTexture, 0); // TODO: Load this in within the constructer!
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, _light_scatter_texture);

        // render the quad
        renderQuad();

        glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind the gbuffer, we dont need it anymore
体积光散射FBO设置

glGenFramebuffers(1,&u light\u scatter\u fbo);
glBindFramebuffer(GLU帧缓冲区、光散射fbo);
glGenTextures(1,&光散射纹理);
glBindTexture(GL_纹理_2D、_灯光_散射_纹理);
glTexParameteri(GL_纹理2D、GL_纹理最小过滤器、GL_线性);
glTexParameteri(GL_纹理2D、GL_纹理MAG_过滤器、GL_线性);
glTexParameteri(GL_纹理2D、GL_纹理包裹S、GL_重复);
glTexParameteri(GL_纹理2D、GL_纹理包裹、GL_重复);
GLTEXAGE2D(GL_纹理_2D,0,GL_RGBA,1920,1080,0,GL_RGBA,GL_无符号_字节,NULL);
glFramebufferTexture2D(GL_帧缓冲区、GL_颜色_附件0、GL_纹理_2D、光线_散射_纹理,NULL);
如果(glCheckFramebufferStatus(GL\U FRAMEBUFFER)!=GL\U FRAMEBUFFER\U COMPLETE)

cerr抖动确实应该解决这个问题。我认为这是循环片段着色器的精度问题,导致输出不够平滑,抖动无法正常工作。尽量不要混淆大小值,因为浮点精度是相对的(相对于绝对值),所以模糊是否会自动使用抖动?所以for循环中的问题是,好的,但是当我抖动时,我只得到点,嗯,你说的“抖动”是什么意思。它是glEnable(GL_抖动),默认情况下仍处于启用状态。你做了什么?你可以试试16F纹理格式。抖动是由于精度问题造成的。
glGenFramebuffers(1, &_light_scatter_fbo);
        glBindFramebuffer(GL_FRAMEBUFFER, _light_scatter_fbo);

        glGenTextures(1, &_light_scatter_texture);
        glBindTexture(GL_TEXTURE_2D, _light_scatter_texture);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _light_scatter_texture, NULL);

        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            std::cerr << "Error: Unable to create VLS fbo texture!" << std::endl;

        glGenFramebuffers(1, &_light_scatter_blur_fbo);
        glBindFramebuffer(GL_FRAMEBUFFER, _light_scatter_blur_fbo);

        glGenTextures(1, &_light_scatter_blur_texture);
        glBindTexture(GL_TEXTURE_2D, _light_scatter_blur_texture);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _light_scatter_blur_texture, NULL);

        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            std::cerr << "Error: Unable to create VLS fbo texture!" << std::endl;

        glBindFramebuffer(GL_FRAMEBUFFER, 0);