- Home /
Raw HDR Rendering
Hi all!
I am currently using Unity for simulation purposes. The images I am producing have specular reflections which are saturated in the output JPG images that are rendered. I was wondering if it is possible in Unity to render images to a raw output format which contains the actual intensity values at that pixel without saturation or clipping. Currently I am rendering like so:
RenderTexture rt = new RenderTexture(w, h, 24);
cam.targetTexture = rt;
cam.Render();
Texture2D img = new Texture2D(w, h);
RenderTexture.active = rt;
img.ReadPixels(new Rect(0, 0, w, h), 0, 0);
img.Apply();
Many thanks!
Answer by Namey5 · Jan 14, 2021 at 09:38 AM
You'll need to specify an HDR texture format for both the render texture and output texture if you want to store HDR values;
//Cache the current active RTs
RenderTexture prevCam = cam.targetTexture;
RenderTexture prevActive = RenderTexture.active;
//Use GetTemporary() and ReleaseTemporary() if the RT doesn't need to exist over multiple frames
//Use ARGBHalf format for both textures (16-bit floating point/channel)
RenderTexture rt = RenderTexture.GetTemporary (w, h, 24, RenderTextureFormat.ARGBHalf);
cam.targetTexture = rt;
cam.Render();
RenderTexture.active = rt;
//Also set equivalent HDR format here
Texture2D img = new Texture2D(w, h, TextureFormat.RGBAHalf);
img.ReadPixels(new Rect(0, 0, w, h), 0, 0);
img.Apply();
//Cleanup RTs
cam.targetTexture = prevCam;
RenderTexture.active = prevActive;
RenderTexture.ReleaseTemporary (rt);
If you are going to then encode to a format to save on disk, you'll need to use an HDR format (EXR is the main one supported by Unity with a function overload to handle encoding for you).
Your answer
![](https://koobas.hobune.stream/wayback/20220613023232im_/https://answers.unity.com/themes/thub/images/avi.jpg)