################
GI and Animation
################


Because GI is a view-dependent process in HOOPS Luminate, computing animations with GI can introduce some flickering artefacts (the GI solution is slightly different from frame to frame). Hopefully, HOOPS Luminate comes with several tools to help you in computing high quality animations with GI.

We distinguish between two animation cases: camera animation only and objects animation.

*******************************
Rendering GI with Moving Camera
*******************************

When only the camera is moving in the scene, the GI solution is the same for each frame. It's then safe to compute the GI solution once for the whole scene and then reuse it for each animation frame. This is accomplished by creating a GI cache in ``RED::GICM_WORLD`` mode through the ``RED::IWindow::FrameTracingGICache`` method.

.. include:: /tasks/ta_ca/ta_ca_rendering/tk_computing_world_gi_cache.rst

The GI cache can be saved on disk in a .red file for reusing it later:

.. include:: /tasks/ta_ca/ta_ca_rendering/tk_saving_loading_gi_cache.rst

Once the world GI cache is available, you need to set it back before rendering:

.. include:: /tasks/ta_ca/ta_ca_rendering/tk_setting_external_gi_cache.rst

********************************
Rendering GI with Moving Objects
********************************

When not only the camera, but also objects move in the scene, you can't compute a single GI cache any longer. You need to build a GI cache for every frame in the animation. This may introduce flickering in the GI signal as the estimated GI at the same scene location can vary a little bit from frame to frame. To overcome this, HOOPS Luminate features a way to interpolate the GI over several frames, making the estimated GI more stable. 

First, you need to compute all the needed GI caches for your animation (can be one GI cache per frame or simply the number of GI caches needed for the current frame) and save them to the disk. 

Then, you can re-use those GI caches to compute each frame of the animation.

.. include:: /tasks/ta_ca/ta_ca_rendering/tk_anim_interpolating_gi.rst

The engine uses the same number of past and future GI caches for the interpolation. Hence, when providing n GI caches to the engine, n is necessarily an odd number with the GI cache of the current frame being located at the n/2 index in the vector.

.. figure:: bk_re_sw3d_gi_anim_objects.jpg
    :align: center
    
    **The current frame is the one in the centre; by setting three GI caches (before, current and next), the GI is interpolated over three frames instead of just using the current one, reducing the GI flickering.**

However, this can introduce some artefacts as past or future moves may produce some GI leaks at the current frame.
