## Recommended Posts

I'm having trouble with additive blending, Im trying to draw particles onto a black background additively so they build up to white at the center. However a single particle (point) is saturating to white immediately. Any RGB values seem to saturate to 1, this is not what I expected.

Shader output color is: RGBA .5f, .1f, .1f, 1.0f

Clear Color is: 0,0,0,0

No Blending:

[attachment=35984:NoBlend.png]

Blending (GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);)

[attachment=35985:PinkBlended.png]

I was not expecting white, I was expecting the same red as the first image.

Am i misunderstanding additive blending? Or am I doing something else wrong? I've hacked my app to pieces trying to solve this.

I've checked the shader output, I can change the colors and it matches up outside of blending.

Blending is enabled, if i use a dark blue background with dark red particles I get pink/purple, its just 100% pin not dark pink.

Im only drawing once, I'm not drawing the same particles on top of themselves several times.

Its not just the particles, the whole scene whites out if I draw it with blending enabled.

I've tried rendering to the backbuffer, an fbo and a multisampled FBO, same thing.

Any other suggestions are welcome.

Thanks,

Arthor.

##### Share on other sites

Are you sure you clear the framebuffer often enough and not drawing the same particles multiple times over themselves?

##### Share on other sites

In your no-blending example, why are you getting red dots when the shader output is RGBA .5f, .1f, .1f, 1.0f ? Typo?

##### Share on other sites

In your no-blending example, why are you getting red dots when the shader output is RGBA .5f, .1f, .1f, 1.0f ? Typo?

0.5/0.1/0.1 is a dark shade of red.  This is what it looks like.
If you view the screenshot in an image editor you'll see that they have RGB 121/23/22 which is (mostly) correct (allowing for rounding and FP imprecision).

Is this a single-buffered GL context?

##### Share on other sites

Additive blending is not just about the colours but about the alpha, right? So I would have expected to see a SRC_ALPHA in there somewhere.

##### Share on other sites

Sorry for slow replies, I've been working and sleeping...

Are you sure you clear the framebuffer often enough and not drawing the same particles multiple times over themselves?

I'm clearing every frame right before I draw. I thought the same thing though, I have checked and I'm sure I'm only drawing the particles once and everything else is disabled.

Is this a single-buffered GL context?

Not 100% sure how to check but I think I'm using double buffering. Would this affect blending?

Additive blending is not just about the colours but about the alpha, right? So I would have expected to see a SRC_ALPHA in there somewhere.

My understanding is that ONE forces the alpha to be 1, resulting in 1 times the src and 1 times the dst colors being blended together so the alpha is still involved its just not affecting the colors. I'm going to have a play with different blending modes though and see if I can work around this, or if they give dodgy results too (I cant remember what I tried last night.).

I'm still struggling though any more advice is greatly welcomed.

##### Share on other sites

In your no-blending example, why are you getting red dots when the shader output is RGBA .5f, .1f, .1f, 1.0f ? Typo?

0.5/0.1/0.1 is a dark shade of red.  This is what it looks like.
If you view the screenshot in an image editor you'll see that they have RGB 121/23/22 which is (mostly) correct (allowing for rounding and FP imprecision).

Is this a single-buffered GL context?

Doh - I misread it as RGBA .5f 1f 1f 1.0f somehow!

Edited by C0lumbo

##### Share on other sites

Doh - I misread it as RGBA .5f 1f 1f 1.0f somehow!

There's probably a useful discussion to be had (which may be more appropriate for a different subforum) about leaving out '0's in float constants like this.

##### Share on other sites
Try to set blendfunc to gl_src_alpha, gl_one

I dont remeber the blending formula but it should do anyway set clear color alpha to 1

Find blending formula and check if that was glone, gloneminussrcalpha

##### Share on other sites

Be sure to disable depth-testing if you want a proper additive blend.

For additive blending, I do something like this: (this is for iOS)

//Setup
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(10000.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_DEPTH_TEST);

//Loop
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
[scene draw];



##### Share on other sites

Another reason may be that clears are affected by the current write masks; if you have glColorMask (0, 0, 0, 0) when you clear, the color buffer will not be cleared!  This will result in multiple frames work accumulating in the manner described by the OP.

##### Share on other sites

I never worked out why GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One); was giving me the results I got but I have worked around it.

I used GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.SrcAlpha); instead and manually set my alphas to 1.0f in the particles. This results in a 1 in the destination after a particle is written and then any source particles thereafter are also 1.0f, which is what I wanted in the first place, I do not understand why the result is different though. Perhaps I'm not understanding what GL_ONE is supposed to do or perhaps OpenTK is passing the wrong enums, but I'm just guessing. Hopefully this helps someone else if they get stuck though.

Thanks for all of the suggestions,  helped me work though an alternative method.

##### Share on other sites

Glad it worked out! I'm not surprised by this at all with OpenTK.  I've seen similar bizarre behavior.

##### Share on other sites
Once again http://www.andersriggelsen.dk/glblendfunc.php
and set alpha to 1

## Create an account

Register a new account