Encode to EXR changes colors

I’ve been trying to create some emission textures with a tool I made. I need to be able to store emission that has HDR to take advantage of a bloom effect I’m using, so I discovered Unity’s builtin ImageConversion.EncodeToEXR. The problem is, when I then apply one of these saved textures to a material as its emission map, the colors are brighter, and in such a way that changing the emission color property of the material cannot return it to the correct colors.

.

Loading the saved texture back in to a Texture2D manually and then applying that to a material maintains the changes; so saving it again compounds the brightness, as below:

.

.

.

The original texture is on the right. I’ve simplified to gray so you can see the brightening effect.
The thing is that when I generate the texture into a Texture2D (formats RGBA32, RGBAFloat, RGBAHalf have all worked) and then put that in using Material.SetTexture("_EmissionMap, texture); I can achieve the colors I want. I would think there is some format or way to save my image that would maintain that. Is EXR just only meant for lightmaps, and foolish to use for anything else? Can Unity support higher bit-depth PNG instead? Or is there some special texture import setting I’m missing? Any insight you can provide would be appreciated.

.

Saving code:

byte[] bytes = ImageConversion.EncodeToEXR((Texture2D)texture, Texture2D.EXRFlags.CompressZIP);
//I've tried uncompressed as well.
System.IO.File.WriteAllBytes(path + ".exr", bytes);

.

Loading code:

Texture2D testTex = Resources.Load<Texture2D>(filename);
Color[] colors = testTex.GetPixels();
((Texture2D)texture).SetPixels(colors);
((Texture2D)texture).Apply();
//texture is an instance variable

.

Texture Import Settings
144996-exrsettings.png

I have same question in 2018.3.

No solution here (and I can’t seem to leave a comment), but I’m having the same problem in 2019.4 :frowning:

Okay - I’m having the same problem in 2019.4, found a solution, but it’s nasty!

Seems like it’s a gamma<>linear space issue? This won’t be particularly fast, and your textures will need to be marked for reading, so this might not work in runtime, but it sounds like you’re writing an editor tool so this’ll probably work

So… before you export the texture - loop over every pixel, convert them from gamma to linear, set and apply them back

// Loop over each pixel, convert them to linear space, apply them back
for (int y = 0; y < problem_texture.height; y++) {
    for (int x = 0; x < problem_texture.width; x++) {
        
        Color c = problem_texture.GetPixel(x, y);
        problem_texture.SetPixel(x,y,c.linear);
    }
}
problem_texture.Apply(true);
byte[] exrBytes = problem_texture.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);