Search Unity

Question Pixel Perfect Camera vs screen resolution questions

Discussion in '2D' started by Autoface, Mar 23, 2023.

  1. Autoface

    Autoface

    Joined:
    Sep 23, 2013
    Posts:
    112
    Hi, So I'm creating a game which uses the Pixel Perfect Camera and I'm having trouble getting things to look relatively the same when working with different screen resolutions.

    The PPU is 16 for all of the psirtes in my game.

    So this is the Pixel Perfect Camera component.
    upload_2023-3-23_12-22-20.png
    I'm using 432x243 because it results in the best sprite size.

    Below is a sample image used to display the amount of zoom/sprite size in the gameplay window.

    This is what is displayed when using 1920x1080 resolution which is good:
    upload_2023-3-23_12-26-28.png

    This is what is displayed when using 1366x768 resolution which is also good:
    upload_2023-3-23_12-27-1.png

    This is what is displayed when using 3840x2160 resolution which is also good:
    upload_2023-3-23_12-27-37.png


    Now this is the bad bad which is at 1280x720 which looks way more zoomed out that any of the others.
    upload_2023-3-23_12-28-17.png

    Why is a lower resolution is resulting in a kind of zoomed out appearance?

    And is there anyway to get a silmilar zoom/scale with all resolutions?


    Many thanks!
     
  2. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    you can only get the same zoom in the same multiples of original res


    original : 432x243
    2x : 864x486
    4x: 1728x972

    as you can see your original resolution doesnt lend itself to traditional resolutions so it will always look different if you use pixel perfect camera
     
  3. Autoface

    Autoface

    Joined:
    Sep 23, 2013
    Posts:
    112

    ahh ok that makes sense.
    So if I were to use 320x180 which looks quite similar on multiple resolutions, is there a way that I can maybe "zoom out" a little without changing the PPU value in the pixel perfect camera component?
     
  4. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    you cant really control zoom freely like that with pixel perfect, you have to take what you can get.

    Remember old games like zelda, minish cap, super mario. Old games didnt have zoomout because of this issue.

    IMO pixel perfect is overrated, its a headache and the end product is not worth it, look stardew valley for example, its not pixel perfect and most people dont notice, in fact they might even think that its pixel perfect.

    You should just use a good formula for ortographic camera zoom levels, so you can set your zoom more freely and get decent result like stardew.
     
  5. Autoface

    Autoface

    Joined:
    Sep 23, 2013
    Posts:
    112
    Ah thats fair enough. The main reason Im using the pixel perfect camera is because of the "half" pixels im seeing, which I think is because of the 16ppu on my sprites. The map in my game is procedurally generated and using a higher PPU or higher res sprites would take a lot of reworking.

    The pixel perfect camera fixes that for some resolutions but for others it doesn't work so well.

    I might try and make a script which adjusts the pixel perfect camera settings depending on what the resolution is currently set to.
     
    Last edited: Mar 23, 2023
  6. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    you could try out this formula without the pixel perfect camera, see if it works for you:

    Code (CSharp):
    1. ortographic size = ((Screen.currentResolution.height) / (scale * PPU)) * 0.5f
    for the scale variable you should use multiples of 1,2,4,8 only to avoid the half pixels, see what works for you
     
    Autoface likes this.
  7. Autoface

    Autoface

    Joined:
    Sep 23, 2013
    Posts:
    112
    Thanks for that. That somewhat works for the half pixel issue... maybe. One of the other things that the Pixel Perfect Camera also fixes is gaps between tiled sprites.

    I mentioned earlier that my map is procedurally generated. All of my terrain/ground sprites are individual gameobjects and when my player walks around sometimes gaps will appear between the sprites. The gaps flicker in and out.
     
    Last edited: Mar 23, 2023
  8. Autoface

    Autoface

    Joined:
    Sep 23, 2013
    Posts:
    112
    Looks like adding all of my terrain/ground sprites to a SpriteAtlas fixed the issue.

    Thanks for the help!