Odd transparent Overlay behavior

Started by grassick, October 10, 2013, 08:29:24 PM

Previous topic - Next topic

grassick

I have an Overlay which I want to be mostly transparent (it is of a non-rectangular shape). I create a Texture (Texture tex = new Texture(myimage, true);) and then display the Overlay.

The GLSurfaceView is translucent, so I'd expect to see my Overlay on top of all objects but only opaque in non-transparent parts.

What happens is that it is indeed transparent in the right places but still obscures 3d objects behind it. That is, it keeps the GLSurfaceView transparent in the right places, but doesn't allow 3d objects to show though the transparent parts!

Since this is for an augmented reality app, the effect is that the overlay displays the camera preview perfectly underneath but obscures 3d objects for the overlay's entire bounds.

I should add that I'm using alpha transparency in the image and that it appears to me that Overlay is blitting the entire texture up, including alpha, rather than blending it according to the alpha. That would explain the behavior I see.

What on earth am I doing wrong?

Thanks,

Clayton

EgonOlsen

You aren't doing anything wrong. That's the way it works, i'm afraid. The alpha gets written into the frame buffer and so an alpha of 0 makes everything translucent, which is why your objects disappear behind the overlay. We had this problem before and i wasn't able to come up with a proper solution for this. The problem is that the alpha based blending happens at a stage in the gl pipeline that comes after shader execution, so i don't see how to fix it with a shader. The other option is to disable alpha writes but that would make the overlay itself disappear except for those parts which have another object behind it, i.e. more or less the opposite of what you have now. Here i are more detailed thoughts about this: http://www.jpct.net/forum2/index.php/topic,2907.msg21437.html#msg21437

If you have some clever idea of how to handle this, i would be glad to hear it...i don't have any ATM.

grassick

Aha!

http://stackoverflow.com/questions/2361602/transparent-texture-in-opengl-es-for-android gave me a suggestion.

I added:

   public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      // Enable blending using alpha
       gl.glEnable(GL10.GL_BLEND);
       gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
   }


Seems to solve it perfectly.

EgonOlsen

I don't see how this is supposed to work in a more complex scene, because it will interfere with what the engine does internally. I suggest to try to get the Object3D from your overlay and add that code into an IRenderHook implementation that you attach to that object (similar to what the thread that i linked to suggested) and also disable GL blend after rendering the overlay.