Additive blending, am I doing it right?

Hey guys,



So I have a multi-target framebuffer with 3 colour buffers. I also have a material that outputs to all 3 of these colour buffers like so:

[java]

outColor3 = vec4(newColorInfo.xyz, 1.0);



vec4 zero = vec4(0.0);

outColor1 = zero;

outColor2 = zero;

[/java]



I am using additive blending on the material. Here are the results I get from two different geometries (I’m working on a deferred implementation, so these are spheres representing point lights)

http://i.imgur.com/PxJIn.png

http://i.imgur.com/fpSVU.png



The output is the colour buffer holding the results of the shader. It seems when the lights cross over the results are not what additive blending should look like… or is it?

Additive makes sense only in a forward rendering process i guess.

It means the color is added to what was previously rendered.



Since you are in a deferred process, those lights are rendered in the same pass. I think you should add the color yourself in the shader.



I don’t completely understand what we are looking at, is it the scene albedo or the final render with lights?

Ah… I see what you are talking about. Additive should increase the intensity where the lights cross over (but only if your not including the black background). This definitely doesn’t look right.



color = background;

color += light1;

color += light2;



Would give you the results in the picture above.



Try additive for the lights only and use mix() to add them. Bet that will give you the results you are expecting.

No, mix does not add, mix linearly interpolate between 2 colors.

To add…you just have to add

@nehon said:
No, mix does not add, mix linearly interpolate between 2 colors.
To add...you just have to add


I know this... what I am saying is additive including the background will just detract from the intensity of the lights. black + white + white is going to fade the initial light, which will in turn fade the second light even further.

Try it... you'll get the same results you see in the image above.

Using additive for the lights alone... and then mixing them with the original color (whether through mix() or *= or some other method of blending the two results) will at least have the effect he is looking for when two lights cross over each other.

EDIT: Actually adding the two lights together separately and then adding them to the background would work as well... it's the order in which its being done now that is the problem.
is it the scene albedo or the final render with lights?

It's just the albedo (assuming I understand that term :)). What the pictures represent are just the diffuse lighting in the scene and everything else is black

Additive should increase the intensity where the lights cross over (but only if your not including the black background)

Yep, that's the part that's confusing me! I'm not sure exactly what's going on here...
Is it not true that the black background shouldn't affect anything?

For instance:
color = 0,0,0,0 (scene clear colour)
color += 0.3, 0.3, 1.0, 0.3 -> color is 0.3, 0.3, 1, 0.3 (some-light... the += is done through additive blending. So I am not actually writing +:)
color += 0.5, 0.5, 0.5, 0.8 -> color is 0.8, 0.8, 1.5, 1.1 (does this amount get normalized as opposed to capped?)

In my brain I am seeing the black just being a starting value. Something that doesn't really do anything. I made sure no colours are going negative as well, so I am kind of at a loss.

you should add the color yourself in the shader

I am not sure how to accomplish this. Since the previous colour is part of the texture I am rendering to I don't have access to it :(

Sorry to waste everyone’s time! The result is actually what it’s supposed to look like. I haven’t tried with actual flashlights on my floor but I made this image in Flash using circle gradients and the result is the same.



http://i.imgur.com/AbmZy.png



Thanks for the input guys. Maybe someone else will get fooled by a similar result and this thread will be useful!