• ### What is your GameDev Story?

This topic is 593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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];



• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015575
×