LDR vs HDR

A story of graphical discovery

As much as I used to think otherwise, knowing the difference between Low Dynamic Range (LDR) vs High Dynamic Range (HDR) can make a HUGE difference in the world of game dev.  It can be hard to tell at first, especially dealing with just colors in an image.  Even when comparing an LDR and HDR image side by side, only a slight difference is noticeable.

I used to work in the electronics section of a store and the demo TVs would constantly display information about how HDR is new and cool and vibrant and… “What?” I thought, “It’s just color to me.”  Even while developing games, unless there was banding caused by post process bloom, I never noticed or cared about the difference between LDR and HDR. Especially since I tend to use Gamma colorspace).  Have a look at this image:

LDR vs HDR color toggle

I lied!  It’s actually a gif and not an image.  In the gif I toggled HDR on and off about every second.  It’s very difficult to tell the difference between LDR vs HDR in this case, which is why I never really cared and always had it off. But then I started working with animation…

Vertex animations baked to 2d textures, to be precise.  If you follow me on twitter you may know I am working on a game called Little People. I started around November 2019 and Unity’s Data Oriented Tech Stack didn’t support this type of animation at all at the time. So I had to come up with my own solution for animating the people, which I accomplished by baking the vertices for each animation frame into a texture, then cycling through the texture over time in a shader.

Original Baked Animation with LDR

It looks terrible, right?  The vertex movement is very jittery.  This looks fine at a very small scale, which is how I planned to use it at the time, but would definitely not be ideal for larger scale projects.  The biggest issue was that since the texture was exported as a png, if a pixel’s r, g, or b value was above or below 0 or 1, the value would get clamped and so would some vertices on the animation.  So I had to scale the mesh down, then bake it and set the x, y, and z positions to a channel of a texture.  That was still fine at the time, since the animation was at such a small scale that detail didn’t matter too much.  I released this animation baking tool, Mecanim2Texture with a shader to the public, even in the not-so-great state it was in.

Then, a few months ago, I started looking for a job at an indie studio and figured that I had best polish up my public repositories since recruiters might look at them.  Just as I was about done cleaning up Mecanim2Texture, I thought to myself “What if I fixed the scale issue?”  I remembered that a while back I accidentally caused a problem with overexposure in a game because I didn’t clamp some values, causing some faux emission.  I realized I needed to do the exact opposite for the textures and let the colors go beyond the 0-1 threshold.  This is where HDR comes in. 

HDR doesn’t clamp in the normal sense.  There’s still a min and a max, but they’re much farther beyond the range of 0-1, plus there’s some extra colors between, which was an extra bonus for me.  So I set to work adding HDR support to my tool.  It took about 20 minutes to add the capability.  10 of those minutes were spent looking through online forums, all suggesting to use external tools to export to HDR.  It turns out that Unity already had something built in.  Then 5 minutes were spent adding the conditions for exporting to HDR and doing some more cleanup.  The last 5 minutes I used to add support for HDR to my shader.  Finally, I baked and exported the animation as HDR!  The resulting texture looks a bit brighter than the LDR texture due to more in-between and out-of-range values.

LDR vs HDR Baked Texture Comparison

After that, I set up a little scene to compare the LDR animation against the HDR animation with my pre-existing shader.  The difference was noticeable the moment I dropped the HDR texture in the animation slot.

HDR vs LDR Baked Animation Comparison

It’s the exact same animation with the same frames and data, but the export method made all the difference.  That difference changed my mind on HDR immediately, and I hope it does for you too.  The usage of HDR is not applicable everywhere, but I highly recommend using it where necessary, like I have.

If you have any questions about this process or my Mecanim2Texture tool, feel free to reach out to me on Twitter. You can also follow the progress of my Little People game on Itch, or check out my personal website. Until then, I hope you found this guide and explanation helpful. Thanks!

You may also like...

2 Responses

  1. Alan says:

    Excellent job, could you upload or give us a link to download the Unity example project please

Leave a Reply

Your email address will not be published. Required fields are marked *