Reflections with Custom Skybox

Hello.

I have create a skybox shader/material. Up to now, I used it in a custom sphere object, but now I’ve tried setting it directly to the RenderSettings.skybox and it works fine. This shader depends on external variables that set the time of day (and thus color of the sky).

Unfortunately, the reflections don’t seem to actually work!
What seems to happen is that the material is applied, but in a “fixed” time of day. The skybox itself changes, but not the reflections.

Here are some screenshots to show what I mean. You can see the sphere and the skybox (on the first three), which both display the same. The reflections on the water (on the last two), always seem to display the sunset colors.

The RenderSettings do say this “the shader of this material does not support skybox rendering”, but I have no idea what that means - it works on the actual skybox.

I can provide the shader code, though it is quite messy.

Anyway, does anyone have any idea of how to solve this? Or a first step on diagnosing the problem.

Thanks!





Whenever you change the time in your script, you could call DynamicGI.UpdateEnvironment. Which will update the hidden global reflection probe, which is created from the current skybox.

1 Like

Thanks for the reply!

Unfortunately, it doesn’t change anything, as you can see from the screen shots. Perhaps I am using something incorrectly? I posted the code section where I’m updating the skybox.

6653158--760174--2020-12-23 15_02_54-.jpg
6653158--760177--2020-12-23 15_03_04.jpg
6653158--760180--2020-12-23 15_03_16-.png

Testing it out… I actually couldn’t get it to work either, but I hadn’t yet tested my time of day system in play mode. When the scene view is open, the reflection is correctly updated because lighting gets rebuilt.

As far as I can tell, there’s no way to force the skybox reflection to refresh. A work around is to create a Reflection Probe object, set it to Realtime and the culling mask to “Nothing” so it only renders the skybox. Then give it a ridiculously large Box Size, so it encapsulates all objects in the scene. Reference it on your component call reflectionProbe.RenderProbe() to force it to refresh. At which point, the skybox reflection will update whenever you need it to.

If you’re using other reflection probes, best to set the importance to 0, so it doesn’t interfere with them.

By the way, you can get rid of the warning by naming your shader “Skybox/”, if it doesn’t have this prefix, Unity assumes it’s not a skybox shader.

2 Likes

Awesome, this worked.
Thanks a lot for the help!