Search Unity

Bug HDRP bug when OnCameraCut is called.

Discussion in 'Cinemachine' started by mons00n, Sep 22, 2022.

  1. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    In CinemachineVolumeSettings.cs the static method OnCameraCut() calls hdCam.Reset(), which in turn sets the variable cameraFrameCount to zero. This can be hugely problematic for HDRP skies as the DoUpdate method in SkyRender.cs does a comparison with the variable m_LastFrameUpdate which does NOT get reset to zero when OnCameraCut is called.
    Code (CSharp):
    1. // method on line 85 of SkyRenderer.cs
    2. internal bool DoUpdate(BuiltinSkyParameters parameters)
    3. {
    4.     if (m_LastFrameUpdate < parameters.frameIndex)
    5.     {
    6.         m_LastFrameUpdate = parameters.frameIndex;
    7.         return Update(parameters);
    8.     }
    9.  
    10.     return false;
    11. }
    What I have observed to happen is that the longer I am in a scene the larger m_LastFrameUpdate becomes and the larger that variable is when OnCameraCut is called, the skybox essentially locks up until the cameraFrameCount can catch up. I'm not entirely sure how this impacts HDRP skies but any external solution that builds off of this framework basically stops working for a period of time. In my case (using Expanse volumetric skies) the atmosphere stops updating, the sun stops moving, and the clouds stop animating.

    I'm not entirely sure what the best way to fix this is given that the m_LastFrameUpdate variable is private and most everything else that is reset is also private or internal. Maybe the SkyRenderer.cs code needs to be updated to check if the camera frame count gets reset to zero?

    For now I am going to comment out the hdCam.Reset() inside of CinemachineVolumeSettings - although I'm not sure of what other issues this may cause (everything seems fine).
     
    Last edited: Sep 22, 2022
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    This sounds like a problem with SkyRenderer.cs.

    Cinemachine needs to reset all temporal camera effects when a camera cut happens, otherwise things like motion blur will smear the cuts. If you don't use any such temporal effects then you can comment it out without problems.

    For other things that need to get reset when the camera cuts, they can also register an OnCameraCut callback and do their thing.
     
  3. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Yea I am thinking it is a bug with SkyRenderer and not necessarily Cinemachine - I'll make a repro case and send it in. And I don't use any temporal effects so happy to hear I should be in the clear for now. Thanks @Gregoryl !