Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved [Fixed in 2021.1] Pixel Perfect camera (experimental) does not like Cinemachine (jittering)

Discussion in '2D Experimental Preview' started by AlexVillalba, Jan 10, 2021.

  1. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    Hi everybody, I have just made some tests consisting in
    1. A game object with a Rigidbody2D (without Interpolation, otherwise jittering appears in both cases).
    2. A game object with a CinemachineVirtualCamera. It uses a Transposer without damping, and follows object in 1.
    3. A game object with a Camera and a CinemachineBrain, which uses the virtual camera in 2, updating in FixedUpdate, and the component:
      1. Option A: Pixel Perfect camera from the 2D Pixel Perfect package v4.0.1.
      2. Option B: Pixel Perfect camera (experimental) that comes with the URP.
      3. In both cases, PPU: 4, Resolution: 1920x1080, all checkboxes ON.
    I apply some force to the Rigidbody2D. Its velocity is constant, and the framerate is constant.

    With Option A, everything is perfect, the object is always at the center of the image, no jittering. I see a yellow banner appears in the inspector telling me this component is not compatible with Cinemachine, and I have to say it seems it is not doing anything, no pixel perfect effect and some rare white dot artifacts when executed in a build. So this option may be the same as no pixel perfect component.

    With Option B, it jitters all the time, although it seems the position of everything is correct in the world, but not at the moment of rendering. I do not know. It does not matter what value I write in any field, which update method I use, whatever, the result is always jittering.

    EDIT: I'm using the 2D Renderer of URP in Unity 2020.2.
     
    Last edited: Jan 21, 2021
  2. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    It's like the Cinemachine virtual camera and the pixel perfect camera are fighting.
     
  3. Coin9

    Coin9

    Joined:
    Feb 14, 2019
    Posts:
    16
  4. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
  5. digiwombat

    digiwombat

    Joined:
    Sep 26, 2013
    Posts:
    48
    I have the same problem and it's known to the devs (check the linked thread in my post). Sadly, at the moment the only solution I've found was to literally copy the the entire URP package out of the package cache (which removes the ability to update it) and manually comment out line 194 of the PixelPerfectCamera script which snaps all renderers and the camera in the scene to the pixel grid. Cinemachine hates the clamping, apparently, and jitters around all over.

    This is obviously no kind of solution because it does not fix jitter for damping > 0, requires custom code changes in a package, requires breaking updates to the entire URP package, and is at best bandaid on top of a gaping wound.

    I get that the 2D team is woefully understaffed, but I just don't get why this isn't even remotely a priority considering how aggressively URP, pixel perfect, and Cinemachine are pushed in the marketing. I basically sat on complaining about it for months because I figured it would get better with some updates but I guess we have to be squeaky wheels.

    Hopefully we'll hear something at some point but I'll probably just write my own camera controller at this point to save myself the pain of wrestling with code I can't tweak without breaking updates for the entire rendering pipeline.

    EDIT: It's worth disclaiming here that the aggressive camera pixel snapping will cause jitter with pretty much any camera follow script, not just Cinemachine, since the PixelSnap function is basically just fighting your camera script. At least, that's how it looks from the code, maybe there's something I'm missing there.
     
    Last edited: Jan 17, 2021
    simple421, ZombByeGod and NotaNaN like this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,823
    Have you tried using the CinemcahinePixelPerfect extension on the vcam?
     
  7. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    I do not see any difference between using it or not, I've just tried.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,823
  9. digiwombat

    digiwombat

    Joined:
    Sep 26, 2013
    Posts:
    48
    In my case, I've had the Cinemachine Pixel Perfect on the whole time. I looked through the code for it briefly and there isn't any locomotion logic, it just passes the othro size to the pixel perfect script for integer scaling:

    Code (CSharp):
    1. var lens = state.Lens;
    2. lens.OrthographicSize = pixelPerfectCamera.CorrectCinemachineOrthoSize(lens.OrthographicSize);
    3. state.Lens = lens;
    PixelPerfectCamera.cs's PixelSnap function snaps the camera position to the pixel grid explicitly, which is where the jittering happens (even with non-Cinemachine follow cams in my testing) so it's something to do with that and the timing between the snap and where the follow cam thinks the camera is. Probably anyway. I haven't looked into it super deeply since I have a thousand other fires to put out, haha.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,823
    If someone here would like to put together a small project that shows this issue, I can take a look at it and make recommendations.
     
  11. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    Done.
     

    Attached Files:

    NotaNaN and Gregoryl like this.
  12. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    The Pixel Perfect Camera (Experimental) (the one for URP and no Cinemachine involved) has always been broken this way. The problem happen with Upscale Render Texture is enabled.

    In a build or maximized game tab it is less noticeable. Heavy inspector updating makes it jitter by 10% of the screen size.
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,823
    I can confirm that this problem is not related to Cinemachine. Attached is the sample project from @ThundThund with Cinemachine removed. The problem is the same.

    My recommendation: open Unity and report a bug in PixelPerfect, using Unity/Help/ReportABug. That way the appropriate team will address it. Include the attached project and clear repro steps in the bug report.
     

    Attached Files:

  14. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    Sure, I did it 2 weeks ago. I added a link to this thread, but I guess I should add the project too. Is there a way to do so? The bug is this one: https://fogbugz.unity3d.com/default.asp?1305133_ok52l78pbgv5gnsv
     
    Gregoryl likes this.
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,823
    NotaNaN and AlexVillalba like this.
  16. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    Thank you.
     
  17. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    Hi everybody again, after 2 months I'm still struggling with this issue, and I'm not the only one. The bug has been closed without any explanation. @Gregoryl are you sure you edited the correct bug? My sample project does not seem to be attached to the bug report (or maybe the bug tracker does not show attachments, I don't know).
    Shal I report the same bug again, attaching the project from the beginning?
     
  18. Angry-Armadillo

    Angry-Armadillo

    Joined:
    May 28, 2013
    Posts:
    4
    I just ran into the same issue today, when trying to update to the newest version of unity. Pixel perfect camera was following my moving gameobjects just fine before, but now it just goes apeshit no matter what setting I use.
     
  19. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
  20. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    347
    It seems it has been fixed in version 2021.1, according to my tests. Can anybody confirm?
     
  21. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Yes, it seems fine in 2021.1.