Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Additive v. Multiplicative Light and Shadow Blending  (Read 6107 times)

0 Members and 2 Guests are viewing this topic.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Additive v. Multiplicative Light and Shadow Blending
« on: March 11, 2017, 05:12:30 am »
I've been working on a new lighting system (wayyyyyyy more efficient than the raycasting one I posted a couple months ago).

Buuuuuuut, now I'm at a fork.  I need to choose between using a multiplicative algorithm for the lights/shadow blending and an additive method.  There is no performance difference, since the change is only in a couple fragment shaders.

Using a multiplicative method seems to make it appear as though the light is actually brightening the area around it, but the lights themselves are much less prominent (and this require some visual emphasis)

I have a system with 2 shadow casters (the two largest light sources) and 12 non shadow casing light sources.
This is what it looks like using a multiplicative algorithm:



This is what it looks like using an additive algorithm:


The big purple light moved a bit between the two, but that light follows the mouse. All the others are static.

I could go on for far too long about why I like one more than the other, but I want to hear what you think.

As far as 360-400fps for 14 lights goes in terms of performance, it's meh, but I'll optimize it later.

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Additive v. Multiplicative Light and Shadow Blending
« Reply #1 on: March 11, 2017, 10:25:02 am »
Well, the multiplicative method creates scenes with greater contrast, but it's not "orthogonal", if you know what I mean. It creates this mist-like/grungy-like effect, which looks great in your example, but indeed, it may not always be how one wants to use the lighting system. In this regard, the additive method is much less opinionated.

Still, I don't think you should just throw away the multiplication method, because it looks freaking awesome. I am not too much skilled in this area, but maybe there's a way to preserve both methods, letting the user choose the one that looks better in their case?
« Last Edit: March 11, 2017, 10:26:33 am by sjaustirni »

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Additive v. Multiplicative Light and Shadow Blending
« Reply #2 on: March 11, 2017, 06:57:33 pm »
True, thanks for pointing that out. I'm not sure what you mean by "orthogonal", but I think I understand what you were getting at.

Sure, I could make it so that one could choose between them, but right now that would be on a per-light-system basis. The only real difference between them is one line in their respective fragment shader

Multiplcative:
color.rgb = color.rgb + color.rgb * maskColor.rgb * lightIntensity;

Additive:
color.rgb = color.rgb + color.rgb + maskColor.rgb * lightIntensity;

It wouldn't  bee to hard to change it so that every light could independently choose how to illuminate the region around it.

Maybe the multiplicative one, with the "mist-like/grungy-like effect" as you said, would be good for eerie/dark/thematic scenes.
I guess what throws me off with the additive one is that it doesn't seem to brighten the scenery. It sort of slaps a translucent sheet on top of it.  The multiplicative one amplifies scenery colors (if I move the lights into a darker area, they are much less apparent, since there isn't anything to actually make brighter, which isn't the case for the additive one).

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Additive v. Multiplicative Light and Shadow Blending
« Reply #3 on: March 11, 2017, 11:03:50 pm »
By "orthogonal" I meant "with no side-effects". Maybe it wasn't the best usage of this word though.

It wouldn't  bee to hard to change it so that every light could independently choose how to illuminate the region around it.
If it's a dedicated lighting library, I would surely allow for writing one's own shaders for lights, maybe with some basic defaults. It would be surely for the best, considering how many blending modes are actually being commonly used.

I guess what throws me off with the additive one is that it doesn't seem to brighten the scenery. It sort of slaps a translucent sheet on top of it.  The multiplicative one amplifies scenery colors (if I move the lights into a darker area, they are much less apparent, since there isn't anything to actually make brighter, which isn't the case for the additive one).
Indeed, that's how addition works. If you take a look at the link I have posted above, maybe you're actually after a different blending mode, like screen, or gamma_bright. If I were you I would try out all of them, just for the sake of it :D
« Last Edit: March 16, 2017, 09:33:23 pm by sjaustirni »

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Additive v. Multiplicative Light and Shadow Blending
« Reply #4 on: March 16, 2017, 07:47:44 pm »
Why not use a combination of both?

I use this (with an additional guassian blur) in addition to my modified LTBL2, which is multiplicative, for a pseudo bloom shader.
The result of both gets then blended additively onto the finished, multiplicative blended image.
Overall, this makes the lighting way nicer.

I'm sure you could pick out the relevant parts...
Code: [Select]
uniform sampler2D currTex;
uniform sampler2D lightCompTex;
uniform sampler2D specCompTex;
void main()
{
        vec2 coord = gl_TexCoord[0].xy;
   vec4 frColor = texture2D(currTex, coord);
   vec4 lColor = texture2D(lightCompTex, coord);
   lColor += texture2D(specCompTex, coord);
   float lstrength = clamp(dot(lColor.rgb, vec3(0.2126, 0.7152, 0.0722)), 0.0, 1.0);
   float brightness = dot(frColor.rgb, vec3(0.2126, 0.7152, 0.0722));
   if (lstrength > 0.1)
   {
      gl_FragColor = vec4(lColor.rgb, lstrength * brightness);
   }
}