Search Unity

[SOLVED ~ mostly] What is the best way to "Pull Focus" using Cinemachine?

Discussion in 'Cinemachine' started by Sun-Dog, Mar 20, 2019.

  1. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    First of all, I have found this thread:
    https://forum.unity.com/threads/depth-of-field-control-please-for-the-love-of-god.484012/

    But the behaviour I'm getting is not consistent. When I change the value on one virtual camera, it changes the values globally.

    • I need 3 different "lenses" with the appropriate DoF.
    • On one camera I need to "pull focus" as the character moves near a close-up camera and without "pulling focus", the character occasionally falls out of the range of focus.

    • I have one Cinemachine Brain and 3 virtual cameras.
    • I use the postprocessing stack v2.
    • I have one global post processing profile.
    • I have imported the CM PostProcessing V2 adapter package.
    • I have added the Cinemachine Post Processing extension to each camera.

    Problem 1:
    Setting the Depth of Field on each Virtual Camera GameObject sets the DoF values globally; so when I set VCam1, it overrides the values of VCam2 & 3. this just seems to be a local way of setting the global value.
    How do I set the "lens" on each individual VCam?

    Problem 2:
    I assume I can find a way to animate the DoF somehow, but currently the Camera track doesn't have an animate button...
    How can I "follow focus" or "pull focus" on a moving character without finding some sort of way to hand animate the DoF? Can I target a bone or parented empty?
     
  2. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
  3. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Now, this doesn't affect any of the other camera focus settings - those would have to be animated ... somehow. As the Cinemachine Post Processing script seems to access the Post Processing Profile - which is an ASSET, the properties on the VCam don't seem animatable from an animation track in timeline.

    Right now I'm limping along with the same "Lens" on all of the cameras as the checkbox sets only the focal distance.
     
    Last edited: Mar 22, 2019
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The way to have individual Post Processing effects for each vcam is to make a separate PP profile for each one, with the settings that you want to override the global profile with.

    Let's sat you have a global profile G, with a focus setting, color correction, and a vignette. Now you have vcam A, and you want a different focus setting but you want to keep the other effects. You need to create a new PP asset for vcam A, containing only the focus settings you want. When vcam A blends in, that effect will blend in too, overriding the global setting for that effect.

    It's true that because the PP settings are assets you can't animate their fields them timeline. CM has made a special case for focus distance, because it's such a commonly requested thing. Under the hood, it creates dynamic assets for the vcams that want to manipulate the focus distance.

    If you do want to animate other PP effects, one possible way is to create a global PP volume containing the destination settings, and use the timeline to animate its weight, effectively lerping it in. You can do similar things with multiple vcams, each with customized profiles. That works well, because the settings are tied to vcams and lerp in along with them.

    One note about the CM PP extension: the focus tracks target setting provides an "offset" field. When you have a LookAt target on your vcam, that field is the offset from the target's transform, i.e. 0 will focus exactly on the target, wherever it happens to be. When there is no LookAt target, that field is the offset from the vcam, so a setting of 10 would set the focus distance to 10.
     
  5. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    When I hear "Lerp", I think "Blend", but I suppose it can also "Cut" if the Lerp goes from 0 to 1 in one frame.

    Each VCam needs its own unique lens, in Unity just as in the real world.
    slice_stanley_kubrick_01.jpg

    I suppose creating a PP for each one wouldn't be too cumbersome or have too much overhead. I'll give it a try.

    What would be wonderful would be to have that lens data treated the same way as the "Focus Tracks Target" button. But that's feedback for the future.
     
  6. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    So, @Gregoryl ...

    Is this the correct architecture?

    MainCamera (the one with the Cinemachine Brain)
    • Post Processing Layer
    • Post Processing Volume (Is Global == true)
      • Targeting Global Profile

    VCam01
    • Cinemachine Post Processing (script)
      • Targeting Local VCam01 Profile

    VCam 02
    • Cinemachine Post Processing (script)
      • Targeting Local VCam02 Profile
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes, exactly.
     
  8. StigTerma

    StigTerma

    Joined:
    Jun 7, 2019
    Posts:
    10
    Hi Gregoryl

    Does this architecture still apply? I can get it working all fine and dandy, but when I want to blend between my profiles with Timemachine, I get wierd hickups. All effects blend fine, except for Depth of Field. Somewhere in the middle of my transition from profileA to profileB, the Depth of Field snaps and jumps from one to the other- no blend at all.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The solution is to put a DoF in the global profile on the main camera. This is because the math in DoF requires a default setting through which it can pass when blending between 2 other settings.
     
  10. StigTerma

    StigTerma

    Joined:
    Jun 7, 2019
    Posts:
    10
    I have that already, same problem.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    What versions on Unity/CM/PP?
     
  12. StigTerma

    StigTerma

    Joined:
    Jun 7, 2019
    Posts:
    10
    Unity: 2019.1.5f
    Cinemachine: 2.3.5
    Timeline: 1.0.0
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Can you put together a minimal project that shows this issue and post it here?
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Maybe it has to do with your specific settings. As an experiment, could you set your main camera's DoF settings to midway between the settings for vcam A and vcam B? Does the problem go away?
     
  15. StigTerma

    StigTerma

    Joined:
    Jun 7, 2019
    Posts:
    10
    dursteric likes this.
  16. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Why not use SIGNALS ?

    Issue : To change each camera shots Focus / aperture / focus length at run time.

    I use the Timelines new feature called " Signals "

    I create a signal in the timeline (its in the Marker drop down ) Each signal trigger an event on the main camera change the Depth of Field components Focus Dist. / Aperture / or Focal Length at any given time on the time line.

    Signals also have " REACTORS " which simply call my script which changes values within thew Depth Of Field
    • Focus Distance
    • Aperture
    • Focal Length

    My Script is placed on the Main Camera


    public class CameraFocus : MonoBehaviour
    {
    PostProcessVolume m_Volume;
    DepthOfField d_Depth;


    public void Start()
    {
    Debug.Log("Starts Here");
    d_Depth = ScriptableObject.CreateInstance<DepthOfField>();
    d_Depth.enabled.Override(true);

    m_Volume = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, d_Depth);

    }

    // Change the Focal Length
    public void SetFocus(float d)
    {

    d_Depth.focalLength.Override(d);

    Debug.Log("Hey it changed the camera focus");

    }
     
  17. julio_kolbapps

    julio_kolbapps

    Joined:
    Mar 2, 2021
    Posts:
    32
    Hello. SomeOne can helpme with this.
    How this work with Unity 2020+?
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    This is an old thread. It's not clear what your issue is. Can you start a new thread and describe the problem you are having?