HDR WTF ??

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8444
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: HDR WTF ??

Post by KlaxonCow »

Little stoned kiwi wrote:I'm watching Five Nights at Freddy's and it's not a good time.
Black, dark, night-time is the norm and looks like garbage on my old kit.

It makes me think this is the place for HDR. It also makes me think post-production efforts could be lazily farmed out to it.
Ah, you can still do "internal HDR", even without a HDR display.

I did this with my little OpenGL engine - I need to get back to converting that to my little Vulkan engine, as I started that but then had to get a new job and stuff that distracted me.

Renders to a floating-point texture. Pixel shader does HDR-to-SDR conversion.

And the reason to do that was because then I've got an "exposure" dial. So, you know, you go into a dark cave and your eyes adjust. Then you come out of the cave to sunlight - it's bright, overblown and bloom-y. Then your virtual eyes adjust and you can see again.

This is because I've seen too many YouTube playthroughs of survival games - Minecraft, Slenderman, Space Engineers, Colony Survival, etc. (and it sounds like "Five Nights at Freddy's" is the same) - where it turns night and then you literally can't see fuck all, if you forgot to bring torches with you.

So my engine rendered floating-point HDR and then tone mapped it to sRGB, but with some nice "exposure" / "contrast" dials available, so that the player's "virtual eyes" could adapt (granted, I'd not got that far - the levers were there, but to do it properly requires working out how bright / dark the screen is and adjusting. Counting pixels was not good performance, so I'd have to come up with something CPU-side or somehow calculate a rough average. I had planned on not having the red channel affect things - human eyesight doesn't adjust to red, which is why digital alarm clocks have red digits and astronomers look at their star charts and things with a red flashlight. So you can see things, without your eyes adjusting, retaining your "night vision").

And, yes, though I was doing it HDR-to-SDR because I only had a normal sRGB screen, the fact that it was calculated in HDR meant that it could easily be upgraded to do proper HDR with a HDR display later on. When I had such a thing to test that it actually works.

HDR screens let you actually see more of those calculations, but you can do the calculations anyway and map it to whatever screen you've got. It does make a difference - light sources don't clip at (255, 255, 255) white, basically, and even in SDR, with an "exposure" setting, it's useful.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
WiteWulf
Sheepie Whore
Sheepie Whore
Posts: 10125
Joined: Mon Aug 23, 2004 11:20 am 0
PSN: WiteWulf
Location: Loughborough(ish)

Re: HDR WTF ??

Post by WiteWulf »

You make an interesting point. A very similar thing IRL convinced me to always shoot with my DSLR in RAW. I took a pic from inside a cave looking out to a bright, sunny beach. The cave framed the scene, but was basically all black as it came out of the camera. Once I'd masked off the beach in the centre I increased the exposure and was absolutely blown away by the amount of detail the camera had captured inside the cave.

All that would have been lost with JPEG. Similar problem with HDR->SDR conversion, obviously, as it's a lossy process
:::G:::

PSN: WiteWulf
Switch: SW-3941-2878-7584
Steam: WITEWULF66
User avatar
Deckard
Sheepie Whore
Sheepie Whore
Posts: 10746
Joined: Fri Jun 18, 2004 11:27 pm 0
Location: Falmouth, Cornwall, UK

Re: HDR WTF ??

Post by Deckard »

I am far more impressed with good HDR than 4k over 1080p in movies / tv especially as my LG does total blacks...
Now with a new Mac Mini Pro so dont judge me !
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: HDR WTF ??

Post by zip accident »

WiteWulf wrote:You make an interesting point. A very similar thing IRL convinced me to always shoot with my DSLR in RAW. I took a pic from inside a cave looking out to a bright, sunny beach. The cave framed the scene, but was basically all black as it came out of the camera. Once I'd masked off the beach in the centre I increased the exposure and was absolutely blown away by the amount of detail the camera had captured inside the cave.

All that would have been lost with JPEG. Similar problem with HDR->SDR conversion, obviously, as it's a lossy process
JPEG is an abomination, and should never have been used or promoted.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4597
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: HDR WTF ??

Post by Little stoned kiwi »

I'm still not sold on it being a good thing. Pre-production, sure.
Manufacturers will be tempted to cut corners on their screens and have HDR work around their deficiencies.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8444
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: HDR WTF ??

Post by KlaxonCow »

WiteWulf wrote:You make an interesting point. A very similar thing IRL convinced me to always shoot with my DSLR in RAW. I took a pic from inside a cave looking out to a bright, sunny beach. The cave framed the scene, but was basically all black as it came out of the camera. Once I'd masked off the beach in the centre I increased the exposure and was absolutely blown away by the amount of detail the camera had captured inside the cave.
Basically, yeah, it's recreating that.

And, as I said, it wasn't, in my case, an effect or even really an attempt to be "realistic". It was, as I say, from seeing so many games where, the second it goes to "night" and you haven't brought a torch with you, the screen is basically black and you can't see fuck all. Which is stupid, and terrible gameplay.

I wanted to add a bit of "pupils adjusting to the light" simulation in there, just so that, at night or in a dark cave or whatever, you'd have "night vision" to actually see things, but when you wander out into the blazing Sun, you can also see things.

And you'd get the "walking out of a dark cave into the sunlight" where it's bloom-y but then clears up, as your virtual eyes adjust, for free - as my HDR-to-SDR tone mapping equations (which I found online) have an "exposure" setting to them, so "eye adjustment" is really just turning that dial up and down, over time, to match the image's overall brightness.

But, as Dio says, a lot of games are no doubt doing what I'm calling "internal HDR". That they render it all to a floating-point texture (that can hold really big and small values). Then you've got a "tone map" equation in your pixel shader that takes the floating-point and converts it to something the display can display.

This is useful, even when the target display isn't HDR, because you're basically avoiding clipping.

Like, bright Sun versus a street lamp (the Sun is so, so, so much brighter and the lighting equations ought to reflect that, that a street lamp turned on and off in the daylight ought not to make much of a difference to anything). Dark cave versus bloom-y daylight. Indoor versus outdoor, but still being able to see everything just fine, after a bit of "eye adjustment" - just like in real life.

There's a wide range of brightnesses in the real world, which 0-255 with RGB can't represent. So you work it all out in floating-point and then have a pixel shader do a floating-point to RGB8 thing for you at the final stage.

And I was doing this on a plain sRGB monitor, with no real view to thinking about HDR displays. Other than "if a 10-bit HDR display is attached then it can be mapped to 10-bits".

The way I think of it is that when you do audio, recording studios often record and edit at 96KHz or 192KHz. Even though they're going to release the final product at more than, at best, 48KHz.

You record and edit at 96KHz or 192KHz, not because the human ear could ever reasonably tell the difference, but because when you're editing the audio, you're going to lose precision around the edges.

Cut this, make it louder, apply an EQ, make it quieter, apply a reverb, copy it and shift it for phasing, make all of that louder.... every time you do a manipulation in the editing, you could be losing a little bit of precision. The x2 of 96KHz and x4 of 192KHz is basically accounting for this. It's a "margin of error".

As you edit 192KHz audio, tiny little losses of precision here and there won't amount to anything audible when you downscale it to 48KHz.

Same thing with Photoshop. You edit the high resolution photograph - as high rez as possible - because when you apply effects and stuff with Photoshop, there's going to be sub-pixel inaccuracies and things like that creeping in. But "work big" and then downscale it at the end. Then you don't have to worry because the tiny little losses are just not perceivable. A "sub-pixel" mistake at 100Megapixels is going to become a sub-sub-sub-pixel mistake, once you've sized it down to 1920x1080 or whatever.

"Work big" to get the calculations right, to retain precision, to avoid clipping. Then downscale it to an SDR monitor's range, or shrink the Photoshop picture to a smaller size to put it on your blog, or the recording studio outputs it at 44.1KHz 16-bit for "CD audio" on a plastic little disc.

And, in that view, HDR monitors are just devices capable of potentially displaying a bit more of that floating-point texture as calculated (but no way at the actual scale of floating-point, as that's got a massive range that no known technology could accurately represent). So I've currently got floating-point to 8-bit RGB for sRGB stuff. But if I had a 10-bit HDR monitor then I can "tone map" to 10-bits. The display can show a bit more of the range I've calculated.

But I - and as Dio rightly notes, many games - are going to be doing the calculation at floating-point level, regardless of what display - SDR / HDR - might be at the output end of this. If it's a HDR monitor, then it can show a little more of the detail that's in there. But if it can't, then it doesn't. You're not doing the HDR just to go "ooh, look, fancy effect". But to get all your "physically based lighting" stuff right and proper. And if a monitor can show a little more of that fine detail, that's nice. But that's not the aim.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
Vargol
Baa!
Baa!
Posts: 59
Joined: Wed Jun 05, 2019 7:54 pm 0

Re: HDR WTF ??

Post by Vargol »

zip accident wrote: JPEG is an abomination, and should never have been used or promoted.
Someone never did the internet over dial-up
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: HDR WTF ??

Post by zip accident »

Vargol wrote:
zip accident wrote: JPEG is an abomination, and should never have been used or promoted.
Someone never did the internet over dial-up
The slowest I used was ?28,000? bps, and even then PNG (during burn all GIFs month, when GIFs were still patented) was miles better than JPEG.

I remember, before I had home internet, receiving a JPEG of a corporate logo, which contained a circle, and when you blew it up to look at it closely, there were artifacts around the edges of the circle.

Unwanted artifacts are what JPEG does, for anything that needs precision it is absolutely awful.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: HDR WTF ??

Post by Dio »

zip accident wrote:
WiteWulf wrote:You make an interesting point. A very similar thing IRL convinced me to always shoot with my DSLR in RAW. I took a pic from inside a cave looking out to a bright, sunny beach. The cave framed the scene, but was basically all black as it came out of the camera. Once I'd masked off the beach in the centre I increased the exposure and was absolutely blown away by the amount of detail the camera had captured inside the cave.

All that would have been lost with JPEG. Similar problem with HDR->SDR conversion, obviously, as it's a lossy process
JPEG is an abomination, and should never have been used or promoted.
What's your alternative? Given that for 90% of use cases it's totally acceptable, and as noted above, bandwidth and storage space for pictures really was quite important in the 1990s.

I mean, even today, I wouldn't fancy the photos I've taken personally suddenly going from a hundred GB or so to 5+ TB...
User avatar
Vargol
Baa!
Baa!
Posts: 59
Joined: Wed Jun 05, 2019 7:54 pm 0

Re: HDR WTF ??

Post by Vargol »

zip accident wrote:
Vargol wrote:
zip accident wrote: JPEG is an abomination, and should never have been used or promoted.
Someone never did the internet over dial-up
The slowest I used was ?28,000? bps, and even then PNG (during burn all GIFs month, when GIFs were still patented) was miles better than JPEG.

I remember, before I had home internet, receiving a JPEG of a corporate logo, which contained a circle, and when you blew it up to look at it closely, there were artifacts around the edges of the circle.

Unwanted artifacts are what JPEG does, for anything that needs precision it is absolutely awful.
I'd been on the internet for a few years before PNG got anywhere big enough, hell they only start discussing creating in in 1995, was wasn't fully spec-ed til late 1996.
What do you think we used before it, giant TIFF or BMP what took 5 or 6 seconds to download when a jpeg would be down in 1.
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8444
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: HDR WTF ??

Post by KlaxonCow »

zip accident wrote:JPEG is an abomination, and should never have been used or promoted.
I feel this is blaming the abuse of the technology on the technology itself.

JPEG does what it says on the tin.

It's a lossy compression that loses the least perceptible parts - the "high frequency" fine detail - to produce a compressed image that is perceptibly similar. That's what it's supposed to do, and it does it well.

It's not the file format's fault if people, failing to understand the distinctions, are erroneously using JPEG for "line art" style logos, which is basically its worst case scenario.

If you're using it for photographs - remembering that the "P" in JPEG stands for "Photographic" - then that's what it's designed for and it does that job well (again, these days, WEBP does a better job, but at the time it was the best format for the job).

It's a bit like blaming your telephone device for the scam calls that come through on it. No, the telephone itself works just fine - it's arseholes abusing it that cause the problems.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: HDR WTF ??

Post by zip accident »

Dio wrote:
zip accident wrote:
WiteWulf wrote:You make an interesting point. A very similar thing IRL convinced me to always shoot with my DSLR in RAW. I took a pic from inside a cave looking out to a bright, sunny beach. The cave framed the scene, but was basically all black as it came out of the camera. Once I'd masked off the beach in the centre I increased the exposure and was absolutely blown away by the amount of detail the camera had captured inside the cave.

All that would have been lost with JPEG. Similar problem with HDR->SDR conversion, obviously, as it's a lossy process
JPEG is an abomination, and should never have been used or promoted.
What's your alternative? Given that for 90% of use cases it's totally acceptable, and as noted above, bandwidth and storage space for pictures really was quite important in the 1990s.

I mean, even today, I wouldn't fancy the photos I've taken personally suddenly going from a hundred GB or so to 5+ TB...
Now? something lossless. I'm aware of PNG and GIF, there may well be something better by now. I'm pretty sure the difference still isn't that big from bitmaps, I understood that compression got to about three to one, and then diminishing returns started to kick in, but I'm certainly not up to date.
Vargol wrote:I'd been on the internet for a few years before PNG got anywhere big enough, hell they only start discussing creating in in 1995, was wasn't fully spec-ed til late 1996.
What do you think we used before it, giant TIFF or BMP what took 5 or 6 seconds to download when a jpeg would be down in 1.
Seconds, you were lucky, "... and pay t' mill owner for permission to come to work."
KlaxonCow wrote:
zip accident wrote:JPEG is an abomination, and should never have been used or promoted.
I feel this is blaming the abuse of the technology on the technology itself.

JPEG does what it says on the tin.

It's a lossy compression that loses the least perceptible parts - the "high frequency" fine detail - to produce a compressed image that is perceptibly similar. That's what it's supposed to do, and it does it well.

It's not the file format's fault if people, failing to understand the distinctions, are erroneously using JPEG for "line art" style logos, which is basically its worst case scenario.

If you're using it for photographs - remembering that the "P" in JPEG stands for "Photographic" - then that's what it's designed for and it does that job well (again, these days, WEBP does a better job, but at the time it was the best format for the job).

It's a bit like blaming your telephone device for the scam calls that come through on it. No, the telephone itself works just fine - it's arseholes abusing it that cause the problems.
I feel that there may have been a case for it when GIFs were in patent trouble, but it should have been dropped when that patent ran out, which must be very nearly twenty years ago now, and it's still the main primary storage format for cameras, even though it's lossy.

The logo wasn't line art, it was a circle of one colour on a background of another colour, there were probably some words or letters, but I remember the circle. Or that's what it should have been, but it was a JPEG.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
ThetaReactor
Baaaaaa!
Baaaaaa!
Posts: 3543
Joined: Wed Jan 21, 2004 4:46 am 0
Location: Face-down in the shag rug.

Re: HDR WTF ??

Post by ThetaReactor »

GIFs were never a substitute for JPEG. They are better for line art and interface bits, yes, but they're also only lightly compressed and limited to 8-bit color, making them a very poor choice for photos.

If anything, GIF is the obsolete format. PNG is better at lossless images and HTML5 video has largely supplanted animated GIFs. SVG is probably the real killer, as it excels at icons and interface bits and even handles light animations.
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: HDR WTF ??

Post by zip accident »

ThetaReactor wrote:GIFs were never a substitute for JPEG. They are better for line art and interface bits, yes, but they're also only lightly compressed and limited to 8-bit color, making them a very poor choice for photos.

If anything, GIF is the obsolete format. PNG is better at lossless images and HTML5 video has largely supplanted animated GIFs. SVG is probably the real killer, as it excels at icons and interface bits and even handles light animations.
Yeah, looked a bit obsolete when I reviewed it on Wikipedia.

Mind you, Degas files on the ST were a really obsolete format.
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: HDR WTF ??

Post by gilesgoat »

zip accident wrote:
ThetaReactor wrote:GIFs were never a substitute for JPEG. They are better for line art and interface bits, yes, but they're also only lightly compressed and limited to 8-bit color, making them a very poor choice for photos.

If anything, GIF is the obsolete format. PNG is better at lossless images and HTML5 video has largely supplanted animated GIFs. SVG is probably the real killer, as it excels at icons and interface bits and even handles light animations.
Yeah, looked a bit obsolete when I reviewed it on Wikipedia.

Mind you, Degas files on the ST were a really obsolete format.
SVG IS ONE OF THE CRAPPEST FORMATS I EVER SEEN TO PARSE/TRY TO WORK WITH !

And/or ( probably that too ) is Inkscape that has an HORRENDOUS output of it ..
Giles the billy goat
"Baa"
Post Reply