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:

I have a work around but not a solution.

The work around is to load a Cube Map PNG image instead of the HDR image. This isn’t ideal but at least gets it working.

There is a free web based HDRI to Cube Map conversion utility here.

@Unity, I’d love a solution or a bug fix please.