I’m having a problem when trying to encode images with .EXR extension. The reason I’m trying to do .EXR is because I need to get images which have more than 24 bits bits of depth (more than 8 bits per channel) and was hoping this would solve my issue as the documentation says it supports 16 and 32 bit floats. I’ve tried doing it with .PNGs but the most I could get is 8 bit channels and some people say that PNGs don’t support more than 8-bits per channel. This brings me to my current problem:
I’m trying to save a screenshot of my scene as a .EXR file. I’ve looked at the Unity documentation on it, but I’m getting weird / wrong behavior. I’m not too sure what their m_Input variable is, but here is the code I replicated:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class SaveRenderTextureToEXR : MonoBehaviour
{
RenderTexture m_InputTexture = new RenderTexture(Screen.width, Screen.height, 32);
// Use this for initialization
void Start ()
{
SaveRenderTexture();
}
// Update is called once per frame
void Update () {
}
void SaveRenderTexture()
{
int width = m_InputTexture.width;
int height = m_InputTexture.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false);
// Read screen contents into the texture
Graphics.SetRenderTarget(m_InputTexture);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
// Encode texture into the EXR
byte[] bytes = tex.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
File.WriteAllBytes(Application.dataPath + "/SavedRenderTexture.exr", bytes);
}
}
This code didn’t really work for me. The output was a really tiny image and I couldn’t open it with anything (I tried InfranView and Photoshop).
I’m not too sure what to do and any help would be appreciated.