I’ve seen a few other people with this issue, but none have helped me solve it. I am trying to save a render texture as a png, and that works fine. I need an HDR supported format so bloom shows up. That’s working, but the exported image is much darker than what the texture is showing in Unity UI.
In this image, on the right is my game view (both in builds and in editor), and on the left is the exported png
The code I’m using to create the render texture via script is as follows:
public RenderTexture CreateNewRenderTexture(int width, int height)
{
RenderTexture newTex = new RenderTexture(width, height, RTDepth, rtFormat, RenderTextureReadWrite.sRGB);
newTex.enableRandomWrite = true;
newTex.Create();
return newTex;
}
The variables rtFormat and RTDepth were set in the inspector for experimentation. The format is DefaultHDR annd the depth is 24. In the past, without HDR format just using 24 as the depth works fine, but I need the bloom to show up as well.
My code to take the image is as follows:
RenderTexture.active = linkedCamera.targetTexture;
var tex = new Texture2D(linkedCamera.targetTexture.width, linkedCamera.targetTexture.height);
tex.ReadPixels(new Rect(0, 0, linkedCamera.targetTexture.width, linkedCamera.targetTexture.height), 0, 0);
tex.Apply();
string savePath = Path.Combine(saveLoad.imageOutputPath, "Shot_" + Utils.GetTimeString() + ".png");
File.WriteAllBytes(savePath, tex.EncodeToPNG());
That’s for still images, but I am also recording this texture to video using a video capture asset. It basically works the same way, but every X frames.
I would appreciate any and all help! Thanks so much ![]()
EDIT: I now understand that EncodeToPNG doesn’t work with HDR formats. I tried EncodeToEXR and that did work (opens file in Ps), but for my purposes PNG is preferred. There’s no way to convert the color space in a way that will allow the picture to show up in a PNG file? I don’t need the full depth for editing that EXR has, just a simple image in PNG format.
