I’m trying to make a transparency scheme in which no matter how many transparent objects I have in front of the background I apply the transparency only once for a pixel (e.g., if A is in front of B wich is in front of the background, I will never draw B, and always will blend A with the background). My current approach of doing that is by double drawing: first draw all the objects depth-only, and then draw with depth function set to GL_EQUAL and draw everyrhing with the required alpha.
As I have a lot of these objects that need to go transparent, this hurts my performance (I double the number of draw calls).
An alternative solution that I found is by using glCopyTexImage2d. Instead of relying on OpenGL blending, I do the following:
- copy the background to a texture with glCopyTexImage2d
- in the fragment shader, instead of using OpenGL sandard blending, I blend myself each pixel against this background texture
The result on my PC is super ok. I’ve got quality transparency and the number of draw calls isn’t increased.
However, the same code doesn’t work on my target hardware (PowerVR Rogue Hood, OpenGL ES 3.0 build 1.2.WINEC7@2829345)
The problem that I have is that the code produces a lot of flickering. Moreover it seems to be pretty slow.
The flickering is called by the glCopyTexImage2d call.
Prior to glCopyTexImage2d call I’ve tried the following:
- set the readbuffer to GL_BACK (making sure )
- set the proper viewport
- glFinish / glFlush
Do you know what can cause the flickering?
Is there another alternative to obtain the same transparency scheme?
Unfortunatelly adding FBOs to my application is much more complex. This transparency scheme is only applied at some step of my rendering process, and only in certain conditions.
Thank you very much