2
\$\begingroup\$

Should one do additive blending (aka lightmapping) in linear space?

I tried doing it in linear space, and it became, well, linear and bland, losing that cool HDR-style bloomy effect. Is there some standard way to do additive blending in linear RGB, or additive blending is now an obsolete gamma space hack and people should forget about it?

\$\endgroup\$
  • \$\begingroup\$ The standard way to do additive blending in linear RGB is to just add two numbers — nothing fancy. If doing that isn't giving you the effect you like, you can use a different blending function. Try showing us an example of the output you have now, and how it differs from the output you want, and we can suggest ways to get closer to your desired effect. \$\endgroup\$ – DMGregory Aug 26 at 22:12
  • \$\begingroup\$ Here I applied a light to a background in gamma and in linear space: imgur.com/M8Lmmje \$\endgroup\$ – SmugLispWeenie Aug 26 at 22:19
  • \$\begingroup\$ If you like the gamma space effect better, then it sounds like you already have a solution. What do you need from us? \$\endgroup\$ – DMGregory Aug 26 at 22:19
  • \$\begingroup\$ Just curious what is the industry standard to apply such lightmaps today, when everything is done in linear space. \$\endgroup\$ – SmugLispWeenie Aug 26 at 22:21
  • \$\begingroup\$ (a^gamma+b^gamma)^(1/gamma) is not equal to (a+b)^(1/gamma) \$\endgroup\$ – Ocelot Aug 26 at 22:28
0
\$\begingroup\$

If you want to reproduce the type of additive blending you'd see in a photo editing app like Photoshop, you probably want to have both the source and the destination in a gamma-corrected color space such as sRGB. If you want to reproduce how light actually works, you should leave your colors in linear RGB.

When photo editing apps first implemented blend modes, they were done in a gamma-corrected color space. Doing an add of 2 colors in such a space (especially in 8-bits per channel) would cause a lot of clipping of colors. Because of this, there were blend modes that achieved some of the desired light-like effects in the gamma-corrected space. For example, the "screen" blend mode in gamma-corrected space looks a lot like an "add" blend mode in linear space.

Fast-forward 20 years and these apps started adding linear RGB as an option for editing and suddenly all the blend modes look "weird" (at least to users who had been doing gamma-corrected blending for the last 20 years). So some applications do a gamma correction before doing blending, and then convert the result back to linear afterwards. So if that's working for you, it's an absolutely fine way to do it. You wouldn't be the first!

See for example, this book:

Artists have dealt with the problems of working directly in video space [i.e. gamma-corrected space] for years without even knowing. A perfect example is the Screen transfer mode, which is additive in nature but whose calculations are clearly convoluted when compared with the pure Add transfer mode. Screen uses a multiply-toward-white function with the advantage of avoiding the clipping associated with Add. But Add's reputation comes from its application in bright video-space images. Screen was invented only to help people be productive when working in video space, without overbrights; Screen darkens overbrights (Figures 11.11a, b, and c). Real light doesn't Screen, it Adds. Add is the new Screen, Multiply is the new Hard Light, and many other Blending modes become evident as mere kludges in linear floating point

\$\endgroup\$
  • \$\begingroup\$ Both GIMP and Photoshop still have gamma-space as the default mode, so artists need to be careful. But gamma space has a nice property of somewhat matching human perceptual gamma curve, which is dynamic, adjusting to environment brightness. Meaning artists don't have to do pow(x,2.2) each time. That appears to be the single biggest reason graphics editors still operate in gamma space. \$\endgroup\$ – SmugLispWeenie Aug 29 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.