Games for Windows and the DirectX SDK blog

Technical tips, tricks, and news about game development for Microsoft platforms including desktop, Xbox, and UWP


Project maintained by walbourn Hosted on GitHub Pages — Theme by mattgraham
Home | Posts by Tag | Posts by Month

HDR Lighting and Displays

github, hdr

Originally posted to Chuck Walbourn's Blog on MSDN,

High Dynamic Range (HDR) lighting has been used in games for a long time, popularized by titles like Valve’s Half-Life 2 using DirectX 9.0c. The rendering uses float-point render targets, allowing the lighting to exceed the normal 0 to 1 range. Then the final result is tone-mapped back into normal range for display. The result is much improved contrast, making it easier to see a mix of dark interiors with bright exteriors, more realistic outdoor lighting, and a host of special effects.

Recent advances in display technology are adding the ability to render a wider range of luminance directly on the display, enabling a wider gamut of colors and better handling of HDR images and scenes. The 4k Ultra High Definition (4K UHD) standard includes the HDR10 Media Profile supported by game consoles like the Xbox One S and Xbox One X, as well as by Windows PCs running the Windows 10 Creators Update. A range of HDR10 capable TVs and monitors are becoming available.

DeviceResources

The DeviceResources abstraction (DX11 and DX12) used in directx-vs-templates now supports an options flag for HDR10 display output. To enable this support, you must build the code using the Windows 10 Creators Update SDK (15063) which also implies that you are using VS 2017–the Windows 10 SDK (15063) doesn’t officially support use with VS 2015. The code will run on older versions of Windows, but you can only get HDR10 output if running on a PC with the Windows 10 Creators Update as well as the required video card, driver, and display combination.

Note the latest DeviceResources will build with VS 2015 and/or the Windows 10 Anniversary Update SDK (14393), but won’t be able to detect HDR10 display output.

DirectX Tool Kit

In order to render an HDR10 swapchain on PC, UWP, and Xbox One, a postprocessing step is typically required to rotate the color space appropriately. To simplify this, I’ve added a ToneMapEffect (along with other post-processing support) to DirectX Tool Kit (DX11 and DX12). The ToneMapEffect class supports preparing the HDR10 swapchain (rotating from Rec.709 to Rec.2020 color primaries, and applying the ST.2084 curve), as well as traditional tone-mapping for supporting classic Standard Dynamic Range (SDR) displays.

Details on how to use these classes are on the wiki (DX11 and DX12) and in the tutorials (DX11 and DX12).

I’ve also added HDR10 display support and tone-mapped SDR display support to the DirectX Tool Kit Model Viewer (DX11 and DX12).

Samples

The official HDR sample is on DirectX-Graphics-Samples. See also the SimpleHDR sample in the Xbox-ATG-Samples GitHub repository–there are DirectX 11 and DirectX 12 versions for UWP, Win32 PC, and Xbox One XDK.

DirectXTex

Note that last year I added support for the Radiance RGBE (.hdr) file format as a source for HDR textures to DirectXTex. The texconv and texassemble tools were updated to support .hdr at this time. I also added a -tonemap switch (using a Reinhard local operator) to the command-line tools to support conversions of HDR textures to SDR range for debugging and diagnostics.

In addition to .hdr file format support, I added instructions/support for opting in to support OpenEXR (.exr) as well. See Adding OpenEXR for more information. Thanks to some community efforts, this is now easier to do by obtaining the required OpenEXR and ZLib libraries from NuGet.

This support is also include in the latest DirectX SDK Sample Content Exporter.

Update: The ‘official’ header signature for the .hdr file format is the string #?RADIANCE. This is recognized by all the known readers, but it turns out a few codebases also make use of an alternative #?RGBE signature. While not official, it’s common enough that I’ve updated DirectXTex in the February 2018 release to accept either version. Note that it still writes files with #?RADIANCE as many readers (including the deprecated D3DX9 library) don’t support the alternative signature.

Note: There are some potential application compatibility issues if you use proprietary solutions such as the “NVAPI” from NVidia on newer versions of Windows 10 to enable HDR10 output. It is recommended you only make use of the proprietary APIs on systems that lack support for IDXGIOutput6.