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

Hi everybody, I have just made some tests consisting in

  • A game object with a Rigidbody2D (without Interpolation, otherwise jittering appears in both cases).

  • A game object with a CinemachineVirtualCamera. It uses a Transposer without damping, and follows object in 1.

  • A game object with a Camera and a CinemachineBrain, which uses the virtual camera in 2, updating in FixedUpdate, and the component:

  • Option A: Pixel Perfect camera from the 2D Pixel Perfect package v4.0.1.

  • Option B: Pixel Perfect camera (experimental) that comes with the URP.

  • 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.

It’s like the Cinemachine virtual camera and the pixel perfect camera are fighting.

Are you talking about the same jitter problem described in this thread?

It’s pretty similar, but it happens to me even when Damping equals zero. I’m using the experimental version that comes with the URP.

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.

3 Likes

Have you tried using the CinemcahinePixelPerfect extension on the vcam?

I do not see any difference between using it or not, I’ve just tried.

@yuanxing_cai any thoughts on this?

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:

var lens = state.Lens;
lens.OrthographicSize = pixelPerfectCamera.CorrectCinemachineOrthoSize(lens.OrthographicSize);
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.

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.

Done.

6763729–781174–PixelPerfectCameraBug.rar (23.4 KB)

2 Likes

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.

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.

6764527–781348–PixelPerfectCameraBug.zip (28.2 KB)

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

1 Like

Thanks for the link. I edited the bug report and added the sample project.

2 Likes

Thank you.

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?

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.

I reported a new bug, with the sample project.
https://fogbugz.unity3d.com/default.asp?1322876_e5ccq0ij7jfra6p3

It seems it has been fixed in version 2021.1, according to my tests. Can anybody confirm?