Search Unity

Upscaling Fixed Native Screen Resolution

Discussion in 'Scripting' started by SkillBased, Oct 16, 2016.

  1. SkillBased

    SkillBased

    Joined:
    Aug 11, 2014
    Posts:
    141
    I'm producing a game that has a retro look so it's in 640 * 360. Even though it's at that resolution natively and is fixed I want to be able to upscale it when the game plays, doubling it to the intended resolution of 1280 * 720

    Before you say "why not leave it at 640 * 360 and let the graphics card/monitor/console/TV do the scaling?" know that I have particular reasons why I don't want that to be the case.

    To clarify, I basically want a 640 * 360 game to render to 720p.
     
  2. SkillBased

    SkillBased

    Joined:
    Aug 11, 2014
    Posts:
    141
    I may have figured out how to do this. I haven't fully tested it out but what I did was set the resolution to 640 * 360 and then the Camera Ortho size to 1.8

    Out of curiosity I switched the resolution then to 1280 * 720 and it all seems to display and work as intended.

    EDIT: Nope. Unfortunately, there are lots of problems with getting Unity to behave pixel perfect at a low res and some solutions create a different set of problems.

    Low-Res Default: Unity won't run the final build in 640 * 360. It seems the lowest it will run at is 640 * 480, which obviously results in distorted stretching. Which is bad.

    Fix #1: As I posted above, you can run the final build at 1280 * 720. What I didn't realize was this re-introduces mis-aligned pixels because it basically scales the game so 1 horizontal pixel becomes 2 horizontal pixels, etc. The problem with this is Unity still calculates per pixel so instead of the smallest unit of movement being 2 pixels (again, on the horizontal axis, for instance) it's still 1 pixel. So, instead of a pixel grid that's always square and looks like this:

    -xx-
    -xx-

    You can get results where the alignments look like this

    -xx-
    --xx

    Now, In-editor you CAN force the game to run at 640 * 360. In-editor tests show that if you run at 640 * 360 Unity shifts/chops pixels a bit but it mostly looks very good and pixel alignment is perfect. However, rotations look really bad so you'd have to work with 0% rotations. If you want things to rotate, you'd probably want to make a spritesheet animation.

    If you can stomach this (not sure I can), the next step is to figure out how to make the final build stretch a 640 * 360 across 1280 * 720. Turns out you can do this with the camera but apparently you need the pro version to do this. Basically you would

    1) Render the scene to a 640 * 360 texture with camera 1

    2) Render the above texture to 1280 * 360 display with camera 2.

    (mentioned in this post by Eric5h5):
    http://answers.unity3d.com/questions/15862/is-there-a-good-way-to-get-very-low-resolutions.html


    Fix #2: The next approach would be to force a "virtual pixel grid" of some kind. Basically this would involve some code that forces transforms to snap to fixed unit interval. So, for instance if your images are at a PixelPerUnit of 1pixel:1unityUnit then all of the calculations that result in moving less than 1 whole unit basically go ignored. The problem with this is it makes motion very jagged because if your GameObject is moving less than a whole unit on each frame, it basically isn't moving when the frame is rendered. This becomes somewhat random which results in very choppy motion IE: frame1: moves a bit, frame 2: doesn't move, frame 3: moves a bit, frame 4: doesn't move, frame 5: doesn't move...

    Another problem with this approach is 1:1 pixelPerUnit mapping is very bad for physics. Anything lower than 8pixel:1unityUnits seems to create bottlenecks and render physics unuseable. You can use a PPU of 10pixel:1unityUnit but now you're snapping to float values of 0.1 units instead of every 1 unit. This isn't a big deal but it's a bit harder working in tenths rather than 1's.

    For me none of this matters though because I find this entire FIX2 approach unacceptable until/unless I see it working the way that I would consider pleasing to the eye.


    ------------------------------
    The search continues...
     
    Last edited: Oct 24, 2016