Search code examples
c#unity-game-enginehdr

Convert Texture2D to EXR (HDRI)


I am looking for a way to convert Texture2D directly to EXR format in byte array. I've done few research and this seems to be complicated than I thought.

Not really looking for a code since I don't have one. Just a suggestion on how to do this.


Solution

  • Unity 5.6 just got released and surprisingly, it has the API to perform this Texture2D to EXR conversion.

    To convert Texture2D to EXR (HDR)

    byte []exrBytes  = texture.EncodeToEXR();
    

    To convert Texture2D to EXR (HDR) Compressed

    byte[] exrBytes = texture.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);  
    

    More EXR encoding flags can be found here.