Search Unity

Question Weird Jitter

Discussion in 'Scripting' started by pingpenne, Jan 11, 2023.

  1. pingpenne

    pingpenne

    Joined:
    Oct 21, 2021
    Posts:
    4
    Some parts of the view jitter around while - and for a few moments after - moving my camera / walking. How could I fix this? This is more noticeable when you look at the water. I'm assuming it has to do with the camera's movement and floating point precision, but I wouldn't know how to fix it. I'm using cinemachine.
    There are also some weird white artifacts on the edges of the columns, not sure why those would be there.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    It looks to me as though your water movement code is executing before the camera has been positioned, so it's rendering with a stale camera position from the previous frame.

    Cinemachine updates the camera position in CinemachineBrain.LateUpdate, and CinemachineBrain has a late execution order. Any code that depends on the camera position must execute after that.

    One way to do this is to set the script execution order of the relevant code so that it executes after CMBrain. Another option is to use CinemachineCore.CameraUpdatedEvent, which is invoked after the camera has been placed.
     
    Bunny83 likes this.
  3. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    Jitter is usually the result of two processes happening at different rates. Identify what's writing the data and what's reading the data, then make sure they're happening together.

    Gregoryl is right on the money there (and I've had this exact problem more than a few times :p )
     
  4. pingpenne

    pingpenne

    Joined:
    Oct 21, 2021
    Posts:
    4
    My water movement is not in a script, it's part of a shader. I think shader rendering already happens a bit after LateUpdate
     
  5. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Are you pushing any values into that shader from C#?
     
    Bunny83 likes this.
  6. pingpenne

    pingpenne

    Joined:
    Oct 21, 2021
    Posts:
    4
    I'm not, it's all default shader graph nodes.
     
  7. pingpenne

    pingpenne

    Joined:
    Oct 21, 2021
    Posts:
    4
    After a bit of experimenting it turns out the shader only gets these artifacts with a clipping plane between 0.01 and 1 (excluded). Any clue? I don't know why the near clip plane would change the way the shader works. I need to find a way to keep the clip plane really low, as this is a first person game.