Search Unity

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

Is it possible to modify update skybox ambient light values at runtime?

Discussion in 'Global Illumination' started by Arycama, Jul 23, 2015.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    182
    I'm procedurally generating objects which are baked into a skybox and assigned as the RenderSettings.skybox at runtime. I have the ambient source in the scene lighting settings set to "Skybox" and the intensity at 1, but it seems like updating the skybox at runtime doesn't cause the lighting to recalculate.

    Is there any way via scripts or similar to make the skybox lighting recalculate based on the current skybox? I found RenderSettings.ambientProbe in the documentation, but haven't found any information on how to use it.

    http://docs.unity3d.com/ScriptReference/RenderSettings-ambientProbe.html

    I read in another thread that "calculations needed to crunch down a skybox to a spherical harmonics representation are quite intensive, so they need an async job" by a Unity Dev :

    http://forum.unity3d.com/threads/skybox-as-an-ambient-source.334783/#post-2170260

    If there was a way to somehow do these calculations at runtime based on the current skybox, that would be awesome. Does anyone have any ideas how I might go about doing this, or if it's even possible at the current stage? It seems like it would be quite useful for people who want to change skyboxes at runtime but also have the lighting update.

    Thanks for any info!
     
    ThaiCat likes this.
  2. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    There are single line of code will do the skybox ambient update at runtime.
    Code (CSharp):
    1.     void Update () {
    2.         DynamicGI.UpdateEnvironment ();
    3.     }
    [Edit]
    This is an expensive function, running this every frame will kill your game performance badly.
    You should add your own condition when it needs to be update.
     
    Last edited: Dec 21, 2015
    desclik, Drafty343, RyanJVR and 2 others like this.