Search Unity

Blending between two virtual camera causes depth of field jitter

Discussion in 'Cinemachine' started by Bordeaux_Fox, Jan 30, 2020.

  1. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Hello,

    I have a problem with two cinemachine camera I blend in the timeline.
    Both cameras have a volume attached, with depth of field and vignette.
    When the fading from camera 1 to camera 2 is finished, I get for short moment a jitter with bokeh of the background. What causes this and how can I avoid it? That cleary distracts my movie.
    So it seems Unity is for one frame not taking both volumes into account?
     

    Attached Files:

    Last edited: Jan 30, 2020
  2. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Anyone? Can I expect that this get fixed?
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    We have not seen this before. Can you repro this effect in a small test project and send it to me?
     
  4. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    Confirming this issue - it happens for me during the first and last 2 frames of a transition - so if I have two virtual cameras in the same position with a different PP volume for each but the same DOF settings applied, there are 2 frames at the start and end of the transition where the DOF becomes noticeably blurrier and gives it a 'pop' effect.
     
    Bordeaux_Fox likes this.
  5. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Thanks, I assumed the bug is not only in my project. So either it is an interpolation error in the Cinemachine code or it is complete by design in the DoF shader in HDRP. I may wait what HDRP 7.2.0 brings this week before submitting a bug case but I'm not sure if it is just Cinemachine related. Would be interesting to try DoF blending with traditional Unity cameras.
     
    Last edited: Feb 3, 2020
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You can remove the jitter by adding a default Volume (Depth of Field) setting to your Main Camera.

    The reason, why this works:
    When blending from camera A to camera B, at the first frame of the blend, the weight of A = 1 - epsilon, and the weight of B = epsilon. So we ignore B, but this causes A to blend to a default dof, which has extremely large values, and so causes a noticeable flicker. We'll fix it in a future patch, but for now, you can use the above workaround.
     
    Gregoryl likes this.
  7. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    I already have a global volume with Depth of Field. So I need to add another global volume as a component to my main camera? With a higher priority? And then which settings should the Depth of Field have for this profile?
     
  8. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    See the image for the volume, I used on my main camera. It is different from the ones I had on my vcams. But, you could use the Depth of Field volume of one of your vcams.
     

    Attached Files:

  9. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    I'm afraid this does not solve the issue. Still get the jitter.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Can you repro this in a small project and send it? At this point it's getting hard for us to diagnose.
     
    gaborkb likes this.
  11. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    I can confirm this fix works - but only when I set the main camera DoF quality to 'Custom' - even if I don't actually change any exposed settings... But thanks!!
     
    Gregoryl likes this.
  12. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    If I make it like in his screenshot, it just overrides the DoF profiles I set up for my cutscene cameras, which is even more worse, because then I have no bokehs at all.
     
  13. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    Weird, for me it doesn't seem to matter what I put into the main camera settings, it doesn't affect the scene DoF at all (which is driven by the VCams). For reference, my setup is to have 2 VCams with individual volumes on both, that only contain a DoF effect, and then a single volume on the main camera with only a DoF effect - I haven't adjusted weights or priorities at all.
     
  14. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    The thing is, I already have a global volume, which contains more effects than DoF.
    But the global volume is not attached to the main camera.
    Even if I give the volume for the main camera a higher priority, it fixes nothing.

    The bug seems to come from different DoF quality settings. The DoF quality of the global scene volume can be tweaked in my game in a settings menu. But for cut scenes, I force the virtual cams to use high quality for DoF, otherwise I don't get good bokehs.
    Nevertheless, between the two virtual cams, which have both high quality DoF, the single frame fallback to the main global volume quality setting should not happen (in case the player decides to toggle the DoF quality to anything than high.)
    So the workaround is to have the same quality of the DoF the scene's global volume until a bug fix arrives. I made a little script that changes the global volumes DoF quality to high before a cutscene and after that switched back the player's setting.

    // Unity Bug: Fix Depth of field. Has to be the same quality as the cutscene cameras.

    if (Engine.globalVolumeProfile != null)
    {
    if (Engine.globalVolumeProfile.TryGet(out DepthOfField depthOfField))
    {
    depthOfField.quality.value = 2;
    }
    }

    // Start cutscene.

    Engine.cinematicActive = true;


    Despite the issue with DoF, I also noticed there is no smooth blending for the Lens Distortion effect. It simply turns off between cam 1 to cam 2 despite I have a blending curve of several seconds in the timeline. So this looks really bland.
     

    Attached Files:

    Last edited: Feb 10, 2020
    Aurecon_Unity likes this.
  15. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Your global scene volume is using Physical Camera, whereas your main camera volume is using Manual focus mode. Focus mode values are not lerpable (enums). I could reproduce a jitter with different focus mode settings. The jitter went away, when I switched to the same focus mode on my volumes.

    Moreover, as opposed to what I said earlier, you do not need to set a volume on your main camera. Instead you can change the Default Settings in HDRP using the HDRP Default Settings tab in Unity's Project Settings window (see here).
     
  16. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    I understand that the different focus mode is a problem. But again, the problem is, that Cinemachine takes the global volume into account while it should only lerp the Cinemachine volumes between two cameras in the timeline.

    So my question is, will you fix it, should I submit a bug request or do you have it already on the track?
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    @Bordeaux_Fox Some things are blendable, and some are not. It's not a Unity bug, it's just math. You need to take care with your volume profiles to keep them blendable, if you expect to have smooth blends between them. If they are not blendable (e.g. have settings for different modes), then you will need to cut instead of blend.
     
  18. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    It don't want the focus mode to be blended. I have for all my cut scene camera the same DoF mode, which is manual. The problem is just Cinemachine switches back to the global volume between camera blending in the timeline for one tiny frame. It should just blend the Cinemachine Volume settings in the timeline. I'm fully aware that some things cannot be blended, but I expect Cinemachine to take Cinemachine volumes into account when blending. So a Cinemachine volume should be a global override.

    Cinemachine Cam 1 Volume -> blend (ignore global scene volume when override is active) -> Cinemachine Cam 2 Volume

    and not:

    Cinemachine Cam 1 Volume -> blend -> short jitter global scene volume -> blend -> Cinemachine 2 Volume
     
    Last edited: Feb 11, 2020
  19. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    @Bordeaux_Fox No need to submit a bug report. We have already fixed it, and the fix should be available in the next release.
     
    Bordeaux_Fox likes this.
  20. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Ok, thank you, I will stay tuned for this update and inform you.
     
    gaborkb likes this.
  21. BlueSpirit

    BlueSpirit

    Joined:
    Jun 10, 2013
    Posts:
    33
    Any updates on this issue?
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    The fix is available in the latest CM 2.6.0.preview.2
     
  23. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Sadly, I cannot upgrade from 2.5.0. You changed something with the FreeLook Camera. When I upgrade, my player camera behaves different then before. It will adjust the vertical Axis automatically, making the player camera looking to the ground, really weird. With 2.5.0 it's not the case.
     
  24. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Could you send us a sample project where you experience the change?