0

我无法让不透明的多边形变得不透明。我正在使用这个网站的公式:

加权顺序独立透明度

这是我的代码:

int programShader = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self changeFrustumX:0 y:0 w:512 h:512];
// Opaque stuff goes here?

// Make everything transparent
glEnable(GL_BLEND);

for (int i = 0; i < 2; i++)
{
    glBindFramebuffer(GL_FRAMEBUFFER, framebufferID[i]);

    if (i == 0)
    {
        // The transparency colors
        glClearColor(0.0, 0.0, 0.0, 1.0);
        glBlendFunc(GL_ONE, GL_ONE);
        glClear(GL_COLOR_BUFFER_BIT);

        programShader = colorPassShader;
    }
    else if (i == 1)
    {
        // The transparency mask
        glClearColor(1.0, 1.0, 1.0, 1.0);
        glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
        glClear(GL_COLOR_BUFFER_BIT);

        programShader = maskPassShader;
    }

    glUseProgram(programShader);

    // Yellow is supposed to be opaque
    [self setProgram:programShader 
        modelView:modelViewArray2 
        projection:frustumArray 
        vertices:yellowVertices 
        colors:yellowColors 
        textures:NULL];
    // Blue not opaque
    [self setProgram:programShader 
        modelView:modelViewArray2 
        projection:frustumArray 
        vertices:blueVertices 
        colors:blueColors 
        textures:NULL];
    // Red not opaque
    [self setProgram:programShader 
        modelView:modelViewArray2 
        projection:frustumArray 
        vertices:redVertices 
        colors:redColors 
        textures:NULL];

}

// get back to the default framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);

// Transparent objects rendering
glClearColor(0.75, 0.75, 0.75, 1.0);
// Original blend
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);

[self changeOrthoX:0 y:0 w:512 h:512];

glUseProgram(combineShader);

glActiveTexture(GL_TEXTURE1);
// Display the color from the framebuffer
glBindTexture(GL_TEXTURE_2D, renderTextureID[0]);
// Colors
glUniform1i(glGetUniformLocation(combineShader, "sAccumulation"), 1);

glActiveTexture(GL_TEXTURE2);
// Display the color from the framebuffer
glBindTexture(GL_TEXTURE_2D, renderTextureID[1]);
// Mask
glUniform1i(glGetUniformLocation(combineShader, "sReveal"), 2);

[self setProgram:combineShader 
    modelView:modelViewArray3 
    projection:orthogonalArray 
    vertices:combineVertices 
    colors:NULL 
    textures:combineTextures];

// Opaque objects rendering
glDisable(GL_BLEND);

我无法让多个 glFragData[n] 工作,据我了解,OpenGL ES 无论如何都不支持多个。黄色多边形应该是完全不透明的,但在图片中它不是。我如何让它不透明而其他一切透明?另外如何创建半透明半不透明多边形?

这是我生成的图片:

在此处输入图像描述

4

0 回答 0