Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Issue Reassigning HDR Image to Skybox at Runtime

Discussion in 'Formats & External Tools' started by PMJenks, Feb 12, 2021.

  1. PMJenks

    PMJenks

    Joined:
    Jan 20, 2020
    Posts:
    8
    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.

    Code (CSharp):
    1. Texture2D texture = Resources.Load<Texture2D>("Textures/Skybox");
    2. byte[] b = File.ReadAllBytes(hdrFilename);
    3.      
    4. // Option 1
    5. texture.LoadImage(b);
    6. texture.Apply();
    7.      
    8. // Option 2
    9. Texture2D newTexture = new Texture2D(2, 2);
    10. newTexture.LoadImage(b);
    11. Color[] pix = newTexture.GetPixels();
    12. texture.SetPixels(pix);
    13. texture.Apply();
    It appears that Texture2D does not support loading HDR at runtime? Has anyone managed to solve this?

    Any help would be appreciated. :)
     
  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    @PMJenks
    Did you get through?
    Which rendering pipeline are you using?
     
    Last edited: Jun 27, 2021
  3. PMJenks

    PMJenks

    Joined:
    Jan 20, 2020
    Posts:
    8
    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.
     
    BrandyStarbrite likes this.
  4. PMJenks

    PMJenks

    Joined:
    Jan 20, 2020
    Posts:
    8
    BrandyStarbrite likes this.
  5. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Okay. Cool.
     
  6. ManuelSalvadori

    ManuelSalvadori

    Joined:
    May 8, 2019
    Posts:
    7
  7. StenCG

    StenCG

    Joined:
    Mar 26, 2015
    Posts:
    66
    I've noticed the RadianceHDRUnity gives Textures with wrong contrast, also latest version creates Texture RGBA32 which is not HDR texture :\