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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    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. TomatoesNeverLie

    TomatoesNeverLie

    Joined:
    Nov 10, 2018
    Posts:
    1
    Sorry to be a bother but I'm having a bit of trouble interfacing with this great package. I'm looking for the equivalent of OnRenderImage for a pixel perfect camera with upscale render texture enabled. That's to say a place where I can run a shader on the low-rez texture, and not the full resolution version in OnRenderImage. Any help would be appreciated. Thanks!
     
  2. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    You can resolve the banding issue by enabling 32-Bit Display Buffers in the Player Settings.

    Good luck getting any help on these forums!
     
  3. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    Since upgrading to Unity 2018.3.x, I can never launch my game first time round in the editor without getting error messages:

    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)

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

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

    If I then stop, and play again, the errors are gone and all works fine, as before.
    It happens every time, in every project, the first time I press play after loading Unity.
    Any ideas?
     
  4. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I think this package is abandoned?
     
  5. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Arbitrary zooming is the first thing we would do when we get our hands on Pixel Perfect Camera again. For now, if you are willing to modify the scripts yourself, you can try multiplying the calculated ortho size with an arbitrary 'zoom level' in PixelPerfectCameraInternal.cs, after line 166:
    Code (CSharp):
    1. orthoSize *= zoomLevel;
    You can then achieve zooming by animating the zoomLevel variable, and when you're done, reset it to 1.0f.
     
    Lars-Steenhoff likes this.
  6. HOvadia

    HOvadia

    Joined:
    Dec 25, 2014
    Posts:
    2
  7. Sly88

    Sly88

    Joined:
    Feb 22, 2016
    Posts:
    73
    I don't know if it is a good place but I will try :)

    I have some problem with the outline effect on my UI elements.
    The outline looks good only on base ratio. When I change screen resolution the outline looks weird, the outline has different sizes on edges( I attached screens).

    I use Filter Point on my assets because it is pixel art.
    Maybe you had a similar problem and you know how to fix it.
     

    Attached Files:

  8. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hi! Manually tweaking the camera's ortho size won't work as Pixel Perfect Camera is also changing that value. Please refer to my previous post on this page and see if that workaround works for you.
     
  9. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,599
    I wanted to say that I'm excited about this package! I had several Game Maker Studio projects with faux-NES-style, low-res pixel graphics. Once Unity rolled-out their new tile map editor, I decided to try and port these projects to Unity, but could never figure out how to get the look just right and still get the smooth scrolling that I could get in GMS. This package finally solves this problem for me.

    I have one slight problem, though- My Vsync is at 60 frames per second and as long as my camera moves at a rate where the pixels per second divides evenly into the frames per second then my scrolling is buttery-smooth (aside from some random rendering spikes that I'll worry about later). 1 pixel per frame is great, but 1 pixel per 2 frames looks very nice also. If the pixels per second doesn't divide evenly, I get scrolling that is slightly jittery. It's not terrible but its not as nice.

    This is only a concern for me because some people have different monitor refresh rates. If I tune everything so that it's smooth for me, than it might not look good for others. Obviously I can include the option to check Screen.currentResolution.refreshRate and change the camera speed accordingly, but moving, for example, 72 frames per second vs 60 is different enough to change the feel of the game-play. Is there a common solution for this problem, or is it one of those great, unsolvable limitations of the universe? To be clear, I had the exact same problem in GMS but have never addressed it.
     
  10. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    Anyone else noticing bad jitters on the Z axis with this package's pixel snap enabled? Is it only XY compatible?

    (Attaching main cam to a character controller and moving it around at all speeds I'm noticing this, Never jitters on the XY oddly enough)
     
  11. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    These two APIs rely on the viewport size to give you the correct result. Depending on your settings, Pixel Perfect Camera may alter the VP size. So you have to make sure to only call ViewportToWorldPoint / ScreenToWorldPoint after Pixel Perfect Camera has applied the modification to camera VP size. Calling them in the Update() callback of your MonoBehaviour should be fine after the first frame.
     
  12. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Are you moving your character in 3D space instead of on a 2D camera-facing plane? The Pixel Perfect Camera is not designed for 3D view or perspective camera.
     
  13. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    I was attempting to use the XZ axis for a top-down game (orthographic camera), but I'll just use XY instead as it seems more compatible. Thanks!
     
  14. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Pixel Perfect Camera shouldn't treat any of the planes differently. If it does, send us a bug report!
     
  15. Kingblade

    Kingblade

    Joined:
    Jan 15, 2014
    Posts:
    16
    So as I'm having lot's of problems without it, I've installed the pixel perfect camera package yesterday.
    It seems to work pretty great, but it has problems working in synergy with cinemachine.

    Once setting up the pixel perfect camera with a confiner on the virtual machine, it confines the wrong area.
    I've tried messing around with different settings to everything, but it keeps happening (and if I turn pixel perfect camera off, it just snaps to the right confinement).

    Also, I wish it would be able to sync with different virtual cameras all set to a different resolution (basically, to zoom in and out using cinemachine virtual camera's transitions).
     
  16. startselect_

    startselect_

    Joined:
    May 2, 2015
    Posts:
    4
    When I try the pixelperfect camera package my z-depth sorting goes out the window.

    Left: pixelperfectcamera disabled, Right: pixelperfectcamera enabled

    I've looked around in the package but I can't find any way to increase the depth buffer bitrate (which ofc is just a guess at what's going on)
     
    foxnne likes this.
  17. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Is this still in development?
     
  18. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    We know currently Pixel Perfect Camera has some issues working with Cinemachine due to the two systems trying the modify the same camera properties at the same time. We'll be working with CM team to find a viable solution to these issues.
     
  19. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Can you please send us a repro project? It's hard to tell what's going on without an example.
     
  20. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Yes it is. We also have a plan to bring pixel perfect rendering to LWRP.
     
    Lars-Steenhoff and Zebbi like this.
  21. startselect_

    startselect_

    Joined:
    May 2, 2015
    Posts:
    4
    Sure, where do I send it?
     
  22. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Will the viewport stretch bug be fixed in the next update?
     
  23. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    You can either attach it directly here in this thread, or give me a Dropbox / GoogleDrive link, or drop an email to yuanxing_at_unity3d.com

    I don't have a nice solution to the raycasting issue you had, if that's what you're referring to. Maybe you can take it to the UI forum and see if other people there have encountered similar problems.
     
    Last edited: Mar 5, 2019
  24. startselect_

    startselect_

    Joined:
    May 2, 2015
    Posts:
    4
    yuanxing_cai likes this.
  25. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    This description sounds interesting, but the two animated gifs don't look different to me. IMO, they're crisp in both and the only difference is the characters are larger in one. I don't have an eye for these things. Can someone point out how the pixel perfect gif differs from the normal one?
     
  26. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I did extensively, and I had a few answers:

    `Unfortunately it seems like event raycasts are also checked against some kind of unscaled camera viewport which ends up not allowing clicking/hovering things that would have been over the edge of the screen pre-scaling.`

    When the viewport is scaled using a stretch/shrink in the way I was doing, the raycasting stays the same as it was, so any on-screen clicks are offset and don't match where they're new position should be. Could this be solved?
     
  27. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thanks for sharing the project! I'll take a look soon.

    The gifs are highly compressed, which makes it hard to tell the difference. However if you look closely at the zombie character's hands, you'll see that without pixel perfect camera, the fingers appear to be changing sizes every other frame, while in the picture above, they stay in constant pixel sizes.
     
  28. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    According to the test project you posted, there's a 0.01 difference between your sprites in the z value. This might be enough to stop z-fighting for the regular camera, but Pixel Perfect Camera would internally snap the positions (including z) of the sprites to a pixel grid, whose spacing is determined by your PPU setting. The 0.01 difference is not big enough for the sprites to be snapped to different grid cells, so they would end up with the same z values when sent to the GPU for rendering.

    The easiest solution is to increase the z value difference. Setting it to 0.1 in the test scene solved the problem. Also, I don't know if there's a strong reason you must use a shader that writes depth, if not you can might want to use sorting layer order/ sorting group to handle the sorting.
     
  29. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thanks for reporting the bug! This will be fixed in the next version.
     
  30. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Did you find a solution to the non-square pixels breaking mouse click positions bug with viewport?
     
  31. Stevepunk

    Stevepunk

    Joined:
    Oct 20, 2013
    Posts:
    205
    customphase likes this.
  32. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I think this is better implemented as a post processing effect, rather than part of the Pixel Perfect Camera. That being said, we'll fix the excessive blurriness when combining Upscale Render Texture with Stretch Fill, probably by using double blitting.
     
  33. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    350
    Hi @yuanxing_cai ,

    Component is great! I really waiting it to work with Cinemamachine!

    While I'm want to use "2D Pixel Perfect", I cannot figure out how to move view port on screen.
    As cropping and orto-size are tight together, I cannot change it independently. And it constantly overwritten by component.

    How I can override cropping to set correct view port center?
    Like this: m_Camera.pixelRect = new Rect(center, size);
    not like this: m_Camera.pixelRect = m_Internal.pixelRect;
     
  34. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Currently you have no control over the viewport or orthographic size when you use Pixel Perfect Camera. Can you help us better understand your use case by telling us why you want to change the camera's viewport?
     
    Last edited: Apr 17, 2019
  35. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    350
    @yuanxing_cai ,Yes)

    As you see m_Camera.pixelRect has not only size but also center. So my code looks like
    Code (CSharp):
    1.  
    2.         var PPUScale = Math.Max(refPPUScale, 1);
    3.         var size = new Vector2(PPUScale * viewWidth, PPUScale * viewHeight);
    4.         var center = new Vector2((Screen.width - size.x+PPUScale*viewOffset.x)/2f, (Screen.height-size.y+PPUScale*viewOffset.y)/2f);
    5.         Debug.Log($"Screen {Screen.width}x{Screen.height}");
    6.         Debug.Log($"View {size}");
    7.         camera.pixelRect = new Rect(center, size);

    It is very helpful, as you cannot have pixel perfect game without backbars. Player should not benefit form greater resolution or wider screen.

    The scenarios:
    1) I use UI "screen space overlay" so can fill those gaps with stats and player portrait. To do that I need to shift viewport to the left of the screen.
    2) Piloting in cabin. It takes a lot space at the bottom, viewport should be moved up.
    3) If you use retro portable game console as decoration for a game, screen should be moved to the top.
    4) Two player mode with split screen. (It is done by viewports)
    5) Animation that running cropping. (world shrinks towards player, player is not in center)
    6) I can put buttons for mobile gaming at the bottom, by moving viewport to the top.
    7) For sake of OOP, I want to have options to override.
     
    Last edited: Apr 17, 2019
    Lars-Steenhoff likes this.
  36. Eingya

    Eingya

    Joined:
    Jan 10, 2014
    Posts:
    8
    How do I handle UI with this package?
     
  37. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    350
  38. sanbox

    sanbox

    Joined:
    Oct 22, 2018
    Posts:
    5
    Hiya! Any updates on porting it to the LWRP (or any of the new RPs)?

    For anyone who's coming here looking for a solution -- if you can guarentee that you'll always be pixel perfect, you can just overwrite the file and call PreCull on LateUpdate in the pixel perfect class -- they provided it to us in C#, not in assembly, so editing it is no problem (thanks Unity!).

    If you're using the LWRP and you need pixel perfect, I'd say probably look into rolling your own based on their example, or figure out if the callbacks the SRPs are supposed to provide are working for you. It gets harry fast if you do anything complicated, but then the ball's in your court anyway, which is nice.
     
  39. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    243
    Im not on the dev team, but there is no point in porting it to SRPs. All of the features of LWRP/HDRP are focused around 3D, you just dont get any benefits out of them with 2D, especially pixel art 2D.
     
  40. sanbox

    sanbox

    Joined:
    Oct 22, 2018
    Posts:
    5
    I wrote a rim light shader for 2D pixel art graphics using Shader Graph, and additionally created further shaders for occluded materials using Shader Graph and a custom forward renderer, all of which would not be possible without the LWRP.

    Thanks for chiming in though @customphase !
     
  41. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    245
    Edited it since I found info in one of the PR on Github that does show it will be used in Pixel Perfect camera.


    This is actually wrong. Not sure how far the news has reached, but I guess I should share here so people can get happy and excited. Before I say this like you I am not on a dev team, but just someone who likes to poke around in unity github repos for cool features not released yet. I haven't fully looked through the pull requests so don't know what is in each one fully.

    There is a 2D SRP system being worked on and will be released in experimental hopefully before end of 2019.2. Keyword experimental I doubt it will be a full release. In the first repo link I posted below if you look under the purpose of the pr. The third bullet point mentions adding two parameters. The two parameters in the PR says specifically used by pixel perfect camera, so yeah guessing that pr is going to have stuff for the pixel perfect camera.

    These PRs are used for the SRP system and Shader Graph system. To add onto to it this PR mentions in the first bullet added two SG (Shader Graph) nodes for Sprite unlit and Sprite lit. So I am assuming we might get some system with shader graph that people could shove custom data into a pixel perfect camera down the line. Again would need a Unity official to say if I am wrong or right. If anyone from Unity can confirm this is correct info be happy to hear it. If this is wrong info and someone might have better data just tell me so I can edit the post with the updated info.


    Here is the first repo for 2d features.
    https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/3482

    Here is another 2D repo with the new 2D light system and possible future shadow system with sprites. Not too sure about the shadow.

    https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/3517
     
    Last edited: May 8, 2019
    customphase likes this.
  42. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    245
    Sorry for double posting and mentioning you since you are probably pretty busy with the 2D SRP systems. , but @yuanxing_cai for others and myself can you give us any idea if the above post I made has any merit to it or should I edit it for more correct information that way people don' get the wrong idea.
     
  43. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    That was some quite insightful analysis! And you got it completely right. We'll ship an experimental 2D renderer within LWRP for 2019.2, which includes support for pixel perfect camera, shader graph, and 2D lighting. We're busy with some finishing touches at the moment, stay tuned and we'll have an official announcement real soon.
     
    Last edited: May 13, 2019
    SugoiDev likes this.
  44. GuroMan

    GuroMan

    Joined:
    Apr 7, 2016
    Posts:
    2

    After installing the package, the package manager stops working.


    Errors occur in the console:


    There are also errors in the "Build Settings" project. After "Build Settings" the project constantly breaks the scripts in the scene.

    What am I doing wrong? Т_Т
     
  45. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    It's probably because the sample project uses a version of Package Manager that's no longer compatible with your Unity version (2018.3.9f1). What you could try is to uncheck manifest.json when you import the sample project, and then install the Pixel Perfect package manually via the Package Manager.
     
  46. GuroMan

    GuroMan

    Joined:
    Apr 7, 2016
    Posts:
    2
    Thanks for the answer. I recently began to learn the Unity. Here was my mistake. Now I updated the Unity to the latest version and it all worked.
     
  47. wu-qing

    wu-qing

    Joined:
    Mar 22, 2019
    Posts:
    1
    how to fix this problem?
    problem1.png problem2.png
     
  48. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    245
    Hey everyone, wanted to share something important about the pixel perfect camera. The 2D SRP has been officially released in preview. Here is the unity forum. It has the Pixel Perfect camera in it and has two bullet points you guys might want to read regarding the Pixel Perfect Camera.

    https://forum.unity.com/threads/experimental-2d-renderer-in-lwrp.683623/
     
    yuanxing_cai and Lars-Steenhoff like this.
  49. henryeverett

    henryeverett

    Joined:
    Jun 18, 2017
    Posts:
    3
    I'm having an issue where the game view is blurry when using Upscale Render Texture combined with post processing effects on the camera. Is this a bug? Is there a way around it?
     
  50. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Maybe its the same bug I reported here? https://github.com/Unity-Technologies/2d-pixel-perfect/issues/5
    Now that they've integrated the camera into the new experimental 2D Render Pipeline, it's probably not getting fixed, sadly.
     
Thread Status:
Not open for further replies.