0

我正在尝试延迟着色,但在尝试对多重渲染目标进行多重采样时遇到了麻烦。好像我只复制一个抗锯齿纹理而不是 3 个(漫反射、位置、法线)。仅复制漫反射。

这是为我的 Geometry Pass 创建的 Anti Alias FBO:

IntBuffer drawBuffs = BufferUtils.createIntBuffer(3);
private void CreateFBOAntiAlias() {

    AntiAliasFrameBuffer = glGenFramebuffers();
    GL30.glBindFramebuffer(GL_FRAMEBUFFER, AntiAliasFrameBuffer);

    textureColorMultiSampled = generateMultiSampleTexture(4);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
    GL32.GL_TEXTURE_2D_MULTISAMPLE, textureColorMultiSampled,
    0);

    texturePositionMultiSampled = generateMultiSampleTexture(4);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
    GL32.GL_TEXTURE_2D_MULTISAMPLE, texturePositionMultiSampled ,
    0);

    textureNormalMultiSampled = generateMultiSampleTexture(4);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2,
    GL32.GL_TEXTURE_2D_MULTISAMPLE, textureNormalMultiSampled ,
    0);


    drawBuffs.put(0, GL30.GL_COLOR_ATTACHMENT0);
    drawBuffs.put(1, GL30.GL_COLOR_ATTACHMENT1);
    drawBuffs.put(2, GL30.GL_COLOR_ATTACHMENT2);


    GL20.glDrawBuffers(drawBuffs);

    AntiAliasRenderBufferObject = glGenRenderbuffers();

    glBindRenderbuffer(GL_RENDERBUFFER, AntiAliasRenderBufferObject);
    glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4,
            GL_DEPTH24_STENCIL8, width, height);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
            GL_RENDERBUFFER, AntiAliasRenderBufferObject);

    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
        System.err
                .println("ERROR::FRAMEBUFFER:: Framebuffer is not complete!");
    } else {
        System.err.println("FrameBuffer AntiAliasFBO success");
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

 private int generateMultiSampleTexture(int samples) {
    int texture;
    texture = GL11.glGenTextures();

    GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, texture);
    GL32.glTexImage2DMultisample(GL32.GL_TEXTURE_2D_MULTISAMPLE, samples,
            GL11.GL_RGBA8, width, height, true);
    GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, 0);

    return texture;

}

这是我的目标 FBO 的创建:

public void CreateFBO() {

    fbo_handle = glGenFramebuffers();
    diffuse_handle = GL11.glGenTextures();
    position_handle = GL11.glGenTextures();
    normal_handle = GL11.glGenTextures();
    glBindFramebuffer(GL_FRAMEBUFFER, fbo_handle);

    //////////////////DIFFUSE////////////////////////////////////
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, diffuse_handle);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height,0, 
            GL11.GL_RGBA, GL11.GL_INT, (ByteBuffer) null);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
            GL11.GL_TEXTURE_2D, diffuse_handle, 0);

    /////////////////POSITION////////////////////////////////////
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, position_handle);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0,
            GL11.GL_RGBA, GL11.GL_INT, (ByteBuffer) null);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
            GL11.GL_TEXTURE_2D, position_handle, 0);

    ///////////////NORMALS/////////////////////////////////////////
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, normal_handle);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0,
            GL11.GL_RGBA, GL11.GL_INT, (ByteBuffer) null);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2,
            GL11.GL_TEXTURE_2D, normal_handle, 0);
    //////////////////////////////////////////////////////////////////


    drawBuffs.put(0, GL30.GL_COLOR_ATTACHMENT0);
    drawBuffs.put(1, GL30.GL_COLOR_ATTACHMENT1);
    drawBuffs.put(2, GL30.GL_COLOR_ATTACHMENT2);

    GL20.glDrawBuffers(drawBuffs);

    rbo_depth_buffer_handle = glGenRenderbuffers();
    glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth_buffer_handle);
    glRenderbufferStorage(GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT32,
            width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
            GL_RENDERBUFFER, rbo_depth_buffer_handle);

    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
        System.err.println("Framebuffer configuration error");
    } else {

        System.err.println("Deferred configuration Success");
    }

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

我在几何传递过程中绑定了我的 AA FBO,取消绑定并执行从 AA FBO 到我的目标 FBO 的 Blit,并以不希望的结果渲染全屏四边形。

public void blit() {
    GL11.glEnable(GL13.GL_MULTISAMPLE);

    glBindFramebuffer(GL_READ_FRAMEBUFFER, AntiAliasFrameBuffer);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_handle);
    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
            GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

}

编辑:我已经尝试在没有多重采样调用的情况下从一个普通的 MRT fbo 到另一个普通的 MRT FBO 并且似乎我只是在复制一个纹理。我的问题的根源是错误地将 MRT 传送到另一个 MRT。

4

1 回答 1

1

唷,好的,我的主要问题是我的 blitting 不正确。blitting方法应该是

public void blit() {

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glBindFramebuffer(GL_READ_FRAMEBUFFER, AntiAliasFrameBuffer);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_handle);



    GL11.glReadBuffer(GL_COLOR_ATTACHMENT0);
    GL11.glDrawBuffer(GL_COLOR_ATTACHMENT0);

    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
            GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);


    GL11.glReadBuffer(GL_COLOR_ATTACHMENT1);
    GL11.glDrawBuffer(GL_COLOR_ATTACHMENT1);
    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
            GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);



    GL11.glReadBuffer(GL_COLOR_ATTACHMENT2);
    GL11.glDrawBuffer(GL_COLOR_ATTACHMENT2);

    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
            GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);


    glBindFramebuffer(GL_FRAMEBUFFER, 0);

}

我的 AA FBO/FBO 的一般设置是正确的,所有纹理都被成功复制,并且对 Aliasing 有重大改进。

于 2015-08-26T01:48:27.237 回答