Search Unity

Ensuring Completion of DynamicGI.UpdateEnvironment for Sky Reflection.

Discussion in 'Global Illumination' started by ferretnt, Mar 6, 2019.

  1. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    We have a game on mobile which is not actually using GI other than skybox reflections, but contains many prefabs which are loaded. Each of these prefabs (which is really a sub-scene contains a different key light which we would like to use to update the Skybox and its reflections before rendering the scene.

    We then want to render a single frame of that prefab *with correct lighting from the skybox as updated by the new key sunlight* to a rendertexture.

    So, our process is currently.

    - Load Prefab (containing scene, new sun position)
    - DynamicGI.UpdateEnvironment()
    - yield return null
    - Camera.Render()

    This seems to work, but is DynamicGI.UpdateEnvironment() always guaranteed to execute (at least for the case of updating the sky, with no actual GI) in a single frame? The documentation says that it "Schedules an update of the environment texture", which doesn't really define a completion time, and there is no async/callback on completion.

    Also, is there anther way to achieve this without a coroutine and a frame delay?
     
  2. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    When you call update, the ambient probe is updated immediately, but all other updates are deferred to later stages/frames. Checking DynamicGI.isConverged should tell you when Enlighten has stabilized. Switching to synchronousMode briefly may also do the trick.
     
    ferretnt likes this.