[HDRP] How to access exposure value via script

Hi,
I need to access the exposure value.

I tried:

Exposure exposure;
if (volume.profile.TryGet<Exposure>(out exposure))
{
    float value = exposure.fixedExposure.value;
}

But this only works if the exposure is set to fixed. It will not change if the exposure mode is automatic for example.
I need to access the value if the exposure mode is automatic or any other mode.

I am using HDRP 14.0.8. Is there anything in this version or in a more recent version ?
Thanks

1 Like

The volume framework will interpolate the settings for the exposure, and if you work with fixed exposure the value that it returns is the one used for rendering.
But if you use automatic exposure, you need to hook up in the render pipeline (with a custom pass for example) and read the exposure value that is on the GPU.

Thank you for the answer.

Can you explain how to access exposure on the GPU for the sake of completeness?

Sorry for the late answer, I was keeping this discussion on my to-do list of things to look at when I had some down time, and it is happening now :slight_smile:
I did build a script that allows you to retrieve the current exposure value per camera, and put it in a repository where I plan to add any future HDRP tolling/helper requests.
Here it the repo that you can import as a git package in package manager.

Or if you only want the exposure readback script, it is here, you should be able to import that .cs file in your project.
You’ll also find a sample script that shows how to use it, it is a simple as calling GetExposureManager.GetCameraExposure(<your camera variable>) from your code.

To go more in depth of the working, the script is using reflection to call the internal function HDRenderPipeline.GetExposureTexture( HDCamera ) to get the 1x1 px RTHandle used to hold the camera exposure, and calls a simple compute shader to read back the value to a compute buffer that is then fetched on the CPU.

In my tests this method tends to have an heavy impact on the framerate, as it forces a GPU to CPU readback during the frame, so I’d suggest to avoid using it every frame.
I’ll look into other lighter solutions.