#Pixel Perfect Camera Native Resolution Mistake :'(

1 messages · Page 1 of 1 (latest)

lyric pasture
#

I'm making a 2D Pixel Art game, with a 32PPU reference and 320x240 Pixel Perfect Camera Resolution

The thing is, I realized too late that 320x180 was a better resolution to fit most resolution (720p, 1080p, 1440p, 2160p)

BUT, when I set to 320x180 resolution, the camera is too close to the character, so I tried 480x270 (x 1.5) and it looks perfect but it doesn't fit with most common resolution...

So I wanted to know if someone encountered a similar problem ? And how it was managed, thanks 🙂

zinc sky
lyric pasture
#

it works with FullHD & 4K but it doesn't work with 720p and 1440p

zinc sky
#

I can't recall the last time I saw that resolution in real life

lyric pasture
#

steamdeck also use resolution close to that, 1280x800

zinc sky
lyric pasture
#

I can do a specific build for steamdeck that's not a problem, I was answering your question about 720p not being used anymore

zinc sky
#

Yes, but I believe you'll have to swap the reference resolution depending on display resolution for the other choices too

lyric pasture
#

Not if I use 320x180 which will cover a majority, that's why I created this topic in the first place

zinc sky
#

Camera size is determined by the relationship of PPU and reference resolution
But you can't change PPU without remaking all the art assets for another PPU

lyric pasture
#

that's the problem yes

#

because if i can change the PPU, everything is solved, but i can't now

zinc sky
#

And the solution is that you have a custom reference resolution for each display

#

Or force it with cropping or stretching

#

If you don't crop or stretch, you have to find reference resolutions that are as close as possible to the desired camera size, per display

lyric pasture
#

so in the settings of the game, when i change the screen size resolution i also change the pixel perfect resolution camera, that's what you're suggesting right ?

zinc sky
#

Yes

lyric pasture
#

hmm that might be a workaround indeed

zinc sky
#

If there's other ways I'm not sure what they would be

lyric pasture
#

but i feel like it's a "dirty" way to do it

#

and it's my fault to not having set the right reference resolution and PPU right from the start

#

maybe i can do something with cinemachine and the pixel perfect extension

zinc sky
#

If you try to get the same pixel ratio and same camera size on both 1280x720 and 1280x800 displays I'm afraid there's no perfectly elegant way about it
Either steam deck will see more vertically or less horizontally compared to switch

#

Not even a "right" reference resolution or PPU can make it so it works when they have totally different aspect ratios

lyric pasture
#

well i'm just targeting 16:9 ratio

#

and 320x180 fits all 16:9 mostly used resolutions

zinc sky
#

Not targeting steam deck then?

lyric pasture
#

for example, if I had set from the start 48PPU and 320x180, it would have been perfect

lyric pasture
#

it's the 720p switch port that is bothering me most

zinc sky
#

Ultimately you've got your sprite art as it is, and then you decide how you want it to appear on each display in terms of pixel ratio and camera size, and then find the best reference resolution to that end

lyric pasture
#

Something i didn't thinked about when starting... fuck me

zinc sky
#

Maybe a reference resolution that mathematically works on switch's tiny screen and a huge 4K monitor is not good to look at if shrunk so small or blown up so big

lyric pasture
#

Also why i'm obsessed with 16:9 and the 320x180 resolution => i don't need to rework my canvas, since with a canvas scaler it will automatically fit

zinc sky
#

Terraria intentionally reduced the camera space on its mobile ports because the pixels would be too small otherwise

lyric pasture
#

and also the UI of course

zinc sky
#

Usually you want the UI scale to change depending on resolution and physical size of the screen

#

Or at least have the option to

lyric pasture
#

Isn't that what the canvas scaler component do ?

zinc sky
#

So it's useful if you want the UI to always adapt to any resolution automatically
But it also can be used to allow scaling the UI elements up or down separately from display resolution

lyric pasture
#

Alright I see

zinc sky
#

A UI scale that looks okay on a FullHD monitor is often too darn small on a mobile device screen

lyric pasture
#

so it can be a problem for switch or steamdeck

zinc sky
#

Or too big on a 4K screen
But because 4K screens have greatly varying physical sizes and their users have varying preferences, not being locked into just one UI scale is helpful

lyric pasture
#

I'll try to change both screen size resolution & pixel perfect camera reference resolution for the different resolution and if it works we can consider this topic solved

zinc sky
#

UI scaling is also an accessibility aspect as some people may have problems with eyesight and either seeing the UI clearly, or seeing the gameplay form behind the UI in some cases

#

A bit of a tangent but something to keep in mind in the future
UI scaling gets way harder if you have to keep that pixel perfect too, though

lyric pasture
zinc sky
#

(And that's before getting into fonts)

lyric pasture
#

lol that's why i didn't used pixel perfect font but a classic one instead

lyric pasture
#

also tested with cinemachine, same results

zinc sky
lyric pasture
zinc sky
#

How are you testing whether it's working or not?

lyric pasture
#

I try first in the inspector then i do a build to change it in game via script

zinc sky
#

So what part didn't work
You couldn't change reference resolution, or display resolution, or couldn't find a matching combination?

lyric pasture
#

couldn't find a matching combination for HD & WXGA, it's either too close or too far

zinc sky
lyric pasture
#

let me show you

#

So, this is the result by default when moving to 720P

#

and it can only move to either this :

#

(too close)

#

or this :

zinc sky
#

Helpful if the screenshots included the resolution dropdown to show exactly which they are

lyric pasture
zinc sky
#

All these are with 1280x720 specifically?

lyric pasture
#

yeah

#

i can't get exactly what i want to show on screen, it's either too close or too far

zinc sky
#

What's the ideal?

lyric pasture
#

what i have in 1080p, this :

zinc sky
#

With 480x270 ref I assume?

lyric pasture
#

yes

zinc sky
# lyric pasture yes

With 1280x720 I think your best camera size match is 426x240 ref with 3:1 pixel ratio
It's not actually a resolution divisible by three so it may be a bit of a fluke that it seems to work

lyric pasture
#

let me try that

zinc sky
#

Camera is only a smidge smaller, which may work in the smaller display's favor

lyric pasture
zinc sky
lyric pasture
#

3:1

#

but nevermind i guess i'll abandon 720p for now, or just accept the idea that it will be a little too close and move on

zinc sky
#

If you're not using Stretch Fill, regardless of camera size your rendered pixels have to map to an integer number of display pixels*

#

So one sprite pixel = 1, 2, 3, 4 and so on in display pixels

lyric pasture
#

Yeah Stretch Fill is doing the job for that when i tried but the render is lame 🙁

zinc sky
#

Also note that if your Grid Snapping is set to None, your sprites aren't made pixel perfect and the component isn't doing anything except resizing the camera

lyric pasture
#

but without the cinemachine camera i always had it activated

zinc sky
zinc sky
#

(Could also be an execution order issue, if CM's camera movement is one frame ahead or behind the pixel snap)

#

Either way you aren't really getting any "pixel perfectness" if you don't have snapping or upscaling

lyric pasture
#

Yeah i guess i'll remove cinemachine since it's causing more harm than anything right now, didn't have all this problems before putting it

lyric pasture
#

With the component :

zinc sky
lyric pasture
#

Alright so it's doing something at least

zinc sky
#

If the camera is exactly of size relative to your chosen PPU and display resolution so that the pixels map 1:1 without having to squash or stretch the sprites, issues related to that disappear

#

But you could do the same by setting the camera size manually without pixel perfect component at all

lyric pasture
#

but the component also help to don't have the famous bug of "empty space" between tiles while moving

zinc sky
#

The practical effect is that without snapping your assets' pixel grid won't be enforced

lyric pasture
#

I don't understand why the pixel snapping or upscale texture option cause jitter, all my physics movement are handled in a fixedUpdate with fixedDeltaTime, i even play with the Update Method of the cinemachine brain but nothing is working

#

i'm just having better result overall without these option activated with a cinemachine camera

zinc sky
lyric pasture
#

and the player has Interpolate activated on the rigidbody

zinc sky
#

Damping 1, 1, 1 means it's rather heavily smoothed
That cannot work well with pixel snapped graphics

lyric pasture
#

alright i'll try playing with this value

zinc sky
#

0 is the only right value
Even old genuinely pixel perfect games with no possibility of sub-pixel camera or sprite positions to snap from suffered from jitter with smooth motion

#

Unless the snapping and motion are both timed precisely

#

But that's beyond the scope of what the pixel perfect component does

lyric pasture
#

Well if i set to 0 i lose the smooth effect and so i have no need for a cinemachine camera

#

and i'm still having the jitter when i activate one of the pixel snapping option

zinc sky
#

Smooth motion and pixel perfect graphics aren't well compatible, so you have to prioritize one of them

lyric pasture
#

I see

zinc sky
#

There are possibly some third party pixel perfect assets that snap and sprites on a render texture and then allow the camera to move relative to it
So best of both worlds basically

#

But last time I checked there were very few if any available, and I don't know if there's unique drawbacks to the technique

#

But it's possible

lyric pasture
#

Didn't know it was that complicated to achieve that in a 2D side scrolling game

zinc sky
#

Unity is a 3D engine, renders sprites as 3D meshes and basically builds everything around that
The 2D features haven't gotten equal development, and what they did get is more focused on the strengths of mesh based sprite rendering