Search Unity

Question Reflections with Custom Skybox

Discussion in 'General Graphics' started by maxmet, Dec 23, 2020.

  1. maxmet

    maxmet

    Joined:
    Oct 29, 2017
    Posts:
    7
    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!
     

    Attached Files:

    Last edited: Dec 23, 2020
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    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.
     
  3. maxmet

    maxmet

    Joined:
    Oct 29, 2017
    Posts:
    7
    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.
     

    Attached Files:

  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    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/<name>", if it doesn't have this prefix, Unity assumes it's not a skybox shader.
     
    Last edited: Dec 23, 2020
    maxmet likes this.
  5. maxmet

    maxmet

    Joined:
    Oct 29, 2017
    Posts:
    7
    Awesome, this worked.
    Thanks a lot for the help!