(For Artists) The Pitfalls of LDR Bloom, Plus a Word on HDR vs. LDR

Hello. I'm Hirayama from the Technology Department.
I wrote about an LDR (Low Dynamic Range) bloom effect before, and this time I'd like to explain, for artists, the problems that come up when you do bloom in LDR.
The short version: "adding it later isn't that easy." In fact, on one of our products recently, there was talk of adding it, but we ended up putting it on hold.
An LDR implementation comes with quite a few constraints, and for several reasons it's hard to just "slip it in later and call it done."
There's only 0 to 255
A game redraws the whole screen every frame, and the canvas it draws to comes in two broad kinds.
- LDR (Low Dynamic Range)
- HDR (High Dynamic Range)
LDR usually means writing numbers in the range 0 to 1 in 256 steps. Each pixel takes one byte for each of R, G, B and alpha, so four bytes in total.
Most of the time, HDR means writing numbers in the range 0 to 65,000 in 65,000 steps. The format is designed so the steps get finer where the numbers are small, giving roughly 2,000 steps between 0 and 1. LDR has only 256 steps, so that's eight times finer. On top of that, you can write big values like 10, 100 or 1,000, so it can express far more than LDR. In exchange, each pixel takes twice the memory: eight bytes.
Dynamic range means "the range of values you can express," and where LDR has only 0 to 1, HDR stretches all the way to 65,000, so of course HDR is better.
Unfortunately, though, bigger means slower. Also, older devices can't use HDR at all. Even so, bloom is a technique originally designed for an HDR canvas. I'd like you to know that doing it in LDR is, fundamentally, forcing things.
So let's dig into exactly what is being forced.
I want the character's gloss to dazzle
First, take a look at the screenshot at the top. That, shall we say, peculiar character's head is gleaming. Thanks to the bloom effect, the highlight spills out past the polygon edges and glows. I'm going for an anime-style look, so the background is just a texture slapped onto a Quad, with no lighting calculation. But making this image takes a bit of work.
First, let's try it naively. Place the background and the character normally.

I gave the character a metallic material and kept everything but the highlight fairly dark.
Now, let's turn on bloom.

That's way too blown out. The settings I used were:
- take the areas where each of R, G and B is 0 or more
- blur them and add them at 1x intensity
Black areas hardly spread, but white areas spread white and red areas spread red, so this is what you get. I only want the really bright areas to spread, not the ones that aren't all that bright, so these are bad settings. Let's change them.

It's better, but the background shouldn't be glowing, right? The setting here is:
- extract and blur only the areas where each of R, G and B is 0.5 or more
but with a threshold of 0.5, the background still glows this much. Only the character's head needs to glow. Let's raise the number further.

Now it extracts only the areas at 0.9 or more, but the background is still glowing.
Of course it is. As you can see from the background image, it has deep red areas and very green areas. In the deep red areas, R is about 1, which easily clears 0.9.
So... what are you supposed to do?
HDR doesn't have this problem
The problem is that you can't tell "areas that are red or green" (the background) apart from "areas that are really shining" (the character's highlight). White is 1, and a dazzling spot where the sun is reflecting hard is also 1. There's simply no way to extract only the latter.
But if the canvas were HDR, there'd be no such problem. That's because you can write values up to 65,000. If the character's highlight writes 100 or 1,000 and the background writes about 1 at most, they're easy to tell apart. Extracting and blurring only the very bright areas is easy.
The real problem is that "nothing above 1 fits." Now you can see what I mean when I say doing bloom in LDR is unreasonable.
So what do we do?
There are a few ways, but the one with the least impact on the existing rendering is to "make values bigger than 1 fit into an LDR canvas."
You may be thinking, "Huh?" After all, I just said that "an LDR canvas only holds 0 to 1."
But there's a trick: change how the values are interpreted. You can reinterpret them later as "a 1 in here actually means 10." In other words, when you first draw, you write values at 1/10. The background's white is 1, so you write a tenth of that, 0.1; the character's highlight is 10, so you write 1.
Then you can "extract and blur only the areas above 0.1." And once all the processing is done, you multiply the result by 10.
You may think, "If you can do that, why not just do it?" But it comes with a sacrifice. Let's try it and see.
Draw at a tenth, then multiply by 10 at the end
First, bring the colors of the background texture down to 1/10. Editing the texture is a hassle, so let's multiply by the material color to get it down to 1/10 instead.

For the character, set the light intensity to 1/10.

Note that the ambient light also needs to be brought down to 1/10. In Unity, you lower the ambient intensity in Lighting Settings.

And with all that,

this is the image we get without bloom. It's almost pitch black, but the character's highlight alone stays white. That's promising. In fact, shaders that do lighting calculations produce values like 10 or 100, and the only reason they didn't go above 1 was that the canvas is LDR. Even if you cut the light to 1/10, 100 only drops to 10, which is still plenty bright, so a bright color gets drawn as you see here.
Now, in this state, let's turn on bloom with settings that extract and blur 0.1 and above. My bloom has a color filter feature that can scale the result by some factor after processing, so I'll use that.

ColorScale is set to 10, which multiplies the result by 10. I tuned the bloom intensity to a reasonable value (about 4 in this example).

Sure enough, only the highlight glows and the background stays as it was, but what is this blocky, jagged stuff?
This is the "sacrifice" I mentioned earlier. What we sacrificed is precision.
LDR normally expresses 0 to 1 in 256 steps. If you draw at 1/10, the original 0-to-1 range gets only a tenth of the steps: just 25. Can you see that the colors outside the highlight are banded and ugly too? If you take something with only 25 steps and multiply it by 10 afterwards, of course it looks ugly.
Compromise
The range of brightness in the natural world is enormous. The ratio between everyday objects and the sun is nowhere near as small as 10x or 100x; it's on the order of tens of thousands. Even an ordinary object and a glowing light bulb differ by about 100x, so ideally I'd blur only the areas holding 10 or 100, but precision rules out even 10x.
There's no way around it, so let's settle for 2x. Draw at half brightness, and multiply by 2 later to restore it. Where we put 0.1 earlier, we now put 0.5, and where we put 10, we now put 2.

In fact, this is the screenshot from the top.
Since only 128 steps are left for 0 to 1, the precision drops quite a bit, and Mach bands show up too, but if you're going to force bloom into LDR, you'll just have to live with that. There are fancier tricks, but they add load, which defeats the purpose.
Summary
What I've introduced here is, I think, the cheapest way to do bloom in LDR. The steps are: "draw everything darker at a fraction of the brightness, set the values so the unwanted areas don't glow, apply bloom, and restore the brightness." In practice, because of the precision problem, 2x is probably the limit.
Cheap as it is, though, retrofitting it is not a simple matter. At a minimum, you need to be able to change the brightness things are drawn at without touching the textures. Reworking the textures would cost far too much to even consider. The standard Unlit/Texture shader doesn't accept a multiply color, so if you've built with it, you'll have to start by swapping shaders.
And even if your shaders accept a multiply color so you don't have to rework textures, anything with "no lighting calculation (Unlit)," as in this example, needs its materials adjusted one by one. In that sense, anime-style backgrounds and additively blended effects are troublesome. For effects, you could move them to a separate camera and "finish post-processing before drawing the effects," but that doesn't work for backgrounds. There probably aren't that many backgrounds, but work is still work.
By the way, this may sound odd after working so hard to make LDR work, but "just go HDR" is of course an option. If you want bloom, that's the most straightforward choice. On devices with fast memory that don't slow down much when the canvas (render texture) gets bigger, that should be fine. You could detect the device's performance somehow and switch to HDR when it's up to the task. Set the camera to use HDR and use the standard PostProcessingStack. If you have performance to spare, there's no need for clever tricks.
That said, there have been devices with restrictions like "anti-aliasing doesn't work in HDR." The safe course is probably to test on a fair number of devices and check their performance and feature restrictions.