OpenGL ES 3.0 - 渲染为保留颜色附件时的锯齿状边缘

时间:2017-03-28 13:25:35

标签: ios opengl-es fragment-shader opengl-3

iOS 上使用 OpengGL ES 3.0 ,我想使用一个带有2个颜色附件的帧缓冲对象(FBO)( A0 A1 )将对象 a0 渲染到 A0 ,将 a1 渲染到 A1 A1 的纹理将保留并在下一帧中重复使用,而 A0 无效(并清除)。

问题在于,当渲染到 A1 时,会创建锯齿状的人工制品(主要是沿着物体边缘),c.f。附加图像(颜色附件1 = A0 颜色附件2 = A1 )。

GPU Snapshot in Xcode - Artefacts in Color Attachment 1

我检查了GL状态并确保当前绑定了正确的FBO并且没有GL_ERROR且GL_MAX_COLOR_ATTACHMENTS为4。 我创建了一个带有2种颜色附件的FBO,如下所示:

// Assuming the FBO and the 2 requried textures were correctly generated

glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _fbo_tex[0], 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, _fbo_tex[1], 0);

// glCheckFramebufferStatus(GL_FRAMEBUFFER) returns GL_FRAMEBUFFER_COMPLETE

顶点着色器:

#version 300 es
uniform mat4 modelviewProjectionMatrix;
in vec4 position;

void main() {
    gl_Position = modelviewProjectionMatrix * position;
}

要渲染到 A0 的片段着色器:

#version 300 es
uniform lowp vec4 colorIn;
layout(location = 0) out lowp vec4 colorOut;

void main() {
    colorOut = colorIn;
}

要渲染到 A1 中的片段着色器:

#version 300 es
uniform lowp vec4 colorIn;
layout(location = 1) out lowp vec4 colorOut;

void main() {
    colorOut = colorIn;
}

这是渲染代码:

// Assuming the correct vertex array is bound
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo);
{
    glUseProgram(_program_for_a0);
    const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
    glDrawBuffers(1, attachments);
    glClear(GL_COLOR_BUFFER_BIT);

    // Draw a0 into GL_COLOR_ATTACHMENT0
}
{
    glUseProgram(_program_for_a1);
    const GLenum attachments[] = {GL_NONE, GL_COLOR_ATTACHMENT1};
    glDrawBuffers(2, attachments);
    // No glClear() call

    // Draw a1 into GL_COLOR_ATTACHMENT1
}

这里失效:

const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, 1, attachments);

如果这是有用的信息,人工制品似乎是由于某些平铺机制造成的,因为它们是32x32像素块。 任何帮助都将受到高度赞赏。

0 个答案:

没有答案