Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Official Pixel Perfect Preview Package

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

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

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    I am being Spammed with Errors in Console (Unity Ver 2018.3.7f1). The errors are for the following methods:
    PixelPerfectCamera.RoundToPixel
    PixelPerfectCamera.OnPreRender
    PixelPerfectCamera.OnPostRender
    PixelPerfectCamera.OnGUI

    Setup:
    I am using several UI elements and TM Pro elements as I am designing a in game Email browser using UI. In the scene there is noting except UI images and text. PP Camera comp is attached to single main camera.

    When:
    This doesn't happen regularly so it is difficult to pin point the cause of the error. It happens only sometimes but most of the times it works well. The last time it happened when I minimised Unity while in Play mode and after 5 minutes I maximised and the console was being spammed with errors every frame. Below is the screenshot

    Image link: https://imgur.com/j1XMg94

     
  2. JLT93

    JLT93

    Joined:
    Jun 15, 2016
    Posts:
    4
    I may be having the same issue. Everything is fine but when I added text to my map, upscaling destroyed the font.
     

    Attached Files:

  3. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
  4. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Can you screenshot your scene and the settings you used for Pixel Perfect Camera and Post Processing?
     
  5. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'll take a look at the issue you reported. It has easy to follow repro steps. Thanks!

    Also please note we'll continue to support the standalone 2D Pixel Perfect package with bug fixes. It's just new features will only be added to the LWRP version of the Pixel Perfect Camera.
     
    Lars-Steenhoff and SugoiDev like this.
  6. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    It's very likely to the same issue with hot reloading scripts. The LWRP version of the Pixel Perfect Camera should already have this issue fixed.
     
  7. JLT93

    JLT93

    Joined:
    Jun 15, 2016
    Posts:
    4
    I updated to 2019.2 and I started using the LWRP version of Pixel Perfect Camera but I'm unable to get it working with Cinemachine this time. The non-LWRP version works with an Orthographic Override script I found via the project's GitHub page.

    Any pointers on this?
     
  8. Pnvanol

    Pnvanol

    Joined:
    Jan 11, 2016
    Posts:
    94
    I updated to 2019.2 and when I press upscale to render texture and maximize game window. My game will appear on the bottom left and everything else black. Is this a bug?, how can I keep showing pixel perfect?

    This can be solved if I increase the reference resolution, but then my character for example will show up really small. Im looking to achieve something similar to hyperlight drifter resolution
     
    Last edited: Jun 4, 2019
  9. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Can you show me what Orthographic Override script you use for the non-LWRP version?
     
  10. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I need more information on you setup. Which version of the Pixel Perfect Camera are you using? Are you also using any Scriptable Render Pipeline?
     
  11. Dingola

    Dingola

    Joined:
    Jul 11, 2015
    Posts:
    5
    Hello there!

    Is there any update on the zooming feature? The code changed a bit since the solution you mentioned a few pages back, any idea how to implement this in a simple way?

    Thanks for reading.
     
    foxnne likes this.
  12. Pnvanol

    Pnvanol

    Joined:
    Jan 11, 2016
    Posts:
    94
    It was a problem with post-process effect I only moved the script up for the post effect volume in the game oobject menu and it solved the problem
     
  13. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
  14. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    We're evaluating how feasible it is to let Cinemachine handle zooming for Pixel Perfect Camera. I can say it looks promising.
     
    Lars-Steenhoff likes this.
  15. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
  16. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Can someone try to get sprite masks to work when stretch fill is disabled on the pixel perfect camera? It's a bug and I filed a report but they keep ignoring it for months because I won't send in my personal project. o_O
     
  17. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    @yuanxing_cai hey, it seems the Pixel Perfect package is no longer in packages.unity.com. Was it deprecated for good now?
     
  18. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I just tried sprite masks and they seem to work fine with Pixel Perfect Camera. If we can't have your project, can you tell us the detailed reproduce steps for the bug you encountered?
     
  19. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    If you're talking about the Package Manager window, you have to check "Advanced->Show preview packages".
     
  20. qkjosh

    qkjosh

    Joined:
    Nov 29, 2015
    Posts:
    33
    Hi @yuanxing_cai - I've put together a simple package that shows a few issues I've encountered with the pixel perfect camera when the camera is at a subpixel position. In this example, I have PPU set to 100, and the camera animating with a toggle between (0,0) and (0.005, 0.005). To be fair, some of these are just general subpixel position issues, but the ppc performs a lot better on sprites than it does on UI elements. I am mainly interested in improving UI rendering.



    There seem to be two main issues:
    1. Sprites with odd-numbered widths or heights will be distorted. The fix to this seems to be to put sprites on even-sized canvases, and set Mesh Type to Full Rect, since otherwise the mesh could still be odd-sized. Unfortunately this increases overdraw, but I can live with that.
    2. Sprites which run up to the edge of their canvas will be stretched or clipped along those edges. The fix I've used to avoid this is to give sprites a 1px border of transparent canvas space on all edges.
    Putting sprites on an atlas can help, since atlases are always POT textures, but issue #2 can still occur with atlased sprites, and padding doesn't seem to help. These issues also have implications for fonts, because individual character meshes are not guaranteed to be the same size (unless maybe you're using a monospace font). It's not so easy to perform the above fixes on a character-by-character basis, so I'm hoping for some solution to font rendering.

    EDIT: I had a few more thoughts. The UI issues mainly seem to occur when setting the canvas to Screen Space - Camera. By design, when the camera is moved, the canvas position is also moved to follow the camera. So, when a camera is at (0.005, 0.005) for example, the canvas will also end up at a subpixel position. PixelPerfectCamera calls PixelSnap() which in turn uses m_Camera.worldToCameraMatrix to override the camera's rendering position, so that it uses the rounded values instead of the camera's actual transform. I'm assuming this was done to avoid the issues you typically get when directly setting an object's transform (smoothness/jitter). However, the transform is still at a subpixel position, so other things that use the camera's transform will have issues.

    Some solutions might include a) provide a new canvas render mode that behaves like Screen Space - Camera except it uses rounded values or b) set canvas render mode to World Space and update the canvas position manually, using the pixel-rounded camera's transform (in other words, create our own script that does the same thing option a would). Note that in my case at least, Screen Space - Overlay is not an option, since then camera post-processing effects won't be applied to the UI. Would appreciate hearing any thoughts you have on this issue!
     

    Attached Files:

    Last edited: Jul 14, 2019
    Lars-Steenhoff likes this.
  21. Lyncks

    Lyncks

    Joined:
    Dec 7, 2018
    Posts:
    9
    I have another small request if possible.

    It seems like even with the upscaled render texture option there's some amount of pixel "snapping" going on. Due to transform hierarchy and rotations in our game the resulting position can end up being + or - some really tiny delta (like 0.0001 territory) but that's enough to cause the pixel to "snap" back and forward between positions, giving it really bad visual jitter.

    As far as I can tell if you're already rendering at a low resolution and upscaling, the lower resolution rendering should basically have some "built-in" level of pixel rounding which doesn't necessarily require the algorithmic snapping.

    I've commented out this line in PixelPerfectCamera::OnPreRender

    Code (CSharp):
    1. Experimental.U2D.PixelPerfectRendering.pixelSnapSpacing = m_Internal.unitsPerPixel;
    That stops the snap jitter, and doesn't appear to otherwise do much to affect the pixel rendering/quality in our project.

    Is it possible to either have an option to disable the pixel snapping entirely if we're using the upscaled render texture, or potentially a way to add some kind of epsilon to the snapping so that the tiniest transform calculation errors aren't enough to cause a sprite to jump to an entirely different pixel?

    If this has been addressed in the newer 2019.2/LWRP versions then awesome! We're still on the 1.0.1 preview.

    Thanks again for the package though, it's otherwise great. :)
     
  22. Scorr

    Scorr

    Joined:
    Jul 2, 2013
    Posts:
    73
    Is there a way to have the pixel perfect camera be upscaled, while using a seperate camera for UI that is full resolution? Seems right now they both get rendered as low resolution.
     
  23. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hey! We really appreciate the effort you put into this test package! The Pixel Perfect Camera is mainly designed for Sprite Renderers, and we actually had some changes on the native side of the Sprite Renderer to make it work nicely with the Pixel Perfect Camera.

    Although we currently don't have a concrete plan for Pixel Perfect to support Unity UI, we encourage you to continue telling us about your use cases so that we can have a clearer picture about what needs to be done.
     
  24. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    I'd like to just add a +1 to UI support. To get a game looking pixel perfect and nice and sharp, EVERYTHING needs to look uniform. If anything doesn't conform to the resolution it sticks out like a sore thumb, or it just looks 'off' somehow. I would love a solution for UI that's as easy as the regular sprite renderers :)
     
    SugoiDev and Lars-Steenhoff like this.
  25. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    Hey folks, I just started getting this error the first time I hit Play in editor. After that everything works fine.

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.U2D.PixelPerfectCamera.PixelSnap () (at Library/PackageCache/com.unity.2d.pixel-perfect@1.0.1-preview/Runtime/PixelPerfectCamera.cs:111)
    UnityEngine.U2D.PixelPerfectCamera.OnPreCull () (at Library/PackageCache/com.unity.2d.pixel-perfect@1.0.1-preview/Runtime/PixelPerfectCamera.cs:151)


    I'm using the latest version of pixel perfect (1.0.1) and Unity 2019.1.10f1.


    Also... I also noticed that my screen shake behaviour from the Pro Camera 2D plugin has changed even though the values have remained the same -- camera shake seems more violent now. No idea why this has suddenly changed or if it's related to the error above, but I noticed it around the same time as this error appeared. *shrug*
     
    Lars-Steenhoff likes this.
  26. qkjosh

    qkjosh

    Joined:
    Nov 29, 2015
    Posts:
    33
    Thanks for the info! For the record, what I ended up doing is using a world space canvas, and updating the position manually using the camera's pixel-snapped positions.
     
    SugoiDev likes this.
  27. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    The null reference bug has been fixed for package version 2.0.2, which will be available for 2019.3. If you can't wait for that long, here's the patched version of PixelPerfectCameraInternal.cs.
     

    Attached Files:

  28. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    Thanks for the update and the patch @yuanxing_cai ! I tried overwriting the script in my project but unfortunately I still get the error.
     
  29. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    OK then it must be a different issue. What do you mean exactly by "first time hit Play in editor"? First time after you create a new project? First time after you launch Unity? First time after you add a Pixel Perfect Camera component?
     
  30. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    First time I hit Play after I launch Unity. If I stop then play again, no error. If I quit Unity, restart and hit play, I get the error again, first time only.

    It's an existing project from January and Pixel Perfect has been in there pretty much since day 1. Never had this problem until about a week ago... I think around when I upgraded Unity to 2019.1.12 although I'm not 100% certain. I was on 2019.1.10 before that.
     
  31. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    Another thing I've discovered this weekend: Raycast2D gives wildly inaccurate results if you're using Pixel Perfect. It seems like the raycast position is scaled by some value? I can't figure out what.

    I'm using 2019.2 for this project. Found out the hard way half way through the Game Maker's Toolkit game jam that my 2D sniper game is going to be a lot of hard work and debugging :/

    If anyone has a quick solution they can help me out with ASAP I'd be really grateful. Right now I'm totally stumped with about 28 hours to go for the jam.


    Vector2 rayStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    RaycastHit2D hit = Physics2D.Raycast(rayStart, Vector2.zero, 0f, charLayer);

    My raycast attempts all seem to fire in a rect that's about 5 times the size of my actual camera viewport.
     
  32. qkjosh

    qkjosh

    Joined:
    Nov 29, 2015
    Posts:
    33
    Something that would be nice is a toggle to choose whether to display the GUI warnings in editor for invalid resolutions, etc. I'm working on a side project that has a base resolution with an odd height, and every time I open the project I have to comment out lines 234-243 of the main script. I guess Unity stores the package inside Library instead of Assets, and reverts any changes on startup.
     
  33. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Hi,

    Is there a way to use "don't clear" when upscaling the render texture (ie keep it transparent)?

    In my game, I don't want the whole game to be upscaled because I need smoother scrolling (snapped to the screen's pixels, not the pixelart pixels), but I want to upscale certain cameras that render layers with particle effects, to make them the same resolution as the pixel art....

    So basically, I want to use the upscale feature on certain cameras, but when I do that, they hide the cameras behind them.
     
  34. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Are you using the standalone package or the Pixel Perfect Camera that comes with LWRP?
     
  35. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    You can copy all the files of the package into a sub folder named as "com.unity.2d.pixelperfect" under the Packages folder of you project, and make local changes at the new location. They won't get reverted.
     
    qkjosh likes this.
  36. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    For this project I'm using the LWRP one.
     
  37. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    There are similar reports saying the LWRP one has issues with screen space - world space position transformation. I'll look into this.
     
  38. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    190
    Wonderful, thank you @yuanxing_cai ! Please keep us posted with any updates in this thread. I'd love to bring Pixel Perfect back into this project if I can.
     
  39. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    If you don't mind modifying the code a bit, then commenting out the two lines of
    Code (CSharp):
    1. GL.Clear(false, true, Color.black);
    in OnPreRender() and OnPostRender() of PixelPerfectCamera.cs should do what you want.
     
    mudloop likes this.
  40. bloodmaximusvii

    bloodmaximusvii

    Joined:
    Nov 2, 2017
    Posts:
    5
    Hi,

    I've been working with the pixel perfect preview package, and for the most part I'm happy with it.

    Just today, I was exploring putting a minimap in my game. I was roughly following this guide https://blog.theknightsofunity.com/implementing-minimap-unity/ that suggests using a Render Texture.

    It sort of worked, but I got a warning in the console:

    Render to texture is not supported by Pixel Perfect Camera.
    UnityEngine.U2D.PixelPerfectCamera:Awake()


    It seems that the Pixel Perfect camera doesn't support this. I do notice it isn't pixel perfect as the minimap camera moves.

    Are there any suggestions you have right now for doing a pixel perfect minimap?
     
  41. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    The initial reason why we put such restriction on the Pixel Perfect Camera is we can't control what you would do with the render texture. If you don't take care when scaling it or sampling it, the pixel perfectness can be easily destroyed.

    But if you know what you're doing, then it's an unnecessary restriction. There's no technical roadblock for the Pixel Perfect Camera to support render texture. So we recently decided to lift this restriction in the Universal RP version of the Pixel Perfect Camera, and will likely do the same for the standalone package.
     
    Last edited: Aug 26, 2019
    Lars-Steenhoff likes this.
  42. bloodmaximusvii

    bloodmaximusvii

    Joined:
    Nov 2, 2017
    Posts:
    5
    Hi @yuanxing_cai , thanks for the reply.

    When you say the Universal RP version, is that the one in the Lightweight RP package? I could still see that warning in version 6.9.1. Are you talking about an upcoming update?
     
  43. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Yeah it's an upcoming package.
     
  44. bloodmaximusvii

    bloodmaximusvii

    Joined:
    Nov 2, 2017
    Posts:
    5
    @yuanxing_cai would you be able to tell me when it's likely to be available. I'm trying to decide whether or not to include a minimap in my game which is only a few months away from completion.

    Alternatively, is there any code I could use now?
     
  45. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
  46. bloodmaximusvii

    bloodmaximusvii

    Joined:
    Nov 2, 2017
    Posts:
    5
  47. bloodmaximusvii

    bloodmaximusvii

    Joined:
    Nov 2, 2017
    Posts:
    5
    Hey @yuanxing_cai , I thought I would share how it went. I took those changes and applied them to a copy of the old pixel perfect package's camera script, and the result is pretty good. Thanks for your help again.
    before-export.gif after-export.gif
    Before and after ^^^
     
    SugoiDev likes this.
  48. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    This issue (Using 2D Renderer (Experimental) in an LWRP Asset causes UI/mouse events to become inaccurate) has been plaguing our team for weeks. Today I made as minimal of an example project as possible demonstrating the issue. I hope it is fixed swiftly!
    https://fogbugz.unity3d.com/default.asp?1180324_ps8f9sl6ob2ns5r8
     
  49. VPellen

    VPellen

    Joined:
    Mar 15, 2018
    Posts:
    2
  50. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
Thread Status:
Not open for further replies.