Search Unity

Question HDRP, Depth of Field, Volumes, and Sequences

Discussion in 'Cinemachine' started by akent99, Jun 7, 2022.

  1. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I am upgrading from the built in render pipeline to HDRP. I used to use the Depth of Field component on Main camera. It had things such as "visualize" (really handy!) and "focus on transform" (get depth of field right so target object is in focus).

    Now (HDRP) it appears you do Depth of Field using Volume profiles? Visualize is gone (pity), and because its a profile, you have to create a new profile file (not just a game object!) per Sequence as the distance for each depth of field may be a bit different (and if you share the profile, changing the depth of field in one Sequence could break other sequences).

    Questions:
    • Am I missing something about Cinemachine virtual cameras perhaps?
    • Is auto depth-of-field based on a target object really gone? How do have a virtual camera track inwards and keep updating the depth of field so the target stays in focus? Manually animating the depth properties of a volume?
    • Is there a way to have volume profiles stored in a game object in the Scene hierarchy? Sharing profile files on disk has bitten me multiple times (reuse a volume profile then accidentally modify it) - or should I just get into the habit of creating hundreds of volume profiles with HDRP? (If it was in a game object, I can never have to worry about modifying one game object and messing up another object in the Scene.)
    Thanks!

    Update: Okay, I just found the "Cinemachine Post Processing" extensions to Cinemachine virtual cameras. It talks about creating a volume profile and setting "Focus Tracking" to "Look At Target" (which I am using in the virtual camera). I have not got it working yet, but it looks like the right sort of thing. (Does post processing require me to "play" the scene to see all the effects? Maybe cinemachine virtual camera overrides don't work in preview mode?)
     
    Last edited: Jun 7, 2022
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Hi @marc_tanenbaum - sorry to bug you, but is there an official latest best practice on HDRP volumes and depth of field post processing for Cinemachine? So can stay focused on the virtual camera Look At target. Looking on YouTube I found a mix of solutions, but none of them work for me. Probably user error, but is there a 2022.1f1 "known working" video/tutorial you recommend? I can get depth of field in general working with volumes, but I have failed to get any post processing on a cinemachine virtual camera to kick in. (I have tried following like 5 tutorials I could find.) I noticed you created a really short video a year ago using Cinemachine Volume Settings component on the camera, but I cannot find such as script. So I assume I should be using Cinemachine Post Processing?

    I am on Unity 2022.1f1 with the default Cinematic Studio package.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Hi @akent99

    CinemachinePostProcessing should not be used in HDRP projects, nor should you be using the Post Processing package (uninstall it from the project if it is there - it just creates confusion).

    With HDRP, Post Processing is built natively into the volume system. So, you should be using the CinemachineVolumeSettings extension on your vcam, which can be found here:

    upload_2022-6-8_7-19-23.png

    CinemachineVolumeSettings components work analogously to CinemachinePostProcessing components: you assign a volume settings asset to the vcam, add PostProcessing overrides, and it blends in and out along with the vcam. Unlike the PostProcessing counterparts, you don't need any additional components on the main camera.

    upload_2022-6-8_7-20-11.png

    The CinemachineVolumeSettings work in and out of play mode, so you should see the results right away.

    Some tips:
    - Set the quality to high
    - The value Focus Distance setting doesn't matter - it will be dynamically overridden if you enable Focus Tracking
    - CM's Focus Tracking Offset is relative to the focus target's origin

    upload_2022-6-8_8-0-3.png
     
    Last edited: Jun 8, 2022
    gaborkb and marc_tanenbaum like this.
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Thanks Gregoryl!
    I upgraded a project, so it did have post processing still loaded. I removed that, but then for testing started a completely new 2022.1f1 3D HDRP template project, added Cinematic Studio, added a sphere and a cube, added Depth of Field post processing to two virtual cameras, and created a timeline to blend between them.

    How do you control the amount of blur? I notice:

    upload_2022-6-8_9-55-50.png

    but if I turn on Physical Camera on the main camera, most of the settings are locked down by the virtual cameras. I created a scene with 3 objects, set up two virtual cameras to focus on the cube and the sphere, then pan between them. I set the "look at" for the focus tracking.

    With sphere as focus
    upload_2022-6-8_9-59-16.png
    upload_2022-6-8_10-2-33.png

    Then focused on cube:
    upload_2022-6-8_10-0-18.png
    upload_2022-6-8_10-2-59.png

    Not much blur going on.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You won't see much blur without lowering the depth of field, which you do using the physical settings of the camera, as the info box says.

    You can't change these directly in the camera because as you say it's being driven by the vcam, but you can change it in the vcam. Open up the vcam's lens/physicalproperties section in the inspector. This section is present when the Camera is set to physical.
     
    akent99 likes this.
  6. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I did get a bit more blur adjusting the aperture on the virtual camera. One gotcha was I was changing the value on the cinemachine camera and seeing no effect so I thought it was doing nothing. But as soon as I moved the play head in the timeline, the value kicked in. Aperture of 0.7 (smallest I could set it).

    Sphere focus
    upload_2022-6-8_10-25-13.png

    Cube focus
    upload_2022-6-8_10-25-45.png

    Can the blur be increased beyond this?

    upload_2022-6-8_10-24-40.png
     
  7. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Even more confused now. I changed all the values up a lot and suddenly things went really blurry (yay!). I set all the values back, and its staying blurry... Huh? The two virtual cameras appear to have the same values.
    upload_2022-6-8_10-40-33.png

    Sphere focus
    upload_2022-6-8_10-41-5.png

    Cube focus
    upload_2022-6-8_10-41-28.png

    (I have to go do some other work - thanks for the feedback so far.)
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The 2 cameras are not the same; one is looking at the cube, the other at the sphere.
    You can increase the DoF effect by using a larger sensor size. Try switching the camera to 70mm Imax.
     
  9. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    I believe you can visualize HDRP's depth of field using the rendering debugger provided in HDRP.
    I don't have unity open right now but I believe it was in Window > Rendering > Debugger, or Analyze > Rendering debugger. Somewhere in there :D

    When you get there, choose rendering in the new debugger window, and there should be a dropdown option for "depth of field" or something similar. If you can't find it in rendering, go to volume, there's a lot of debug options but I'm sure it's there.

    more info here: Rendering Debugger | High Definition RP | 14.0.3 (unity3d.com)
     
    akent99 likes this.
  10. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Yes, that has helped a lot for more blur, thank you.

    If I am understanding, when I disable the tick box in the Main Camera for Physical Camera, it does not show it on the screen any more, but the underlying physical camera is still being used (that is, the virtual cameras are ignoring that the Physical Camera checkbox is turned off and using the current virtual camera regardless). I was thinking disabling it made it "go back to a default".

    Thank you! I found it - Window / Rendering / Analysis / Rendering Debugger / Volume / Post-Processing/Depth of Field / main camera. Easy! There are console errors, but it seems to work.
    Code (csharp):
    1. Saving Prefab to immutable folder is not allowed: Packages/com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Resources/DebugUIPersistentCanvas.prefab
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    3.  
    Something still feels "strange" (inconsistent - like why were the same virtual camera settings from a previous post looking different in the later post), but I will try to repeat and confirm with the debug panel. I restarted Unity in the middle of all that and now cannot repeat my last post (!). It is acting more sanely again. I am wondering if some computation got cached and the restart or debugger window flushed that cache or something.

    Lessons learnt for blurring:
    • Virtual camera / Physical properties / Aperture matters for controlling depth of field
    • Adding Cinemachine Volume Settings with a Look At Target works, but you may need to fiddle with "Focus Offset" when turning the blur level up
    • The main camera Physical Camera matters (even when disabled) - 70mm blurs more than 8mm, due to adjusting Sensor Size and Focal Length (if you only adjust 1 of the two settings, the position of the objects in the camera shot move, so you have to increase one and decrease the other)
     
    Gregoryl likes this.
  11. serdardesign

    serdardesign

    Joined:
    Sep 10, 2021
    Posts:
    1
    make it simpler please for us camera guys jesus christ
     
  12. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    One other observation - I assume this is just how real 70mm lenses work, but the further the target focus object is from the camera, then less impact 70mm has on depth of field blurring. I had to crank values to like a 200mm or more to get the background to blur when the focus target was further from the camera.

    A visualization of depth of field effect like the old system had would have been useful - it took me a while to realize the above. I thought depth of field had broken, when it was really just minimal blur because the target was further from the camera. As a non-camera professional, I just want a slider to control the focus area (you need a bit of depth as the target has depth, but I want the minimal depth that keeps the target object complete in focus. The new stuff might be more like the physical world, but is harder to use for used to be a pretty simple use case.)