You need also to have a CinemachinePostFX behaviour on the Unity camera. In addition, the PostFX on the vcam with the follow focus needs a PostProcessing profile that includes depth of field.
@Gregoryl I had that - apparently my F-stop wasn’t low enough to produce the desired effect. Thanks!
I’m struggling to grasp this. Not sure why it’s so over complicated, couldnt the PPSv2 simply have a focus on target and then on the camera (virtual or not) itself have a focus value that you could change per camera? Do I really need to use Timeline to animate my focus values? What if I’m just transitioning between cameras and all is kind of procedural? I don’t get it.
The ppv2 profile has a focus depth setting, and the PostProcessing CM extension has a focus follows target setting, which dynamically updates the focus depth. That should give you what you’re looking for.
Yes that is true, but that means I need to have a target and honestly I don’t want one. I want a free camera (3dsmax lingo). I’ve managed to work around this by using the camera transform as a follow target but I’m pretty sure that’s not the intended way and will mostly screw something up along the way.
If you don’t want a target that’s fine. In that case focus follows target makes no sense, and you can instead just give each vcam its own fixed focus distance in its pp profile. If you want this to animate, you can blend between vcams with different values.
I’m trying to animate my DOF like the OP. (I tried PostProcessingV2 and it seems to be broken on import, and it also seems to break another script I need for my scene.)
But that don’t work. Of course I don’t know much about scripting soooo, that’s probably it.
Why complicating such a simple concept as free camera with animated DOF though aperture slider? I don’t want to set a target, I don’t want to blend two cameras. I just want to animate Post Processing sliders and switches. Is it possible in Post Processing v2?
The problem here is that post-processing profiles are assets, and the sliders manipulate shared values in the assets, and not fields on game objects. That’s why you can’t animate them.
Because focus pulling is such a common need, Cinemachine has added a special case for it in the CinemachinePostProcessing extension. You can animate the “Focus follows target” offset found there. But it is a special case.
@redemprez you can make an empty object be your focus target, put it under the vcam in your hierarchy, set the camera to look at it and only keyframe it on the Z axis. Voila, custom focus handle.
Hi, Adam, thanks for the hint, indeed. I can do it. I also found that using third party Beautify DOF I can animate it in timeline, I will check which solution works better for me.
There is a way to do it through code. You have to create a post processing profile (it’ll create itself as a file in your asset directory). Then you attach it to your main camera, and then you can override it’s settings in C# code.
It’s probably not advised though. For my project in particular I just needed depth of field resistance, bloom and to create color grading profiles, very simple stuff. For most games, though, you’ll want it to be less simplified for more control.
I still am struggling to find a way to do this with Post Processing stack v2. Am I missing something? I dont even see that component that lets you use cinemachines target position?
im currently following along with this but im just shocked the amount of code im writing to just set a post processing setting…
https://docs.unity3d.com/Packages/com.unity.postprocessing@2.0/manual/Manipulating-the-Stack.html
I don’t know why you’re writing code. Just add a PostPorcessLayer component to your Camera in the editor.
Then create a default global volume for the scene by adding a PostProcessVolume to an empty GameObject and setting a profile with its effects. Do all this in the editor, not in code.
Finally, add a PostProcessing Extension to your vcams, and create a profile for them with the effects you want. These effects will take over while the vcam is active. If you don’t see that extension in the Extensions menu, then you need to import the CM PostProcessing V2 adapter package, available in the Cinemachine menu
shit… i thought this hadn’t posted or I would have replied with a follow up
code snippet for racking focus dynamically
DepthOfField dofSettings = postProcessingProfile.GetSetting <DepthOfField>();
dofSettings.focusDistance.value = Mathf.Lerp(dofSettings.focusDistance.value, Vector3.Distance(Camera.main.gameObject.transform.position, focusTarget.transform.position), Time.deltaTime *4f);
}
as to why, I’ve got a dynamic dialogue system that racks focus between two targets. I have the adapter package installed but dont have a PostProcessingExtension component available unfortunately.
things are working great with this though!
This is what my code looks like, but like @Gregoryl said it’s very rare you’d want to do something like this.
The reason I did it is that I have a single custom inspector in where I control all of the effects and lighting for my game at a single place. I can use a single instance of a ‘SceneSettings’ class and then pass lighting information from one scene to another to emulate time of day across multiple scenes.
I’m simplifying the effects though dramatically by having a single bool and slider for depth of field, color grading has like a drop down enum menu with about 6 or so settings like day, night, dusk, dawn, dream etc… and bloom just has an intensity slider.
I’m able to adjust bloom, depth of field and color grading settings then in real time while the scene is running to get the lighting just how I want it. I consider it like a custom lighting panel:
The following code is used within Update() of my own scene script, which is attached to a scene game object that is active in the hierarchy (it could be just attached to your main camera):
//You get the post processing profile from the camera the 'post processing behaviour' script is attached to:
PostProcessingProfile postProcessingProfile = mg.MG_Camera.GetComponent<PostProcessingBehaviour>().profile;
//Depth Of Field Model instance:
DepthOfFieldModel depthOfField = postProcessingProfile.depthOfField;
//Depth of field settings instance:
DepthOfFieldModel.Settings depthOfFieldSettings = postProcessingProfile.depthOfField.settings;
//settings.graphics.DepthOfFieldOn is my own class and subclass:
if (settings.graphics.DepthOfFieldOn)
{
//depthOfField is the instance of DepthOfFieldModel above:
if (depthOfField.enabled != true)
{
depthOfField.enabled = true;
postProcessingProfile.depthOfField = depthOfField;
}
depthOfFieldSettings.focusDistance = settings.graphics.DepthOfFieldResistance;
postProcessingProfile.depthOfField.settings = depthOfFieldSettings; //< -- apply it
}
else
{
if (depthOfField.enabled == true)
{
depthOfField.enabled = false;
postProcessingProfile.depthOfField = depthOfField;
}
}
The method within the custom inspector script corresponding to the scene script this is all in looks like this:
private void DisplaySettings_DepthOfField()
{
__BgnV("box");
__BgnH("");
EditorGUILayout.LabelField("Depth Of Field On:");
s_Scene.settings.graphics.DepthOfFieldOn = EditorGUILayout.Toggle(s_Scene.settings.graphics.DepthOfFieldOn);
__EndH();
if (s_Scene.settings.graphics.DepthOfFieldOn)
{
DisplaySettings_DepthOfField_Options();
}
__EndV();
}
private void DisplaySettings_DepthOfField_Options()
{
__BgnH("");
EditorGUILayout.LabelField("Depth of Field Resistance:");
s_Scene.settings.graphics.DepthOfFieldResistance = EditorGUILayout.Slider(s_Scene.settings.graphics.DepthOfFieldResistance, 0f, 1f);
__EndH();
}
//BgnV and EndV are just BeginHorizonal and EndHorizontal or whatever it was:
private void __BgnV(string options)
{
EditorGUILayout.BeginVertical(options);
}
private void __EndV()
{
EditorGUILayout.EndVertical();
}
private void __BgnH(string options)
{
EditorGUILayout.BeginHorizontal(options);
}
private void __EndH()
{
EditorGUILayout.EndHorizontal();
}
And this allows me to adjust lighting settings across scenes in one panel like so:
Pro-tip: After trial and error for hours, apparently Look-At DOF on a Vcam works only on Play (as in press Play at the top center of the Editor to run the game in it). NOT reflected when just scrubbing through or hitting playback in the Timeline to test.
…
…
…
I wonder if EasyBokeh would do the trick. I used it in my last project and it was compatible with a lot of things.
Ok reading the whole forum brings me only to one conclusion: To ask again, since we have 2022 and I too have the same problem to not be able to record dof fokus via transform target in timeline, by using dof from post processing stack > package manager > Unity 2021.LTS.
So how would a full working use case to get it working?
What render pipeline are you using? HDRP or URP or builtin?
