Search Unity

Dancing shadows

Discussion in 'Cinemachine' started by Lord_Eniac, Feb 4, 2021.

  1. Lord_Eniac

    Lord_Eniac

    Joined:
    Jan 28, 2020
    Posts:
    50
    I have what I hope to be an easy problem to fix. My scene has real time lighting, a cinemachine virtual camera, and a light source that is set to real time with soft shadows enabled. If I set the camera to look at my main player, the shadows dance around (as if the light source were changing directions erratically). If I change the look at target to nothing, the shadows behave. If I set the target to a stationary object, there will be some "dancing", but it will eventually settle down.

    At first, I thought I was getting some weird z-fighting, but I narrowed it down to the Cinemachine camera. If I step through time, I can watch the shadows change orientation from one frame to the next.

    EDIT: Incidentally, the objects in the scene appear to be fine (e.x. no jittering, etc.) I am additively loading the scene, so I don't know if that would affect anything. I've also tried changing the various update stages of the brain. Nothing, short of changing the look at target to null, fixes the problem.

    Currently using Unity 2020.1.1f1 with Cinemachine 2.6.3
     
    Last edited: Feb 4, 2021
  2. Lord_Eniac

    Lord_Eniac

    Joined:
    Jan 28, 2020
    Posts:
    50
    After some more investigation, I've narrowed it down further. The problem can only be seen if the look at value is set. My particular look at object is a physics-based object, but I don't think that's the issue based on my investigation.

    Changing the near plane value of the virtual camera can cause the problem to nearly disappear when using a value of 1.0, but using values less than 0.5 are where problems start. The attached image illustrates this. The higher the value for the near plane, the better the behavior of the shadows.

    If the look at target is null, then there aren't any problems at all regardless of the near plane value.

    Illustration.png
     
  3. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    My gut is that this isn't a Cinemachine issue but rather a graphics issue. When you strip away all the fancy tooling, Cinemachine doesn't do much more than manipulate the camera's transform, so it's not particularly likely to be the source of shadows that do unexpected things...it's just that the Camera is attached to that transform.

    (Full disclosure: graphics is definitely NOT my area of expertise).

    I've seen something like this before. In my case, it turned out that I had more lights than the render pipeline would support, which caused some lights to "pop" off and on at unexpected moments. The solution in my case was to shift from Forward to Deferred rendering. Again, I'm not a graphics expert, so I might have this wrong and following my solution might not be appropriate to your case.

    In any event, I think you'll get better attention to this issue in the graphics forum.
     
    Lord_Eniac likes this.
  4. KingAustin

    KingAustin

    Joined:
    Jan 12, 2016
    Posts:
    20