Reflections don't update when changing skybox at runtime

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.

Have you tried the “Realtime reflection probes” checkbox in Quality settings?

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)

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

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

OK, got it working ! You were both right, the answer is :

  • Check “realtime Reflection Probe” inside Quality settings
    and that code :
Texture texture = NativeGallery.LoadImageAtPath( path, maxSize ); // With the plugin NativeGallery available on the AssetStore
RenderSettings.skybox.SetTexture("_Tex", texture); // be careful, not "_MainTex" but just "_Tex" !
// with a public ReflectionProbe refProbe, that Type "Realtime", Refresh Mode "Via scripting", and Time Slicing "No time slicing"
refProbe.RenderProbe();

Thanks a lot guys !

3 Likes

Hey,
glad to know you nailed it :smile: I thought that we could update a baked reflection probe through code, but maybe not after all.
Cheers!

@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

3920494--334579--Capture.PNG

It is not working. Is it a correct way? I do not have any reflection probe in my scene.

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.

4 Likes

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.

2 Likes