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.