Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reflections don't update when changing skybox at runtime

Discussion in 'General Graphics' started by x2stone, May 2, 2018.

  1. x2stone

    x2stone

    Joined:
    Dec 17, 2014
    Posts:
    22
    Hi Unity Developers, dear Community Users,

    My question is simple : Why reflections don't update when changing the skybox's texture at runtime, unless environment reflections is set to "skybox" ? (I don't talk about Ambient Light or GI or something that of course needs baking or hard calculations that a mobile can't do)

    I'm trying to achieve a simple mobile app in which the user load a image (lat-long format, 2:1 ratio) from his photo gallery (or by taking a photo) and use it as new environment reflections.

    I tried to change the skybox's texture in Rendersettings (unless "Environment Reflections" is set to "skybox"), but it's not working. Some people say that the "Environment Reflections" has to be to "custom", but with that setting, you have to use cubemap, that takes 6-sided pictures, which I don't want to use (must be a simple lat-long picture). I tried GI.UpdateEnvironment, not working neither.

    In the editor, when I change the skybox texture, Unity does a little calculation (like "Reflection probe 1/3..."), unless I don't have any Reflection probe in my scene. So I assume that Unity have an "internal reflection probe" based on the skybox. Is there a way to force this "internal Reflection Probe" to update (on mobile) ?

    Thanks for your help/advices.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,948
    Have you tried the "Realtime reflection probes" checkbox in Quality settings?
     
  3. x2stone

    x2stone

    Joined:
    Dec 17, 2014
    Posts:
    22
    Thanks for your quick answer !
    No, I haven't modify this quality setting because, as I said, I have no reflection probe in my scene but perhaps it impact skybox internal update. I will try.
    I build for mobile platform, will I have some performance issue if I change this setting to realtime ? Because I need to update juste once (each time a new picture is loaded from the gallery)
     
  4. Yuvii

    Yuvii

    Joined:
    May 20, 2014
    Posts:
    55
    Hey,

    The "little calculation (like "Reflection probe 1/3...")" you see is Unity baking lightmap. even if there's nothing to bake, it will do this to check everything.

    Don't use a realtime reflection probe, it will uselessly use performances.
    Set a Baked reflection probe, and use C# to update it when you need.

    After a quick search on google i found this, didn't try it but it may be what you're looking for.

    Cheers
     
  5. x2stone

    x2stone

    Joined:
    Dec 17, 2014
    Posts:
    22
    Thanks a lot Yuvii, I just check your link, and I just see that I can use "null" as parameter to "update the probe's default texture" ! Sounds great, hope it will work. I will let you know if it works.

    Cheers
     
  6. x2stone

    x2stone

    Joined:
    Dec 17, 2014
    Posts:
    22
    OK, got it working ! You were both right, the answer is :
    - Check "realtime Reflection Probe" inside Quality settings
    and that code :
    Code (CSharp):
    1. Texture texture = NativeGallery.LoadImageAtPath( path, maxSize ); // With the plugin NativeGallery available on the AssetStore
    2. RenderSettings.skybox.SetTexture("_Tex", texture); // be careful, not "_MainTex" but just "_Tex" !
    3. // with a public ReflectionProbe refProbe, that Type "Realtime", Refresh Mode "Via scripting", and Time Slicing "No time slicing"
    4. refProbe.RenderProbe();
    Thanks a lot guys !
     
    Last edited: May 6, 2018
    Garrettec, guycalledfrank and Yuvii like this.
  7. Yuvii

    Yuvii

    Joined:
    May 20, 2014
    Posts:
    55
    Hey,
    glad to know you nailed it :D I thought that we could update a baked reflection probe through code, but maybe not after all.
    Cheers!
     
  8. UDN_30011711-3d42-4608-a55a-5bf3a3109e16

    UDN_30011711-3d42-4608-a55a-5bf3a3109e16

    Joined:
    Nov 23, 2016
    Posts:
    6
    @x2stone I am facing the same problem.

    Here is my code:
    RenderSettings.skybox = skyMaterial; //Here skyMaterial is a public material which have Skybox/Cubemap shader.
    DynamicGI.UpdateEnvironment();

    Now I am your code like this:
    RenderSettings.skybox = skyMaterial;
    refProbe.RenderProbe();

    I have declared a public ReflectionProbe refProbe;
    Added following on a game object and asiigned it to ReflectionProbe

    Capture.PNG

    It is not working. Is it a correct way? I do not have any reflection probe in my scene.
     
    Last edited: Nov 23, 2018
  9. Klaus-Eiperle

    Klaus-Eiperle

    Joined:
    Mar 10, 2012
    Posts:
    41
    I'm sure it's too late for you ... but maybe important for other programmers with the same problem.

    Go to Project Settings > Graphics > Always Containing Shaders and add these three shaders:
    - Hidden/CubeBlur
    - Hidden/CubeCopy
    - Hidden/CubeBlend

    I do not know if they are all always needed. The Reflection Map was calculated without these entries in the editor as desired, but not in the build. But now it works.

    It would be a great help, when the Editor would show warnings in that case.
     
  10. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    This is EXACTLY what fixed the issue. This is a gross oversight from Unity not logging a warning when reflection probes are used without these shaders being included. I had decided to clean up the build-included shaders a couple months ago because I am continuing work on a very old project and everything worked fine. At some point (after the update to Unity 2018.4.10f1) the reflection probes must've stopped rendering in the build without anyone noticing for a while.

    Including those three internal shaders in the "always included shaders" list fixed the reflection probes and everything's working fine now.
     
    EmilCoehl and bgebitekin like this.