2D Game: Pixel perfect camera + Stretch Fill breaks Camera.WorldToScreenPoint

,

Hello,

I’m making a 2D game. The important thing is to make camera show only the required area no matter which resolution is selected. I’m using Pixel perfect Camera for that with Stretch Fill, so it fits any resolution.

Another think I have is a shader that inverts color if vertex position is lower left from inputted screen position (red circle here). This shader works correctly when I don’t used the Stretch Fill, but when it is on, it moves the screen position of inputted object away as you can see from these images (Screen position is passed as vector Camera.main.WorldToScreenPoint(circle.transform.position):wink:

16:10 aspect


Full HD

QHD

The screen position offset then changes based on different resolution. If I turn off stretching, output is correct, but i can see around the room.:

Any idea how to go around this or possibly other way of doing it? What I’m looking for is a way to show tilemap of specific resolution (496x288) on any camera resolution with black borders around…

Until this bug(?) is fixed, you could just create another camera as a child of the main camera(at 0,0,0 local position and rotation) that doesnt have pixel perfect component attached and use it for screen-world space conversions. The child camera component must have the same settings as the main camera

You can disable the camera component for the child camera and it wont incur much overhead

Unfortunately, that did not fix the issue. Both camera’s return same screen position, problem is, that since Pixel perfect Camera transforms the render afterwards, this “correct” position is incorrect in the transformed view during shading. Or at least that’s what I think it is.

Alright, thought of an easy workaround which seems to work.
Instead of passing screen position into a shader, I’m passing world position and in shader calculating world position of each vertex.

Thanks for help anyway.