News for hackers. Stuff that matters.
Re:Games Look Bad: HDR and Tone Mapping by oppositelock on Monday October 23, 2017 @04:41PM (#15536777)
I've spent years working on rendering algorithms and game engines, so I guess I am a graphics programmer.

You are right, the final output dynamic range is limited by your output device, you can't circumvent that.

The 1,000,000:1 is the contrast ratio you might see on a sunny day, and represents the state of the world that your eyes are seeing.

Your eyes aren't capable of 1,000,000:1 contrast either, at least not globally across your field of vision, so we can play tricks in rendering to simulate what you would perceive with your limited eyeballs on a 1M:1 contrast ratio day, and this is what HDR rendering does.

Internally, the rendering code handles luminance well in excess of its ability to display on the final output device. All the game rendering happens internally in HDR, preserving this high level of contrast. The final steps of producing a displayable image are doing something to convert non-displayable "real" contrast ratios into post-processed simulation to fool you into perceiving high contrast scenes. This last part is subjective and artistic, since you are trying to figure out a way to show that high dynamic range scene. Common tricks played here are the light bloom from bright areas, the artificial amplification of darks areas, etc.

All these in-between rendering steps compose the result of multiple rendering passes into an image. Each pass which is blended with the results of a previous pass is subject to quantization error. The more passes you do (and modern games do lots), the more this quantization error accumulates, and leads to pretty ugly banding artifacts. You want to do your internal processing in the highest color resolution that you can, so that you only have to worry about the error of quantizing the 1M:1 scene into a 256:1 output device. You don't need the full 20 bits, and common practice is to use 16-bit S10E5 floats since hardware handles this quickly.

HDR televisions, while nicer than nothing, don't help you all that much. Displays have generally been 8-bit per channel, giving you 256 values distributed along a gamma curve which maps to a device with perhaps 3,000:1 contrast capability. HDR tv's give you 1024 values along a gamma curve that spans a higher range of contrast, but not all that much higher.

Re:Games Look Bad: HDR and Tone Mapping by ttoinou on Monday October 23, 2017 @04:54PM (#15536851)
OK but that doesn't explain this sentence from the original blog post :

   In the real world, the total contrast ratio between the brightest highlights
   and darkest shadows during a sunny day is on the order of 1,000,000:1.
   We would need 20 bits of just luminance to represent those illumination ranges
Re:Games Look Bad: HDR and Tone Mapping by jacobolus on Monday October 23, 2017 @05:02PM (#15536909)
Theoretically you can have arbitrary contrast with 1 bit (white = looking at the sun, black = 1 photon per square centimeter per year, or whatever). The author probably has some specific amount of brightness discrimination in mind that he wants to adequately capture. For example, with brightness levels corresponding to just-noticeable differences in terms of human perception, after adapting to looking at that specific portion of the scene.

In practice modeling vision precisely gets really complicated because there are several types of spatial and temporal adaptation and contrast effects that the human visual system can undergo / be affected by, and something like a video game definitely doesn’t have the computation available to handle it perfectly (not to mention the programmers don’t want to implement anything that complex and finicky). There is also a complication that display black is never especially close to zero light, and depends a lot on the light hitting the display. Etc.

So for practical purposes you just have to come up with some kind of “good enough” heuristic.

Re:Games Look Bad: HDR and Tone Mapping by dragonwriter on Monday October 23, 2017 @06:51PM (#15537580)
> The author probably has some specific amount of brightness discrimination in mind that he wants to adequately capture.

The assumptions seems to be a linear illumination scale with the darkest value at 1 (with true absence of illumination at zero); 1,000,000:1 needs about 20 bits for that.

Re:Games Look Bad: HDR and Tone Mapping by ttoinou on Monday October 23, 2017 @05:06PM (#15536935)

   So for practical purposes you just have to come up with some kind of “good enough” heuristic
Ok I agree ; that's what I'm saying to chrisseaton
Re:Games Look Bad: HDR and Tone Mapping by baq on Monday October 23, 2017 @06:06PM (#15537329)
2^20 is just above 1M, so that's how many bits you need to capture the darkest and the brightest pixel without losing information (brightest/darkest = 1M). the assumption is that you tone map those 20 bits onto however many bits you have available (8 for standard display, 10 for HDR, 14 for DSLR sensor, etc.) - at least that's my understanding after consulting wikipedia.
Re:Games Look Bad: HDR and Tone Mapping by chrisseaton on Monday October 23, 2017 @06:43PM (#15537546)
Either I'm crazy or everyone else is :) You still have lost information with 20 bits. There are an infinite number of levels of light between the darkest and the brightest. With 20 bits you can represent 1,000,000 steps between darkest and brightest. Why do you need to represent 1,000,000 steps? Why does it matter that the brightest is 1,000,000 times brighter than the darkest? 20 bits lets you represent ones times brighter, two times bright, etc up to 1,000,000 times brighter, but what about one-and-a-half times brighter? You can't represent that in 20 bits. Why doesn't that matter?

The article says that the highest light level in a scene is 1,000,000 times brighter than the lowest. It does not say, or even imply, that you can see the difference between those levels of light to a one in a million, which is what 20 bits needs.

Can you see what I mean? The factor between the lowest and the highest is entirely separate from the question of how many levels between you can see, which is what directs how many bits of resolution you need.

Re:Games Look Bad: HDR and Tone Mapping by symstym on Tuesday October 24, 2017 @12:04AM (#15539125)
I'm not sure this is a constructive comment, but I just wanted to say that you are completely correct, everyone else is crazy, and I am baffled at how much confusion there seems to be over this topic.

One thing to add: Wikipedia sayeth "the eye senses brightness approximately logarithmically over a moderate range". If we go with that, then you presumably want to encode brightness logarithmically, and the number of bits you have available will determine the ratio between your adjacent quantized levels. In that case I believe the ratio between adjacent levels would be exp(ln(max_range_ratio)/(2^bits)).

Re:Games Look Bad: HDR and Tone Mapping by Promit on Tuesday October 24, 2017 @01:34AM (#15539463)
You don't want to encode brightness perceptually until you're showing it to the user. You need a linear space to actually do lighting calculations, which means physical luminance values. Within that space, you can use whatever scale you wish, with consequences to banding and quantization artifacts for decimating the bit depth. Tone mapping includes conversion to a log space via the gamma curve.

I explained it in another comment but basically the "20 bit" value is based on an idealized digital image sensor rather than a game rendering pipeline (which operates in floating point). It has admittedly proven somewhat confusing.

Re:Games Look Bad: HDR and Tone Mapping by Dylan16807 on Tuesday October 24, 2017 @02:49AM (#15539719)
It's worth noting explicitly that floating point numbers let you have a linear scale but logarithmic-ish storage at the same time. A 12-bit float could represent a 1:1000000 range, let you perform normal linear math, and also be just as banding-free as a 20 bit integer.
Re:Games Look Bad: HDR and Tone Mapping by onikolas on Tuesday October 24, 2017 @01:30AM (#15539443)
That's why even the good old 8 bits per channel images are encoded logarithmically. Enter the gamma curve: https://en.wikipedia.org/wiki/Gamma_correction
Re:Games Look Bad: HDR and Tone Mapping by Taniwha on Tuesday October 24, 2017 @05:07AM (#15540237)
no - the REASON why we use gamma is deeply historical and has essentially to do with trying to build TV receivers with the minimum number of vacuum tubes
Re:Games Look Bad: HDR and Tone Mapping by mark-r on Tuesday October 24, 2017 @07:48AM (#15540878)
Is it just a coincidence that the gamma curve also corresponds roughly to our eyes response to light? Awfully lucky if it was.
Re:Games Look Bad: HDR and Tone Mapping by dastbe on Monday October 23, 2017 @07:33PM (#15537847)
To be honest I think everyone else is crazy and/or doing a calculation without thinking about what it means.

All we know is that the range is N to 1000000N, but we do not know in and of itself that N is the smallest delta perceivable or possible.

Re:Games Look Bad: HDR and Tone Mapping by chrisseaton on Monday October 23, 2017 @07:45PM (#15537923)
Well since at least one person thinks I'm not crazy I'll stop trying to argue now - thanks!
Re:Games Look Bad: HDR and Tone Mapping by trishume on Monday October 23, 2017 @08:55PM (#15538313)
I think you're making sense.

I don't know anything about games but at least in cameras the relation you want between the bit depth and dynamic range is determined by what you want to measure rather than a formula. An eye tracker I have is a 10-bit IR camera because a normal 8 bits are insufficient to both note that IR LED reflections are way brighter than everything else, while also having sufficient detail in the lower values that the edges of the pupil are easy to detect. At least, without having the scale be logarithmic or discontinuous or otherwise compressed.

Re:Games Look Bad: HDR and Tone Mapping by onikolas on Tuesday October 24, 2017 @01:28AM (#15539433)
You are correct. Luminance is a real number not integer so the more bits the better (unless you go all they way down to photons!). So, more bits allow us to increase the dynamic range and also allow more values in that dynamic range.

The real benefit of HDR is in the "more values" part since, as the author notes, our displays have a very limited dynamic range anyway.

Re:Games Look Bad: HDR and Tone Mapping by tripzilch on Saturday October 28, 2017 @06:23AM (#15574636)
Yes. I'm leaning towards a "didn't really think it through" oversight on the author's part, rather than fundamentally confusing signal-to-noise ratio (which is what more bits give you, if you treat em right) with numerical range.

Hell, I like to think I'm somewhat knowledgeable about these things and I read straight past that line thinking "that's a million, that's about twenty bits, okay".

But you are absolutely right, now that you pointed it out it's obvious.

And indeed you can get the same range using only one bit (per channel, that is) and if you had high enough (very high) resolution and proper dithering, you'd totally get away with it, too. In that case, the tonemapping goes just before the dithering.

Re:Games Look Bad: HDR and Tone Mapping by thibauts on Thursday October 26, 2017 @02:31AM (#15556840)
The straight to the point answer is yes, you can use less bits to encode the same range, though for practical matters you'll get strong banding as a result. That is because the log curve applied to make the range viewable on a screen will stretch the lowest part of the range. Moreover, the multiple passes made in the linear (wide) range will produce artifacts viewable in screen space much more quickly.
Re:Games Look Bad: HDR and Tone Mapping by tripzilch on Saturday October 28, 2017 @06:31AM (#15574650)
The only negative result you're certain to get and can't avoid is a low signal-to-noise ratio. You only get banding (unwanted spatial artifacts) if you do it badly (without dither).
Re:Games Look Bad: HDR and Tone Mapping by balls187 on Monday October 23, 2017 @06:49PM (#15537576)
To express a ratio of 1000000:1, you need at least 20bits. I think that's all the article is saying, and that far more bits than the current contrast ratio that is supported--essentially show that we're far off from supporting actual contrast ratios.

I didn't interpret the articles premise that if you had 20 bits, you could 100% reproduce the light in a scene.

Re:Games Look Bad: HDR and Tone Mapping by robotresearcher on Monday October 23, 2017 @09:42PM (#15538570)
> To express a ratio of 1000000:1, you need at least 20bits.

You only need 1 bit if you declare an encoding scheme where 1 == 1 million. You need 20 bits to define 1 million DIFFERENT luminances. Their ratio is subject to an arbitrary scaling.

Re:Games Look Bad: HDR and Tone Mapping by chrisseaton on Monday October 23, 2017 @06:55PM (#15537600)
Sorry I still don't get it :)

> To express a ratio of 1000000:1, you need at least 20 bits.

You mean to express all the integer factors in the range 1000000:1, you need at least 20 bits. With 20 bits you can represent 1 times brighter, 2 times brighter ... 1000000 times brighter.

But there's nothing special about those coefficients. 20 bits does not allow you to represent 1.5 times brighter. That's still in the range 1000000:1 but 20 bits isn't enough to represent it.

If we're happy to skip 1.5 times brighter, why can't we skip all the even integer times brighter values, and use 19 bits?

Re:Games Look Bad: HDR and Tone Mapping by dragonwriter on Monday October 23, 2017 @07:02PM (#15537656)
> If we're happy to skip 1.5 times brighter, why can't we skip all the even integer times brighter values, and use 19 bits?

Things get wonky if you don't have a linear scale with a true zero; in such a scale the low end of your N:1 contrast ratio (in the smallest representation) has a value of 1, and the high end has a value of N.

Re:Games Look Bad: HDR and Tone Mapping by tripzilch on Saturday October 28, 2017 @06:46AM (#15574675)
Good thing in real life there's no such thing as truly zero photons, then (which is a detail the article actually shortly touches upon).

Also, if that type of "wonky" throws off your rendering pipeline, you're bound to get something else wrong.

Such as ever having a linear scale with a small number of bits in your pipeline. The linear scaled brightness stays afloat all the way through (cause floats have this handy feature of being transparently sorta-logarithmic in the way they use their bits, even 16-bit floats beat 20-bit ints for that purpose), only at the very end you apply the tonemap+gamma function(s), then dither, then truncate to fixed (8) bit integer.

Re:Games Look Bad: HDR and Tone Mapping by comex on Monday October 23, 2017 @11:53PM (#15539076)
Hmm… but the actual display’s representation of 0 cannot be darker than the minimum brightness value it supports. If 1 really is 1x the minimum, then 0 and 1 have to be displayed identically. But then your scale isn’t even linear, nor does it have a true zero. How does that help?

edit: And aren’t output color spaces already highly nonlinear due to gamma correction?

Re:Games Look Bad: HDR and Tone Mapping by colejohnson66 on Tuesday October 24, 2017 @01:59AM (#15539549)
0 is the lowest and x-1 is the highest for a ratio of 1:x. It’s 1 all the way to x; You just subtract one because computers start counting from 0
Re:Games Look Bad: HDR and Tone Mapping by comex on Tuesday October 24, 2017 @06:03PM (#15545616)
But in that case, skipping "even integer times brighter values" wouldn't exclude 0 - because 0 is 1x brighter, an odd integer.
Re:Games Look Bad: HDR and Tone Mapping by colejohnson66 on Tuesday October 24, 2017 @01:58AM (#15539543)
Is that the reason you can’t just chop off the two least significant bits when converting from 10-bit to 8-bit?
Re:Games Look Bad: HDR and Tone Mapping by stefs on Monday October 23, 2017 @06:11PM (#15537367)
what he meant, technically:

2^19 = 524,288

2^20 = 1,048,576

Re:Games Look Bad: HDR and Tone Mapping by oppositelock on Monday October 23, 2017 @05:00PM (#15536898)
Let's call that the writer's artistic license.
Re:Games Look Bad: HDR and Tone Mapping by ttoinou on Monday October 23, 2017 @05:08PM (#15536947)
Well it's kinda accepted in photography / computer vision to say this.

Another argument for this formula might come from Shannon information entropy but I'm not 100% sure