Cinemachine VS DepthOfField what is going on here?

Hi everyone, I need your help.

With the depth of field effect from the post processing stack v2 and “focus tracks target” enabled in the Cinemachine Post Processing script I get weird focusing issues.

I posted a video to youtube showing the problem (easier to see it in full screen)

If you look at the objects on the top left and at the one bottom left, you can see the focus going in and out. If we disable “Focus tracks target” in Cinemachine’s post processing script it stops. If we disable Cinemachine’s brain script on the camera it also stops. Cinemachine’s tracked target is the player you see in the scene. We also tried adding a simple cube to the scene and setting it as the target to eliminate the player from the equation, and we get the same result.

Any ideas?

FYI I use the latest version of Cinemachine and the Post processing stack V2. Both installed using the package manager in Unity 2018.4.12f1.

BUT WAIT! There is more to this problem.

If I aim the camera in the -X or -Z direction (global coordinates), in addition to the focus problem, the ground’s texture is moving! If looking in the +X or +Z it doesn’t move.

The ground object is just a default cube with a scale of x1000 y1 z1000 and an albedo texture added to the standard shader.

Here is a video, once again, full screen helps a lot. The movement in the ground texture is subtle but you will see it!

Disabling “Focus tracks target” fixes the DepthOfField’s focusing problems but not the ground texture.

Near the end of the video, I disable the “Cinemachine Brain” which fixes the moving texture problem.

How do I fix this?

EDIT

Huh… Strangely disabling the player object also stops the ground from shaking but does nothing for the Depth of field.

What the CM PostProcessing extension does under the hood is to make a global PP volume containing the profile settings and set its weight to match that of the vcam - if the vcam isn’t blending then that weight is 1. So the new volume is blended into the current volume settings for the camera. What Focus Tracks Target does is to dynamically adjust the Focus Distance setting in that volume.

Turning off CM effectively eliminates these dynamic vcam volumes from the PostProcessing stack, so that they are no longer blended in.

Do you get the same strangeness when you disable all the CM stuff, but add a global PP volume with the same profile that you put in the vcm PP extension? That would be worth a try, because it will eliminate CM from the equation. My guess is that you will still see the focus strangeness. If you do, then this question needs to be asked on the PP forum.

Give it a try and let us know the result.

I will try it right now

EDIT: Done.

It’s fixed when CM is disabled, and we use a Global Volume instead.

Here is the video:

Here is another test I did:

As the description says, I was investigating if tiny movements in CM’s target which induce movement in the camera and CM’s vcams is the cause of the DOF focusing issues. Later in the video I replace the target by a sphere that doesn’t move and the problem still exists.

I found the source of the problem. I added a debug line to see what values the CM Post processing script was dealing with and did a video:

When I pause the game you can see strange values interfering with the distance calculations. It appears the problem is with state.FinalPosition suddenly changing values.

Very interesting. Thanks for doing all that detective work. I’d like to understand why that state.FinalPosition is fluctuating. It’s not something we normally see. Can you show me the inspector for the active vcam at the time of the fluctuating value? Is a blend in progress?

Interesting indeed, and you are welcome. It’s the least I can do to help resolve this faster.

I’m making the video you asked for, brb.

EDIT: Here a video where I take you for a tour of all the CM scripts and the active cam

Thanks for the effort, but the video is of limited help. Still images of the inspectors pasted directly into a forum post are easier for me to process.

Your setup is fairly complex, with state-driven cameras and things being animated. I need to get an understanding of the specific vcams involved, how they are set up, and how the target is animated. The state.FinalPosityion always fluctuating to a specific value is suggestive of multiple systems trying to drive things in a conflicting manner.

Would you be able to reproduce this problem inside a very simple scene, with just cubes and spheres and the like? That would probably be the most help, because you could just send me the project and I could peek into it properly.

Just found something else. In your code the focus distance is obtained with:

focusDistance += (state.FinalPosition - state.ReferenceLookAt).magnitude;

Every time the value of state.FinalPosition fluctuates, focusDistance = 110.5474f no matter how zoomed in or out the focus of the DOF is.

In other words, It jumps between the correct value (which changes with the zoom level) and that fixed value of 110.5474f at what almost seems like a regular interval.

Sure, if the vcam is bouncing around, so will the focus distance. The question is: why is the vcam bouncing around? I need to see how it’s set up.

When you say vcam do you mean the cinemachine freelook camera?

EDIT
From searching the hierarchy the vcams are actually in the top, middle and bottom rig of the freelook camera.

Here are some screenshots of the entire settings:




I need to understand the whole pipeline, which seems to be (correct me if I’m wrong): FreeLook + StateDriven + Brain

You are correct and at the moment the state came is locked so it will use that freelook cam only.

Screenshots or the state driven cam and the brain are incoming.

5188262--515579--upload_2019-11-18_14-46-3.png

Thanks. And the extensions? On the FreeLook and StateDriven.

Also: can you try as an experiment to assign ReSkinPlayer2 as LookAt and Follow targets directly in the FreeLook? Right now they inherit from StateDriven.

I would also like to remind you that even if I set a basic sphere as the target I get the same problem. So I doubt it’s related to how the player is animated.

FreeLook has no extension loaded.
StateDriven only uses the post processing script.

Here are some screenshots of the post processing script setting:

5188343--515594--upload_2019-11-18_15-5-26.png

Can you try as an experiment to bypass the State-Driven-Camera altogether? Disable it, move the extensions to the FreeLook, move the FreeLook out of the SDC’s children (i.e give it no parent), and see if you still get the flicker

I tested with the target and look at set in the freelook.
5188388--515606--upload_2019-11-18_15-14-35.png

Same focus problem.

OK I will try that.