Search Unity

Keyframing post process FX values with Timeline

Discussion in 'Cinemachine' started by chuckgriff, Mar 5, 2018.

  1. chuckgriff

    chuckgriff

    Joined:
    Mar 4, 2015
    Posts:
    4
    Hi all,

    Is there a way to use an Animation Track (or any track) in Timeline to keyframe the individual values of a specific post process FX, such as the Depth of Field effect's Focus Distance or Aperture?

    Although there are threads and videos about this area they seem to all be discussing the deprecated scripts, before Cinemachine Post Processing became an Extension. It's a little confusing.

    Adam Myhill mentions in a comment on this video (
    ) that it is possible to keyframe everything, rather than blending entire cameras together to achieve the same result. Can someone explain how?

    Thanks very much.
     
    AntonioModer likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    You can use timeline to keyframe settings on GameObject. However, the PostProcessing Profile is an asset - meant to be shared by multiple game objects. Think of them as static settings. You can't animate those, but you can blend between them.

    That said, Cinemachine does provide a special "Focus Tracks Target" option that allows you to set the focus distance for any camera independently of the asset, but this is a special case. Look for it in the CinemachinePostProcessing extension.

    I think Adam's comment referred to the fact that you can use timeline to animate any Cinemachine setting that isn't an asset.
     
  3. chuckgriff

    chuckgriff

    Joined:
    Mar 4, 2015
    Posts:
    4
    Ah, OK. I understand. Thanks for the reply!
     
  4. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Yes and you can also use the PPS volumes as a way to drive values, blending between different volumes is effectively a set of keyframes for as many values as you want. You're not directly keyframing, but you're blending between different volumes of desired settings.
     
  5. oumur

    oumur

    Joined:
    Sep 12, 2013
    Posts:
    11
    why has this to be so hacky? I see no reason not to allow to animate this kind of stuff. Especially for Cutscenes...
     
    8esBabys, Mr-Jun, Flickone and 13 others like this.
  6. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    I really agree with oumur.
    The post process has never been static on any content...
     
    8esBabys, Flickone, CloudyVR and 3 others like this.
  7. Kashlavor

    Kashlavor

    Joined:
    Jan 10, 2014
    Posts:
    2
    I think it would be convenient to be able to use Timeline to control post-processing, maybe a custom track or something.
     
    Flickone, fullerfusion and kkrg001 like this.
  8. sergiobd

    sergiobd

    Joined:
    May 14, 2014
    Posts:
    37
    I really wonder what is the reason for this. Animating Post-processing effects is useful in many situations. How to request this as a feature?
     
  9. thomasphifer

    thomasphifer

    Joined:
    Mar 26, 2016
    Posts:
    13
    My natural inclination was to start animating the post processing values as I would any other value but I quickly saw that this was not possible. While it would be nice to be able to directly animate these values I am willing to learn how to do this using multiple volumes. I just need a better picture in my head to get started. So are you saying we could duplicate our current post-processing volume, create a new profile, change the values we want, make it Not Global and then have the physical volume "box" slide into place via animation?
     
    Last edited: Aug 17, 2020
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    You start with a global volume containing the effects you want. To animate a specific value within an effect, create another global volume with only that effect in it, with a new value for the effect. This will override the value in your default profile. The weight of that override volume dictates how much it will blend with the other active volumes. You can animate the weight in Timeline.

    This doc might help give you an overview of what's going on:
    https://docs.unity3d.com/Packages/c.../manual/Quick-start.html#post-process-volumes

    If you're using Cinemachine, you can attach PostProcessing effects to virtual cameras, and they will blend in and out along with the vcams. Under the hood, CM is creating dynamic global profiles containing the override effects, and animating their weights.
     
  11. thomasphifer

    thomasphifer

    Joined:
    Mar 26, 2016
    Posts:
    13
    Ah bingo! Thank you as always Sir Gregoryl!
     
    headblockhead and Gregoryl like this.
  12. dsketchbook

    dsketchbook

    Joined:
    Jun 3, 2017
    Posts:
    4
    Compared to other software the whole setup of Unity and their post-processing and volumes is so annoying! Why does it have to be so hard to animate a DOF in this software! I don't personally like the idea of blending between volumes in this instance. Plus all cameras in a scene may have different DOF which means you can't really animate a focal shift cleanly with an override or can you?

    If you are using a timeline for camera animation, why can't it just see all the keyable properties for the volume overrides even if it is its own asset?
    As if you are using DOF and in manual mode, I personally want direct animation control of it. As if someone picks up my file they can clearly see what's been affected and animated and not have to go through every volume in a scene to find out what one had X setting... Seem very un artist-friendly and slow to get results.
     
  13. Philip_Zhang

    Philip_Zhang

    Joined:
    Feb 15, 2017
    Posts:
    25
    Currently, you can write a script to set your PostProcessVolume's values at runtime, then you keyframe the values on your script.

    gameObject.GetComponent<PostProcessVolume>().profile.TryGetSettings(out yourPostProcessEffectSettings);
    yourPostProcessEffectSettings.yourParameter.value = newValue;


    Note that .profile will instantiate a new cloned profile like mesh and sharedMesh, but since it's in a cutscene so you probably want to use this instead of .sharedProfile to not messing around with your asset.
     
    Resonantmango likes this.
  14. Kychris

    Kychris

    Joined:
    Apr 21, 2017
    Posts:
    2
    Yeah the design decision is really weird, maybe there is a reasonable explanation, Philip's method seems to be the way
     
  15. Sir-Allsen

    Sir-Allsen

    Joined:
    May 22, 2016
    Posts:
    4
    I really wish they would let us change the values inside an animation or timeline. I understand they are shared, but sometimes we just want to apply an effect for a brief period of time and have it fade in and fade out.
     
    CloudyVR likes this.
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    The easiest way to do this is to make a global volume with the effect and animate its weight to blend it in and out.
     
  17. dsketchbook

    dsketchbook

    Joined:
    Jun 3, 2017
    Posts:
    4
    Would be great if it was more artist intuitive than just constantly applying volumes to everything to band aid the approach. It really would be great if you could do it inside the object you want x to happen. All these extra things you need to keep adding makes unity very messy. Why is it even called a volume? surely you want it call it something that is almost universal in the naming.

    I do like Unity but I personally get frustrated that things are all over the place and in all different menus and not at all logical at the best of times. Admittedly I am coming to this from many years VFX and having learned multiple different software's and pipelines over the years. Maybe this is normal in game engine software.
     
    fullerfusion and takuyacebok like this.
  18. jlink

    jlink

    Joined:
    Jan 8, 2017
    Posts:
    11
    @Gregoryl using volumes to animate post effects is hacky. The method you describe works if you want to animate a single group of effects linearly, but if you want to animate individual effects more granularly then the volume setup balloons quickly. There are a lot of screen effects out there that work with Unity's post processing system and there isn't a great solution for animating them.
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    Agreed, it's not the most convenient solution, but while asset properties remain not directly animatable in Unity, we're kind of stuck with these awkward workarounds.

    One thought: maybe it's possible to make a helper script that can expose specific PP properties for animation, and under the hood create and manage dynamic profiles and manipulate their weights. That's what Cinemachine is doing for focus distance. Maybe this approach can be generalized. Might make a good asset-store offering :)
     
  20. zackchong

    zackchong

    Joined:
    Mar 28, 2017
    Posts:
    6
    @Gregoryl Hi Gregory, I have been doing the blending two volumes methods, but I encountered massive lag and jittering during the blending. I have tested it in different computers, even with a gtx 1080Ti. The lag is all over the place while blending the two volumes. Is there any workaround for that? Thank you.

    ps: I used a frame debugger and found out that there is a CommandBuffer VolumeBlending happening, and then there are two 4096x4096 luts under the commandBuffer. I assume it is causing the lag due to creating large resolution luts every frame?
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    I think that this question is better asked on the graphics forum. They will know more abut what's going on in there and how to optimize.
     
    Last edited: Jun 4, 2022
    zackchong likes this.
  22. Zylinski

    Zylinski

    Joined:
    Dec 17, 2012
    Posts:
    2
    I do this in a script to animate post processing. I create a Volume and VolumeProfile on the fly and animate the properties of them directly. This results in not needing a VolumeProfile asset.
    Code (CSharp):
    1. void Start()
    2. {
    3.         m_volume = gameObject.AddComponent<Volume>();
    4.         m_volume.isGlobal = true;
    5.         m_volume.priority = 10;
    6.         var p = ScriptableObject.CreateInstance<VolumeProfile>();
    7.         m_lensDistortion = p.Add<LensDistortion>();
    8.         m_vignette = p.Add<Vignette>();
    9.         m_chromaticAberration = p.Add<ChromaticAberration>();
    10.         m_volume.profile = p;
    11. }
    12.  
    13. void Update()
    14. {
    15.     if (m_lensDistortion)
    16.     {
    17.         m_lensDistortion.active = LensDistortion.Enabled;
    18.         m_lensDistortion.intensity.Override(LensDistortion.Intensity.Evaluate(ts));
    19.         m_lensDistortion.xMultiplier.Override(LensDistortion.XMultiplier.Evaluate(ts));
    20.         m_lensDistortion.yMultiplier.Override(LensDistortion.YMultiplier.Evaluate(ts));
    21.         m_lensDistortion.scale.Override(LensDistortion.Scale.Evaluate(ts));
    22.     }
    23.  
    24.     if (m_vignette)
    25.     {
    26.         m_vignette.active = Vignette.Enabled;
    27.         m_vignette.color.Override(Vignette.Color.Evaluate(ts));
    28.         m_vignette.center.Override(new Vector2(Vignette.CenterX.Evaluate(ts), Vignette.CenterY.Evaluate(ts)));
    29.         m_vignette.intensity.Override(Vignette.Intensity.Evaluate(ts));
    30.         m_vignette.smoothness.Override(Vignette.Smoothness.Evaluate(ts));
    31.     }
    32.  
    33.     if (m_chromaticAberration)
    34.     {
    35.         m_chromaticAberration.active = ChromaticAberration.Enabled;
    36.         m_chromaticAberration.intensity.Override(ChromaticAberration.Intensity.Evaluate(ts));
    37.     }
    38. }
    39.  
    Where the LensDistortion, Vignette and ChromaticAberration look something like this:

    Code (CSharp):
    1. [Serializable]
    2. public class LensDistortionParams
    3. {
    4.     public bool Enabled = false;
    5.     public AnimationCurve Intensity = new AnimationCurve();
    6.     public AnimationCurve XMultiplier = new AnimationCurve();
    7.     public AnimationCurve YMultiplier = new AnimationCurve();
    8.     public AnimationCurve Scale = new AnimationCurve();
    9. }
    10.  
    11. [Serializable]
    12. public class VignetteParams
    13. {
    14.     public bool Enabled = false;
    15.     public Gradient Color = new Gradient();
    16.     public AnimationCurve CenterX = AnimationCurve.Constant(0, 1, 0.5f);
    17.     public AnimationCurve CenterY = AnimationCurve.Constant(0, 1, 0.5f);
    18.     public AnimationCurve Intensity = AnimationCurve.Constant(0, 1, 1.0f);
    19.     public AnimationCurve Smoothness = AnimationCurve.Constant(0, 1, 0.0f);
    20. }
    21.  
    22. [Serializable]
    23. public class ChromaticAberrationParams
    24. {
    25.     public bool Enabled = false;
    26.     public AnimationCurve Intensity = AnimationCurve.Constant(0, 1, 0.0f);
    27. }
    28.  
     
    Last edited: Sep 6, 2022
    ssojyeti2, Yuchen_Chang and Gregoryl like this.
  23. A_Random_Stranger_Online_

    A_Random_Stranger_Online_

    Joined:
    Jul 10, 2023
    Posts:
    4
    people could use this in a lot of scenarios. in my case i want to make the vignette animation intensify whenever the player is holding down the aiming button
     
  24. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    476
    Would be good if this design flaw could be addressed. Pretty sure you could easily animate values using the old, pre volume post processing system.
     
    Klauensprung likes this.