Pixel perfect camera borders

I’m using the pixel perfect camera, with the reference resolution set to 512 by 288. Even though this is a 16:9 ratio, when I play the game on my computer with the resolution set to 1920 x 1080 (or set the game view to 1920x1080), there’s this wide border around the box set to my reference resolution. I’m confused why these borders exist, considering there’s no aspect ratio mismatch. I can set the Pixel Perfect camera’s Crop Frame option to Stretch fill, but then the pixels are blurry which ruins the whole point.

Any help would be greatly appreciated! The photo below shows the window with my reference ratio, and then the outer green line is what actually gets rendered. The red indicates what I’d like to crop, so those tiles at the edge are at the edge of the window.

Thanks so much,
Taylor Anderson

Let’s start with basic math: 1920/512=3.75 1080/288=3.75. Just because aspect ratio matches doesn’t mean you get perfect “pixel perfect” scaling. 3.75 is not an integer. Since the dimensions didn’t divide some fudging will be necessary to fit 3*(512, 288)=(1536,864) on your screen.

(1920, 1080)-(1536, 864) = (384, 216) this where your borders come from and they need to be filled somehow. It’s your choice how to do it and what tradeoffs better fits your game.

a) cropping not selected → Gap filled with rendered content. Camera will use 1:3 scale and the visible area will be slightly wider than reference resolution. actual visible area will be 1920/3=640 1080/3=360 (640x360 which is bigger than 512x288). Picture will cover whole screen without stretching.
b) cropping enabled → Gap will be created with (typically) black border. Visible game area will be 512x288 drawn at 1:3 scale.
c) cropping and stretching enabled → The 512x288 picture will be stretched to fill whole screen. There is no black border, you don’t see more than intended but it’s not an integer scaling which is not exactly perfect. I guess only reason this mode exists (instead of just using regular orthographic camera) is because you can still use pixel snapping and upscale render texture settings.

No matter what tools you use (Unity or not) you will end up with one these 3 options: varying amount of visible area, black borders, stretched result. Because that’s the result of simple math if the numbers don’t match something will be need to tweaked.

There is also fourth option: d) changing your intended reference resolution, but that somewhat changes the content of your game and helps only with one or two resolutions if you are planning to support multiple resolutions you will still need to use one of the other 3 strategies for non perfect cases.

I want to create a Pixel Art game that supports 16:9 (Videogames) and also 4:3(iPad).

I use it as reference resolution (640x360), and my Backgrounds has these resolutions.

Is it possible to supportt these two aspect ratios using Pixer Perfect Camera?

Using Reference Resolution as 640x360 it works as expected (Full Screen) on 16:9 resolutions1024x768 (I got a small game area with Black Borders Up and On Sides)

If I use as Reference Resolution 480x360 (4x3), it also works on 16:9, but strangely I got two black bars up and down.

Is there a way to make both options viable?

360x2 = 720

720 != 768

the black bars is the difference between 768-720

1 Like