High Dynamic Range (HDR) Output changes the inputs to your scriptable render pass when it applies tone mapping and color space conversions. These changes can cause your scriptable render pass to produce incorrect results. This means that when you use HDRhigh dynamic range
See in Glossary Output and a scriptable render pass that happens in or after the AfterRenderingPostProcessing injection point, you need to account for the changes HDR Output makes. This also applies when you want to add overlays during or after post-processingA process that improves product visuals by applying filters and effects before the image appears on screen. You can use post-processing effects to simulate physical camera and film properties, for example Bloom and Depth of Field. More info post processing, postprocessing, postprocess
See in Glossary, such as UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary or output from other camerasA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary, because you need to work with the color gamut that results from HDR Output. To make a scriptable render pass work with the changes HDR Output makes, you must manually perform tone mapping and convert color space in a script.
However, if you add your scriptable render pass at or before the BeforeRenderingPostProcessing injection point, you don’t need to make any changes for compatibility with HDR Output. This is because Unity executes your scriptable render pass before it renders the HDR Output.
Note: You can avoid this problem when you use a camera stack to render camera output before Unity performs tone mapping. Unity then applies HDR Output processing to the last camera in the stack. To learn how to set up a camera stack, refer to Camera stacking.
To make a scriptable render pass pass work with the changes HDR Output makes to color space and dynamic range, use the SetupHDROutput
function to apply tone mapping and color space conversion to the material the scriptable render pass alters:
Open the C# script which contains the Scriptable Render Pass you wish to use with HDR Output.
Add a method with the name SetupHDROutput
to the Render Pass class.
The following script gives an example of how to use the SetupHDROutput
function:
class CustomFullScreenRenderPass : ScriptableRenderPass { // Leave your existing Render Pass code here static void SetupHDROutput(ref CameraData cameraData, Material material) { // This is where most HDR related code is added } }
Add an if
statement to check whether HDR Output is active and if the camera has post-processing enabled. If either condition is not met, disable the HDR Output shaderA program that runs on the GPU. More info
See in Glossary keywords to reduce resource usage.
static void SetupHDROutput(ref CameraData cameraData, Material material) { // If post processing is enabled, color grading has already applied tone mapping // As a result the input here will be in the display colorspace (Rec2020, P3, etc) and in nits if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { } else { // If HDR output is disabled, disable HDR output-related keywords // If post processing is disabled, the final pass will do the color conversion so there is // no need to account for HDR Output material.DisableKeyword(HDROutputUtils.ShaderKeywords.HDR_INPUT); } }
Create variables to retrieve and store the luminance information from the display as shown below.
if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { // Get luminance information from the display, these define the dynamic range of the display. float minNits = cameraData.hdrDisplayInformation.minToneMapLuminance; float maxNits = cameraData.hdrDisplayInformation.maxToneMapLuminance; float paperWhite = cameraData.hdrDisplayInformation.paperWhiteNits; } else { // If HDR output is disabled, disable HDR output-related keywords // If post processing is disabled, the final pass will do the color conversion so there is // no need to account for HDR Output material.DisableKeyword(HDROutputUtils.ShaderKeywords.HDR_INPUT); }
Retrieve the tonemappingThe process of remapping HDR values of an image into a range suitable to be displayed on screen. More info
See in Glossary component from the Volume Manager.
if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { var tonemapping = VolumeManager.instance.stack.GetComponent<Tonemapping>(); // Get luminance information from the display, these define the dynamic range of the display. float minNits = cameraData.hdrDisplayInformation.minToneMapLuminance; float maxNits = cameraData.hdrDisplayInformation.maxToneMapLuminance; float paperWhite = cameraData.hdrDisplayInformation.paperWhiteNits; }
Add another if
statement to check whether a tonemapping component is present. If a tonemapping component is found, this can override the luminance data from the display.
if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { var tonemapping = VolumeManager.instance.stack.GetComponent<Tonemapping>(); // Get luminance information from the display, these define the dynamic range of the display. float minNits = cameraData.hdrDisplayInformation.minToneMapLuminance; float maxNits = cameraData.hdrDisplayInformation.maxToneMapLuminance; float paperWhite = cameraData.hdrDisplayInformation.paperWhiteNits; if (tonemapping != null) { // Tone mapping post process can override the luminance retrieved from the display if (!tonemapping.detectPaperWhite.value) { paperWhite = tonemapping.paperWhite.value; } if (!tonemapping.detectBrightnessLimits.value) { minNits = tonemapping.minNits.value; maxNits = tonemapping.maxNits.value; } } }
Set the luminance properties of the material with the luminance data from the display and tonemapping.
if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { var tonemapping = VolumeManager.instance.stack.GetComponent<Tonemapping>(); // Get luminance information from the display, these define the dynamic range of the display. float minNits = cameraData.hdrDisplayInformation.minToneMapLuminance; float maxNits = cameraData.hdrDisplayInformation.maxToneMapLuminance; float paperWhite = cameraData.hdrDisplayInformation.paperWhiteNits; if (tonemapping != null) { // Tone mapping post process can override the luminance retrieved from the display if (!tonemapping.detectPaperWhite.value) { paperWhite = tonemapping.paperWhite.value; } if (!tonemapping.detectBrightnessLimits.value) { minNits = tonemapping.minNits.value; maxNits = tonemapping.maxNits.value; } } // Pass luminance data to the material, use these to interpret the range of values the // input will be in. material.SetFloat("_MinNits", minNits); material.SetFloat("_MaxNits", maxNits); material.SetFloat("_PaperWhite", paperWhite); }
Retrieve the color gamut of the current color space and pass it to the material.
// Pass luminance data to the material, use these to interpret the range of values the // input will be in. material.SetFloat("_MinNits", minNits); material.SetFloat("_MaxNits", maxNits); material.SetFloat("_PaperWhite", paperWhite); // Pass the color gamut data to the material (colorspace and transfer function). HDROutputUtils.GetColorSpaceForGamut(cameraData.hdrDisplayColorGamut, out int colorspaceValue); material.SetInteger("_HDRColorspace", colorspaceValue);
Enable the HDR Output shader keywords.
// Pass the color gamut data to the material (colorspace and transfer function). HDROutputUtils.GetColorSpaceForGamut(cameraData.hdrDisplayColorGamut, out int colorspaceValue); material.SetInteger("_HDRColorspace", colorspaceValue); // Enable HDR shader keywords material.EnableKeyword(HDROutputUtils.ShaderKeywords.HDR_INPUT);
Call the SetupHDROutput method in your Execute() function to ensure that HDR Output is accounted for whenever this Scriptable Render Pass is in use.
The following is the complete code from the example:
class CustomFullScreenRenderPass : ScriptableRenderPass { // Leave your existing Render Pass code here static void SetupHDROutput(ref CameraData cameraData, Material material) { // If post processing is enabled, color grading has already applied tone mapping // As a result the input here will be in the display colorspace (Rec2020, P3, etc) and in nits if (cameraData.isHDROutputActive && cameraData.postProcessEnabled) { var tonemapping = VolumeManager.instance.stack.GetComponent<Tonemapping>(); // Get luminance information from the display, these define the dynamic range of the display. float minNits = cameraData.hdrDisplayInformation.minToneMapLuminance; float maxNits = cameraData.hdrDisplayInformation.maxToneMapLuminance; float paperWhite = cameraData.hdrDisplayInformation.paperWhiteNits; if (tonemapping != null) { // Tone mapping post process can override the luminance retrieved from the display if (!tonemapping.detectPaperWhite.value) { paperWhite = tonemapping.paperWhite.value; } if (!tonemapping.detectBrightnessLimits.value) { minNits = tonemapping.minNits.value; maxNits = tonemapping.maxNits.value; } } // Pass luminance data to the material, use these to interpret the range of values the // input will be in. material.SetFloat("_MinNits", minNits); material.SetFloat("_MaxNits", maxNits); material.SetFloat("_PaperWhite", paperWhite); // Pass the color gamut data to the material (colorspace and transfer function). HDROutputUtils.GetColorSpaceForGamut(cameraData.hdrDisplayColorGamut, out int colorspaceValue); material.SetInteger("_HDRColorspace", colorspaceValue); // Enable HDR shader keywords material.EnableKeyword(HDROutputUtils.ShaderKeywords.HDR_INPUT); } else { // If HDR output is disabled, disable HDR output-related keywords // If post processing is disabled, the final pass will do the color conversion so there is // no need to account for HDR Output material.DisableKeyword(HDROutputUtils.ShaderKeywords.HDR_INPUT); } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.