Issue Reassigning HDR Image to Skybox at Runtime

I’m trying to apply a different HDR image to the Skybox at runtime. My code sample has 2 options.

  • Option 1 loads a new image into the skybox’s texture.
  • Option 2 creates a new texture and uses GetPixels/SetPixels to transfer the image across to the skybox’s texture.

Both options run without error but do not display. Inspecting the texture shows that it hasn’t loaded the HDR properly.

The texture is set to Writeable in the Editor and obviously, I don’t try to run both options at the same time, I have just included them below for reference.

Texture2D texture = Resources.Load<Texture2D>("Textures/Skybox");
byte[] b = File.ReadAllBytes(hdrFilename);
      
// Option 1
texture.LoadImage(b);
texture.Apply();
      
// Option 2
Texture2D newTexture = new Texture2D(2, 2);
newTexture.LoadImage(b);
Color[] pix = newTexture.GetPixels();
texture.SetPixels(pix);
texture.Apply();

It appears that Texture2D does not support loading HDR at runtime? Has anyone managed to solve this?

Any help would be appreciated. :slight_smile:

@PMJenks
Did you get through?
Which rendering pipeline are you using?

Hi @BrandyStarbrite

No I have not managed to get this to work. I can see that the Editor has a nice HDR/EXR importer, but this is lacking at runtime.

After a LOT of reading and research, it doesn’t look like anyone else has managed to solve it either. I have resorted to importing PNG cubemaps at runtime as these are supported.

It would be great if they added support for this. Since it was originally raised a couple of years ago, HDR/EXR has grown in popularity.

1 Like

I’ve posted it as a Feature Request if you would like to vote for it,

https://forum.unity.com/threads/feature-request-import-hdr-exr-image-into-texture-at-runtime.1132597/

1 Like

Okay. Cool.

For anyone still looking for a solution, i found a plugin HDR/EXR runtime importer:

I have tested it and works really well.

I’ve noticed the RadianceHDRUnity gives Textures with wrong contrast, also latest version creates Texture RGBA32 which is not HDR texture :\