Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Official Pixel Perfect Preview Package

Discussion in '2D Experimental Preview' started by rustum, May 28, 2018.

Thread Status:
Not open for further replies.
  1. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    That's good to know, thanks!

    A status boolean and an event we can subscribe to would be nice in that case!
     
    embraceware likes this.
  2. embraceware

    embraceware

    Joined:
    Apr 17, 2017
    Posts:
    32
    I'd like to know how others are handling the readiness of the PixelPerfectCamera.

    I created a cameraInitialized bool in my GameManager singleton which is flipped to true once the pixelRatio on the PixelPerfectCamera is calculated. When I first started using the PixelPerfectCamera I expected the calculated results to be available in the Start() method and was wondering for hours why the pixelRatio was always 1... o_O
     
  3. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    You could start a watcher coroutine or do the calculation yourself.
     
    embraceware likes this.
  4. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    how to get ride of that red text(error) it keeps showing in some resolutions like 800:480 ? i tried to change the Assets pixel per unit and reference resolution settings but nothing new.
     

    Attached Files:

  5. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    no idea in unity forum ????
     
  6. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    @MrZzzero
    Comment out line 237 and line 242 in PixelPerfectCamera.
     
  7. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    thx for the reply but what do u mean ? is it a problem in the script of the pixel perfect camera ?? i didn't touch it ; is it a bug in the package of unity version 2018.2.3f1 i tried to redownload the package but i have same problem even in new projects ???
     
  8. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    Its not a bug, its by design.
     
  9. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    So there is nothing wrong with my camera or project settings ? another question is there a way to change the view size of this pixelperfect camera ,i want to zoom out ? thanks in advance
     
  10. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    Increase orthographic size.
     
  11. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    173
    I'm having trouble using this script correctly.

    My settings are:
    PPU 32
    Reference Resolution 640x360

    If I play in resolution
    1024x600 I see way too much of the stage, orthographic size becomes 9.375

    In resolution
    1280x800
    it plays perfectly

    But then in all these resolutions I see way too much:
    1024x576
    800x480
    854x480

    I don't understand why it can't just show the proper amount of 'tiles' either horizontally and vertically. It only works OK on some resolutions.
    Very confusing.
    I just want to show around 20 tiles wide. Height can be flexible.
     
  12. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    173
    I didn't follow your conversation but I can't change the orthographic size when the script is attached
     
  13. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    like what rose said u can't change orthographic size cause i think the perfect pixel script who do that auto , this option need more clarification from it's creators i mean this package .
     
  14. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    Did you set it up to crop the sides? This should get rid of the problem of seeing more of the stage than you are supposed to.
     
    Last edited: Sep 10, 2018
  15. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    173
    Then I have a lot of black around the game, haha.
    Isn't there a way to make it bigger without making it so blurry? (If I turn on Stretch it doesn't look any better than without the camera.)
     
    MatthiasStuetzer likes this.
  16. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'm looking through PixelPerfectCameraInternal trying to find the right place to stretch the viewport height by 1.2, so effectively every pixel appears to be 1/5 taller than it is wide, to emulate the old 320x200 to 320x240 CRT aspect ratio correction. I understand the viewport will render outside of the screen, which is fine since I'll be designing everything to fit in the section that is within the screen. Which part of the script/class should I modify to allow this?
     
  17. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    The ideal way for stretching would be not to use the blurring AND/OR not to stretch the smallest version of the texture but the one you would get when cropping X and Y... it auto fits the texture into the window. If you stretched that version it would look nicer. From what I've seen it is how GameMaker Studio 2 does it. When you resize the window it is blurry for a second and then it catches up and becomes crisp.
     
  18. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Yeah, I'm just trying to emulate this effect:

    The left is square pixels, the middle is what would happen if the rendertexture at the reference size were stretched, and the right image is what would happen if the upscaled rendertexture were stretched. You end up with nice, 1:1.2 width/height pixels, whereby the width of the pixel is the same, but the height is now 1.2, as it has been stretched after the upscale, which is allowing this.
     
    MatthiasStuetzer likes this.
  19. DrFischman

    DrFischman

    Joined:
    May 3, 2013
    Posts:
    3
    Is there a way to get this script to respect the viewport rect settings on the camera? I want to utilize pixel perfect rendering but only within a subsection of the viewport. Currently with this script enabled the viewport rect is ignored and it fills up the full screen.
     
  20. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Yes more than a few people mentioned the blurriness when doing stretching. It's on top of our todo list.
     
    Last edited: Sep 13, 2018
    MatthiasStuetzer likes this.
  21. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Most of the calculations of the camera properties happen in LateUpdate() of the component so that it's the last one to touch the camera. So after PixelPerfectCamera has been running for one frame you can be sure that pixelRatio will have the right output.
     
  22. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    What's your desktop resolution? Judging from your screenshot you're on a rather small resolution. It's possible the game view size isn't handled correctly when Unity editor is running at very small desktop resolution.
     
  23. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Zooming is another feature we'll work on for the next major update of the package.
     
  24. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    The black bars is a price you need to pay if you want pixel perfectness for an arbitrary resolution. We're figuring out how to best fix the blurriness when stretching though.
     
  25. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Currently no. The reason for that is we need to control the viewport size in order to do the cropping. If cropping / letterboxing is not needed then I think there's a way to make it respect your viewport setting.
     
  26. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    upload_2018-9-13_19-12-24.png

    I replied you in our private conversation. Here's what manually calculating Camera.aspect could achieve. As you can see the pixels aren't square anymore.
     
    Last edited: Sep 14, 2018
    Zebbi likes this.
  27. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    Thank you for the update! I'm sorry if I came across as too complainy. I'm really excited for your team's great work on this package as this would be the last thing needed for me to drop GameMaker completely for 2D projects.
     
    yuanxing_cai likes this.
  28. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Whereabouts is camera.aspect? Your example looks great! As each pixel at 8w*9h, I'm looking for each pixel to be 20% taller than it is wide, which is a bit more than your example. What changes should I make to get it at least the same as yours, then ready for tweaking?
     
  29. DrFischman

    DrFischman

    Joined:
    May 3, 2013
    Posts:
    3
    Can you elaborate on what this way would be?
     
  30. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    There are places in the PixelPerfectCamera code where we set VP size to (Screen.width, Screen.height) when Crop Frame X/Y is not enabled. These need to be changed to instead take your original VP size.
     
  31. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    It's simple: you just do something like
    CSharp]mainCamera.aspect = mainCamera.pixelRect.width / (mainCamera.pixelRect.height * 1.2f);

    in one of your own scripts.
     
    Last edited: Sep 14, 2018
  32. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Is there some way to do pixel perfect post processing with RT upscaling? Im trying to do screen space 2d reflections via OnImageRender, but when i distort the reflections, it clearly becomes pixel imperfect. Is there some way to do post processing on the upscaled RT specifically?

    PixelImperfectPostProcessing.PNG
     
    Last edited: Sep 23, 2018
  33. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Are you around at the moment? I've pmed you an example, unfortunately that method seems to stretch the viewport before the upscale and it keeps the image within the screen creating a mushed, 4:3 looking image?
     
  34. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Nevermind. Got it done via Command Buffers using CameraTarget rendertexture.
     
  35. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Glad you've solved it! Do you mind posting a new screenshot of your desired/correct result? I just want to know more about what type of post processing effects people want to apply to their pixel art games.
     
    Last edited: Sep 25, 2018
  36. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    post effects that need to be pixel perfect to work well
    - scanlines
    - crt filter
     
  37. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Yeah. Especially now that Switch's NES emulator has a CRT filter...
     
  38. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Sure thing! I just needed post processing to be done in the same resolution as the upscaled RT and conform to the pixel grid, but OnImageRender seemed to do it on a full screen resolution RT. Its much better in motion, so heres the gif:
     
    yuanxing_cai likes this.
  39. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Sorry for the late reply. One of the other things you could try is to fetch Camera.pixelRect after Pixel Perfect Camera has be running for at least one frame. A simple way to try it out is to put your aspect ratio script in Update() instead of Start().

    And oh, please use direct conversation only when it's absolutely necessary, for example when you need to include sensitive information about your project. We want to keep all the interactions and conversations as open as possible so that other users can benefit from those information if they have similar questions. Thanks :)
     
    Last edited: Sep 25, 2018
  40. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Sorry! Here's the script I put on my mainCamera:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class AspectCam : MonoBehaviour {
    5. public float aspect;
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         Camera mainCamera = GetComponent<Camera>();
    10.         mainCamera.aspect = mainCamera.pixelRect.width / (mainCamera.pixelRect.height * 1.2f);
    11.     }
    Here's what it looks like before I use it:

    And here's what it looks like with that script attached:

    Any ideas why it seems to be mashing the pixels up before the rendertexture is blitter, and then squeezed into the window with pillarboxing? Here's how I was expecting it to appear (and I'd just readjust the position of the camera and UI):
     
  41. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Doesn't appear to be improving it by adding to update, is there anything else I can try to get the above effect?
     
  42. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527


    Interesting video about retro games, including discussion about non square aspect ratios
     
    Zebbi likes this.
  43. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Wow thanks, I'll take a look! Non-square pixels were almost a standard before SVGA so it's nice to see it being discussed.
     
  44. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Well, that takes me back. I honestly forgot that I had issues with it. Well, here's the project, I still can't make parallax work correctly. It jitters too much, even when using rounding function provided by the camera script.

    https://drive.google.com/open?id=1AGlJ134nLweMTL8kDZNYVz60vMc5aJPF

    Used Unity 2018.3.b3 for this project. Each sprite has a parallax script and in it there is a checkbox that determines whether to use raw position input or have it rounded by the camera script.

    Thank you.
     
  45. UDN_46c91c6c-aeb1-471f-87fb-917fc1db02c9

    UDN_46c91c6c-aeb1-471f-87fb-917fc1db02c9

    Joined:
    Dec 3, 2017
    Posts:
    21
    Hello, I have an issue with the camera snapping.
    I am prototyping a game heavily based in post effects, so I decided to go into a low resolution pixel art direction that could help me by heavily reducing the work of the fragment shader.
    So, this is how I procceded:
    1. I downloaded the demo project and opened the tileset scene.
    2. I modified the camera to render the gameplay to a 320x240 texture (same as the pixel camera configuration), no bilinear filtering
    3. I placed the texture into a plane and the main camera points towards this plane.
    Seems to work wonderfuly until you move.
    It seems that the camera is not snapping to the pixel.
    badcam.png

    This seem to be creating a strange behavior where in the final render, some pixels are bigger than others:
    badcam2.png

    When the camera is scrolling is horrible because each pixel row and column is changed on every frame and it looks like an underwater effect.

    Is there any way to workaround this? Am I missing something? It should be kind of easy to render one-to-one pixels but it seems not.

    In fact, it seems to be something related to the snap to pixel because the main character doesn't snap:
    badcam3.png
     
    Last edited: Oct 4, 2018
  46. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    So ive been trying to find a way around excessive blurring when using stretch fill, and ive found that upscaling the low-res RT with point filtering by a integer amount to the closest resolution to the screen resolution, and then outputting that RT with bilinear filtering, produces a much better and clearer results. Its obviously not a panacea, not pixel perfect since its impossible, but it produces much better results than default stretch fill now. Heres the screenshots of the results:

    Reference (900p):
    pixel_reference.png

    Default blurry stretch fill implementation (1080p):
    pixel_1080p_old.png

    Custom stretch fill (1080p):
    pixel_1080p_new.png

    Custom stretch fill (1440p):
    pixel_1440p_new.png
     
    Last edited: Oct 7, 2018
    yuanxing_cai and SugoiDev like this.
  47. Jordi_Unitys

    Jordi_Unitys

    Joined:
    Dec 15, 2016
    Posts:
    19
    Hey! Currently trying to reduce the excessive blurring when using stretch fill too. Can you tell me where do you get access to the low-res RT ? Thanks
     
  48. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    You have to manually create the copy of the screen contents via command buffers. I.e like this

    Code (CSharp):
    1. copyBuf = new CommandBuffer();
    2. copyBuf.name = "Copy screen";
    3. copyBuf.Blit(BuiltinRenderTextureType.CurrentActive, upscaledRT);
    4. m_Camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, copyBuf);
    RT doesnt have to be upscaled, i just use the upscaled one.
     
  49. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Last edited: Oct 11, 2018
  50. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
Thread Status:
Not open for further replies.