0
\$\begingroup\$

I'm trying to get some particles to work properly - they should blend among themselves but not with the background color. For this I'm using additive blending, textures with premultipled alpha and set the color as (r*a, g*a, b*a, 0) on textures I want to add up. I'm using the blend mode: glBlendFunc(GL11.GL_ONE, GL_ONE_MINUS_SRC_ALPHA); for everything.

I found out that what I want to do can be achieved by rendering and additively blending the particles in a framebuffer and then render that framebuffer on top of the background with standard alpha blending. In theory I think this should work..however i'm still getting the same result as I did before which is very bright particles at bright areas of the background.

So what I'm doing is simply: 1)Render the background as usual with color (r*a,g*a,b*a,a)

2)Bind my fbo

3)Use GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glClearColor(0f, 0f, 0f, 0.0f);

4)Render all the particles with color as (r*a,g*a,b*a,0)

5)Unbind the fbo and render it on top of the bg with (1,1,1,1) color.

Why doesn't this work?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

I think you may not entirely understand how destination blending works.

You claim that you set your output to (r*a, g*a, b*a, 0.0) and then use GL_ONE_MINUS_SRC_ALPHA for the destination blend factor. Because source alpha is constant (0.0) in this example, that works out to be equivalent to GL_ONE.

Likewise, if you apply GL_ONE, GL_ONE_MINUS_SRC_ALPHA in your second pass that effectively discards anything already in the color buffer:

SrcColor.rgba * 1.0   +   (1.0 - 1.0) * DstColor.rgba    =  SrcColor.rgba  =  (1,1,1,1)

In this case, you would be better off simply disabling blending in the second pass.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .