3D Opaque Polygons with OpenGL and weighted OIT

194 views Asked by At

I'm having trouble getting opaque polygons to not be transparent. I'm using a formula from this site:

Weighted Order Independent Transparency

Here's my code:

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);

I couldn't get multiple glFragData[n] working and from what I understand OpenGL ES doesn't support more than one anyway. The Yellow polygon should be totally opaque but in the pictures it's not. How do I get it opaque and everything else transparent? Also how do I create half transparent half opaque polygons?

Here is a picture that I generated:

enter image description here

0

There are 0 answers