PDA

View Full Version : GL Problem with "blending"



TobiasReich
08-06-2012, 01:08 PM
Hello everyone,
I hope you may help me with this problem.
It might be not a specific OpenGL ES 2.0 problem since it happens on my android phone but when I tried to make a GL application, I got a weird problem.
My image is partly transparent. Behind the GL Surface is a camera image (for Augmented Reality).
my problem is, when I make the pixels semi-transparent in the fragment Shader I get a weird result. The brightest pixels seem overexpose. It looks like subtracting color values in Photoshop.
This doesn't happen without transparency and it happens only with the brightest pixels where I used something like:
gl_FragColor = vec4(clamp(textureColor.rgb * lightWeighting.xyz, 0.0, 1.0), 0.5);
I tried clamping in the shader but it didn't really work. I guess it is because there is still the camera picture behind making it "brighter".
Anyway, I hope someone here has seen that problem before.
Thank you for your help,
Tobias


P.S. I was trying a bit more to solve this problem.
I found that the Blend-Mode:
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA_SATURATE, GLES20.GL_ONE);
gives a rough solution for this. So when I do that quick-and-dirty solution, it somehow works. But still, there must be a better way to control the "oversaturation"...

https://dl.dropbox.com/u/13527005/glProblem.jpg

TobiasReich
08-07-2012, 05:26 AM
Okay, looks like nobody knows that problem. Maybe there is someone with a Galaxy S3 who might want to help me.
I made a very small test program to show this.
You may download the code here:

https://dl.dropbox.com/u/13527005/CameraGLTest.zip

or if you only want to test it you will find the .apk here:

https://dl.dropbox.com/u/13527005/CameraGLTest.apk

I would be very, very glad for any information about this. Even if you tell me it works perfectly fine on your S3. After all than I would know I have a problem with my phone!
Thank you very much for your help!
Tobias

TobiasReich
08-08-2012, 05:35 AM
Alright, I got an answer for that.
The problem was the premultiplication for the alpha values.
So in the easiest way it is enough to write:

vec3 color = clamp(textureColor.rgb * lightWeighting.xyz, 0.0, 1.0);
color *= 0.5; // premultiply by alpha
gl_FragColor = vec4(color, 0.5);

Even though I don't see why it worked perfectly fine on older systems and it I'm still not sure how to manage this on Gl1.0 where I can't write my own shader code.
So hope this helps to anyone who has the same problem!
Thanks,
Tobias