Search code examples
iphoneopengl-estransparencyalpha-transparency

ISGL3D Transparency issues


I am running a iOS project using the isgl3d framework for showing pod files.

I have a stylish car with 0.5 alpha windows, that I wish to render on a camera background, seeking some augmented reality goodness.

The alpha on the windows looks okay, but when I add the object, I notice that it renders the entire object transparently, where the windows are. Including interior of the car.

Like so (in example, keyboard can be seen through the dashboard, seats and so on. should be solid)

bad car is bad

The car interior is a seperate object with alpha 1.0.

I would rather not show a "ghost car" in my project, but I haven't found a way around this.

Have anyone encountered the same issue, and eventually reached a solution ?

SOLVED: Thanks to Demi's answer. Here is the final code:

// Render opaque objects
        [_scene render:renderer opaque:true];

        // First planar shadow pass (if needed)
        [self renderPlanarShadows:renderer];

        // Render transparent objects
        glColorMask(1, 1, 1, 0);
        if (_zSortingEnabled) {
            [_scene renderZSortedAlphaObjects:renderer viewMatrix:&viewMatrix];

        } else {
            [_scene render:renderer opaque:true];
        }
        glColorMask(1, 1, 1, 1);

Solution

  • Problem: your glass rewrites alpha channel. Make it not modified when draw car's glass. Disable writes to color buffer's alpha channel when you drawing transparent items by using glColorMask(1, 1, 1, 0). Don't forget to restore after transparent drawing: glColorMask(1, 1, 1, 1)!!!