OpenGL blending issue

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Apr 10, 2013 at 11:54

I did a quick demo for a company, I can’t show any screen shots, or talk about the app, as it is wrapped up in the sort of NDA that is scary.

In general though it has fixed elements and moving elements. The fixed elements are drawn onto the opengl screen with alpha blending enabled. I don’t clear the screen, so the moving elements fade out gradually.

The issue is that they never fade out completely. You end up with a very feint gray shadow on the screen.

I don’t understand why

Say you start out with a value of 64 and alpha blend 0,0,0,0.9 over the top

final pixel = 64*0.1 + 0*0.9 = 6.4
final pixel = 6*0.1 + 0*0.9 = 0.6

So it should go to zero

Anybody know why it doesn’t

2 Replies

Please log in or register to post a reply.

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 Apr 10, 2013 at 12:08

Assuming ONE_MINUS_SRC_ALPHA / SRC_ALPHA and the default blend formula you should get what you described.

However, if you have the formula reversed (1-a and a swapped), you get:

out = dst*0.9+0*0.1

which leads to:

64,58,52,47,42,38,34,31,28,25,23,21,19,17,15,14,13,12,11,10,9,8,7,6,5,5,5,5,5,5,5,5,5,5,5,5,5….

(5*0.9 = 4.5 \~ 5)

Any alpha value more or equal than 0.5 won’t fade to black because the result will eventually get rounded to more than 0.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Apr 10, 2013 at 13:31

It rounds up? :angry:

man thats’ a pain in the proverbial