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. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
  2. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    245
    I would, but the problem is that the whole thing is terribly hacked together atm. I made a complete copy of both PixelPerfectCamera and PixelPerfectCameraInternal classes, to have full access to the pipeline and experiment with it, and make changes directly inside of them. But i think it can be done nondestructively, without changing existing classes. I need to look into it some time later.
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,223
    How do I get pixel perfect textmesh pro?
     
  4. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Sorry again for not being able to reply timely. If you don't mind sending over a sample scene of your project, I can help you look further into the issue you had. This will also help us better understand the request for non-square pixel ratio, if we decide to officially support that.
     
    Lars-Steenhoff likes this.
  5. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Sure thing, I'll PM it. Do you have an example of using a non-square pixel ratio with PPC? I'd love to know if you've managed to implement it in the script successfully.
     
  6. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I don't. That's why I'm asking for a sample scene from you in the first place :)
     
  7. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'll see if I can come up with a shader that does some tricks to reduce the blurriness, otherwise this is the way to go.
     
    customphase likes this.
  8. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Here is a basic scene with PPC and the currently broken aspect stretch script on the camera: https://www.dropbox.com/s/opyp84ecu72eclu/exampleforcamera.zip - you'll see a familiar image in the scene, and all I need to do is stretch the camera viewport height by 20% to make it appear correctly (as it does in ScummVM with aspect ratio mode on). Ignore the pillarbox for now, the image is aligned correctly centrally and at the top, the pixels just need stretching vertically by 1.2.
     
  9. tomzigza

    tomzigza

    Joined:
    Aug 4, 2017
    Posts:
    31
    I don't know if somebody already mentioned this, but there is a warning when you have an odd numbered height screen that it won't work correctly. Sadly on mobile this is a thing(iphone X for example). Any thoughts on this? Could there be some way to just not use the last row of pixels or something sneaky like that?
     
  10. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Let me know if you manage to get around to looking at this, thanks!
     
  11. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thanks! I'll take a look at it as soon as I get some time.
     
  12. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Did you actually find any visible artifacts on a iPhone X screen? The high DPI retina screen could make the artifacts caused by odd-numbered resolution hard to spot with the naked eye.

    Not using a row or column of pixels should be possible by tweaking the viewport rect.
     
  13. mohnfeldmedia

    mohnfeldmedia

    Joined:
    May 30, 2017
    Posts:
    2
    The pixel perfect package is working great for us. Thanks!

    I have a question, though. How do I get/calculate the cameras world space extends?

    The usual way, ie
    Code (CSharp):
    1. vertExtent = Camera.main.GetComponent<Camera>().orthographicSize;
    2. horzExtent = vertExtent * Screen.width / Screen.height;
    does not seem to yield correct results.
     
  14. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    What settings are you using for your Pixel Perfect Camera component?
     
  15. abczac123

    abczac123

    Joined:
    Mar 24, 2018
    Posts:
    2
    I've had the pixel perfect camera in my game for a while now and it's working great, nice work!

    I see there was some discussion on pixel perfect particle systems. Is there any word if this is going to be supported? It would be super cool to have this also.
     
  16. mohnfeldmedia

    mohnfeldmedia

    Joined:
    May 30, 2017
    Posts:
    2
    I have ppu at 100 and a reference res of 400x180. No upscale, pixel snapping or cropping.
     
  17. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Sure thing.
     
  18. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    I've created a thread for this in the 2D section already, but maybe this is a better place for it:

    I've been using the "2D Pixel Perfect 1.0.1-preview" package and it's working like a charm. But this
    week I started using the "Shader Graph 3.0.0-preview" package, this package required that I created a render pipeline asset, I chose a "lightweight pipeline asset". Creating shaders is working fine and shader graph really blew my mind!!! But now my pixel perfect camera is broken. It no longer shows pixel perfect graphics and the button on the camera, "Run In Edit Mode" no longer works either.
    Is there anyone who has experienced this before? Maybe the devs of either package know what causes this?
     
  19. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    Hmm, I hoped that at least the devs would know the answer to this one, back to the drawingboard I guess.
     
  20. ezonecom

    ezonecom

    Joined:
    Jul 23, 2013
    Posts:
    17
  21. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    What about games that use pixel perfect elements mixed with 3d elements, will these work with the custom 2d pipeline?
    ( perspective camera layered with orthographic )
     
  22. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
  23. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I've tried it in update and it still just does a weird squashing the screen into a slither until it disappears into black. I've also tried negative values and it kind squashes the viewport down until it becomes black. Do you have any suggestions as to how I can just stretch the final upscaled image on screen vertically?
     
  24. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    @yuanxing_cai here's another example:


    As usual, this is 4:3, so it's a bad example, but you can see how shrinking the viewport after it has been upscaled allows for rectangular pixels. Now, I'm trying to do this for a 16:9 that has rectangular pixels, and I don't want pillarboxing, so shrinking the viewport won't be an option. So we need to start with:
    • A 320x180 (16:9) pre-scaled viewport area.
    • Scaled by 6x for 1920x1080, which is the most popular resolution so we'll imagine that's generally what it'll be.
    • Then we need to stretch it post-scale so each pixel is 1:1.2, or 5:6.
    • So we need to resize the height from 180*6 to 216*6.
    • As long as the stretching occurs after it has been upscaled , it will appear okay.
    Since shrinking the viewport width would result in black bars (as the rendertexture can't see any further than it knows), it would probably be best to start with a screen that's designed to have 20% of blank empty at the bottom, so it can be stretched down. So:
    • For 320x180, we'll shave off 20% of the height, which is -36 pre-scaled pixels.
    • Begin with a pre-scaled imaginary viewport of 320x144 (that's 36 blank pre-scaled pixels at the bottom), but PPC will still have a viewport of 320x180.
    • Upscale to 1920x1080, but our imaginary viewport is now 1920x864 (that's 216 upscaled blank pixels at the bottom)
    • Then stretch that image outside of the PPC viewport to a pixel ratio of 1:1.2, or 5:6 so it becomes an imaginary height of 1080 stretch pixels that are 1.2 taller than they are wide
    Here's how it would appear on a screen without 1:1.2 un-scaled or 5:6 scaled pixel aspect ratio (note the 36 unscaled or 216 scaled extra pixels at the bottom):

    The blue section under the screen is the extra blank pixels (36 unscaled, 216 scaled by 6x)

    ScummVM and Dosbox generally have games that are 4:3 going inside a 16:9 screen, so they can afford to simple scale up 6x and shrink the width by 20%, as you saw earlier, but we can't do that as we still want to use the full widescreen ratio, we just want each pixel to be 1.2x taller than it is wide, and this could only be done if PPC could actually overscan into the rendertexture, which I don't believe it can, nor am I sure it should.

    Here is a project with a scene called stretched.unity that shows a pixel-perfect example of what I have shown above, with the extra space all set-up: https://www.dropbox.com/s/yt50yykz0tue6rl/exampleforcamerastretch.zip?dl=0

    If anyone knows how to get the extra space offscreen and the pixel height stretched to 1.2, please be my guest!

    PS: I'm using 384x216 as my 16:9 base resolution for my games, upscaled by 5x to 1920x1080. The principle will still be the same for this, except it requires a 5x upscale for 385x216 to become 1920x1080, just as anyone running 1600x900 monitor would require a 5x upscale for 320x180.

    I would be using:
    • 384x216, we'll shave off 20% of the height, which is -44 pre-scaled pixels.
    • Begin with a pre-scaled imaginary viewport of 384x172 (that's 44 blank pre-scaled pixels at the bottom), but PPC will still have a viewport of 384x216.
    • Upscale by 5 to 1920x1080, but our imaginary viewport is now 1920x908 (that's 172 upscaled blank pixels at the bottom)
    • Then stretch that image outside of the PPC viewport to a pixel ratio of 1:1.2, or 5:6 so it becomes an imaginary height of 1080 stretch pixels that are 1.2 taller than they are wide
    Once it's been upscaled, it still looks fine, and I want to just add that I'm hoping to find a solution to stretch pixels for any base resolution and/or aspect ratio. I merely used 320x180 as a good big pixel-art example!
     
    Last edited: Dec 4, 2018
  25. Lyncks

    Lyncks

    Joined:
    Dec 7, 2018
    Posts:
    9
    Thanks for this package! It's definitely the best/cleanest implementation of this I've seen.

    One issue we've noticed though is that it doesn't work with Lens Flares.

    I managed to get it working by commenting out:

    Code (CSharp):
    1. if (m_Camera.activeTexture != null)
    2. {
    3.     Graphics.SetRenderTarget(null as RenderTexture);
    4.     GL.Viewport(new Rect(0.0f, 0.0f, Screen.width, Screen.height));
    5.     GL.Clear(false, true, Color.black);
    6. }
    7.  
    and adding this in Awake():

    Code (CSharp):
    1. UnityEngine.Rendering.CommandBuffer commandBuffer = new UnityEngine.Rendering.CommandBuffer();
    2. commandBuffer.name = "Clear Black Bars";
    3. commandBuffer.SetRenderTarget(null as RenderTexture);
    4. commandBuffer.SetViewport(new Rect(0.0f, 0.0f, Screen.width, Screen.height));
    5. commandBuffer.ClearRenderTarget(false, true, Color.black);
    6. m_Camera.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterHaloAndLensFlares, commandBuffer);
    But I'm not sure if that's the best way to handle it. Any tips?

    Thanks!
     
  26. Rob-Meade

    Rob-Meade

    Joined:
    Oct 27, 2016
    Posts:
    56
    Hi,

    My apologies if this question has already been asked, but, is this compatible with Cinemachine?

    In a current project I have used tilemap and am suffering from a 1px gap in the background.

    I started with this video:


    From the comments I ended up at this Unity blog:
    https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

    Which was when I spotted the link at the top offering a fix for the issue, which is how I ended up here.

    Reading the blog I did try manually changing the orthographic camera size, it wouldn't remain, I realised I had cinemachine in place which was overriding the setting. Having entered a value which worked and the gaps disappeared all was well, right up until cinemachine performed a zoom in, at which point the orthographic size changed again and all the gaps (lines) appeared in the background again.

    So, with the above package, is this compatible with cinemachine or are they likely to clash?

    Any info would be really appreciated, thanks in advance :)
     
  27. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    We're still evaluating what a pixel perfect particle system really means. Do you have any specific requirements on this?
     
  28. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    OK I don't see anything wrong with your equation. What's your screen resolution / game view resolution when you did the test? And how's result not correct? i.e. expected result vs actual result.
     
  29. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    So the plan about the custom 2D render pipeline has changed a bit. The new approach we're gonna take is, instead of creating a whole new SRP, we are adding a 2D "scriptable renderer" to LWRP. It's still super tailored to do mostly 2D rendering, but it'll use the basic infrastructure of LWRP. We'll make sure Pixel Perfect Camera work fine with this new 2D scriptable renderer.

    Currently Pixel Perfect Camera doesn't work with any SRP.
     
    Lars-Steenhoff likes this.
  30. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    We're doing a full examination of the potential compatibility issues with Cinemachine. One thing is certain - in cases where both components try to modify the same properties on the camera, they WILL clash. What we can do is to figure out who should be given the priority, and warn you properly when these cases happen.
     
  31. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    What's exactly not working?
     
  32. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thanks for the detailed description of your issue! I'm taking a look at it now. Will get back to you as soon as I have a conclusion.
     
    Zebbi likes this.
  33. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    @Zebbi OK. I think I have a solution for you:
    upload_2018-12-10_19-8-35.png
    Instead of using 320 * 180 as the ref resolution, use 320 * 144 instead, so that the 144-pixel tall image would fill the entire internal render texture. Also make sure Crop Frame X/Y and Stretch Fill are checked. Then go to CalculatePostRenderPixelRect() in PixelPerfectCameraInternal.cs, make the following changes:
    Code (CSharp):
    1.  
    2. if (useStretchFill)
    3. {
    4.     // stretch (fit either width or height)
    5.     float screenAspect = (float)screenWidth / screenHeight;
    6.     if (screenAspect > cameraAspect)
    7.     {
    8.         pixelRect.height = screenHeight;
    9.         pixelRect.width = screenHeight * cameraAspect * 0.8f;
    10.         pixelRect.x = (screenWidth - (int)pixelRect.width) / 2;
    11.         pixelRect.y = 0;
    12.     }
    13.     else
    14.     {
    15.         pixelRect.width = screenWidth;
    16.         pixelRect.height = screenWidth / cameraAspect * 1.25f;
    17.         pixelRect.y = (screenHeight - (int)pixelRect.height) / 2;
    18.         pixelRect.x = 0;
    19.     }
    20. }
    21.  
    As its name indicates, CalculatePostRenderPixelRect() calculates the viewport to use when we blit the internal render texture to the screen. By stretching the viewport here (either expand the height by 25% or shrink the width by 20%, depending on if it's currently fitting width or height), you are basically stretching the internal RT and making the pixels not square anymore.

    According to my test, this solution works fine with 16:9 and less wider (e.g. 4:3) screen aspect ratios, but has some issue with ultra wide ratios (probably need to change how we choose the right zoom level in this case, didn't think too much). It also doesn't work if Stretch Fill is not enabled.

    Sorry for the long wait, I know you've been trying desperately to make it work :) I hope this solution helps you. Let me know if you have further questions.
     
    URocks, Lars-Steenhoff and Zebbi like this.
  34. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thank you SO MUCH!! I'm going to play with this right now and play with the pixel ratio (with that setting, I get post-scaled pixels of 6x7 and scummvm is 4x5, so my base pixel size is obviously larger and needs tweaking). I can't thank you enough for helping me with this issue, can these values be used as adjustable parameters in PPC? I'd LOVE to see this incorporated in the next version! Thanks again, REALLY can't tell you how happy I am about this; I'll post if I find anything after some playing around!

    EDIT: For pixel size of:
    • 6x7 use 320x144
    • 5x6 use 384x174 (round up to 174 from 172.8 NOT round down to 172)
    • 4x5 use 462x206 (testing this)
     
    Last edited: Dec 10, 2018
    Lars-Steenhoff likes this.
  35. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    @yuanxing_cai so very close! I just need a little help with figuring the exact matching size, and I'm not sure if it's the script changes or the pixel ratio. Here is a scene from Fate of Atlantis, directly captured using Fraps from ScummVM:

    Link to image: https://i.imgur.com/6uXQKCV.png (1020x1080)

    Here is my attempt at matching the pixel ratio using 462x206:

    Link to image: https://imgur.com/p0tZtAE.png

    However, if I overlay the two, you'll notice the pixel ratio is slightly different as my image is a bit smaller:

    Link to image: https://imgur.com/QmuTx9L.png

    I'm trying to basically make it so each pixel appears exactly as large physically on-screen as they do in ScummVM, including the exact same stretched pixel height; I'm just trying to add a little extra image to the left and right, so it becomes 16:9 instead of 4:3. Is there a reason why using these sizes I can't get the same upscale ratio, or am I using the wrong reference resolution? As far as I'm aware, the actual pixels-per-unit have no effect if both the sprite image and the PPC pixels-per-unit match. I've found 428x200 is giving the closest pixel ratio to ScummVM, and I'm also finding that using a 1.2 instead of 1.25 gets a closer ratio. Here's a project for playing with: https://www.dropbox.com/s/0qypphwcmb4mfsc/exampleforcameraIndy.zip?dl=0

    PS: Why is the height stretch by 1.25 instead of 1.2?
     
    Last edited: Dec 10, 2018
  36. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'm somewhat confused about what exactly you're trying to do here. Are you trying to recreate these classic LucasArts point-and-click games in Unity, and you want the visuals to look precisely the same as they are in ScummVM? Or are you making your own game, but aiming for similar visuals / styles?

    The way ScummVM does the aspect ratio correction, according to this wiki: https://wiki.scummvm.org/index.php/User_Manual/Configuring_ScummVM, is by first scaling the original 320 * 200 image to 320 * 240, then further upscaling to your fullscreen resolution. The first stretching (320 * 200 to 320 * 240) is not pixel perfect, and will result in some visible distortion. If you look closely at the screenshot you took directly from ScummVM, for example around the area near the sign that says "TONIGHT", you'll notice nonuniformly sized pixels.

    The way we stretch the image is different. We stretch the already upscaled image instead of the original one. It's actually the 5x6 "mega pixel" approach described here: https://www.gamasutra.com/blogs/Fel...idescreen_Tips_on_correcting_aspect_ratio.php. Because of this difference, you can't just overlay the two screenshots and expect them to look exactly the same.

    As for the 1.25 ratio, that was to stretch the image in your sample scene from 320 * 144 to 320 * 180, as 144 * 1.25 = 180. If 5 * 6 mega pixel is what you want, then set the original image size as the ref resolution (320 * 200 in the case of Scumm games), and use 1.2 as the height stretching ratio.
     
    Last edited: Dec 10, 2018
    Zebbi likes this.
  37. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'm making my own and aiming as closely as possible, and using ScummVM as a reference so I can get as close a match as possible.

    I've tried in the past to upscale at 1x, and it always resulted in incredibly visible distortion, whereas ScummVM always seemed graceful. I still can't understand why, as from that example you posted, Guybrush looks terrible when stretched pre-upscale.

    In ScummVM this is definately not how he appears, so it seemed logical to use a post-upscale stretch.

    As I posted in the edited post above, I've found that using 428x200 gives a very close pixel match, and using a 1.2 stretch instead it sits pretty much perfectly and looks great. I kinda gave up on the math and just played with the two numbers, screenshotted and overlayed until it looked okay!

    So thanks again for an incredible job, I'll look forward to porting my games over to this awesome new look and really hope it becomes an integrated feature in a future update! Now, to wait on Aseprite for an update that allows custom pixel ratios so I can draw the art in it's intended pixel aspect!

    UI Question: Should I be using different settings if I'm using a UI with in camera space with the new stretching? I'm matching my reference resolution to my camera reference resolution, but it only appears correctly if I use a different size; for instance, my camera reference resolution is 428x200 but the UI looks best if the custom scaler is set to 384x200.
     
    Last edited: Dec 10, 2018
    Lars-Steenhoff likes this.
  38. Lyncks

    Lyncks

    Joined:
    Dec 7, 2018
    Posts:
    9
    The lens flare doesn't render with the script enabled on the camera, and it does render without it.

    Without the Pixel Perfect Camera script:

    flarewithout.jpg

    With the Pixel Perfect Camera script:

    flare.jpg
     
  39. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Here's a really simple example: https://www.dropbox.com/s/ipfjwi1h64wwt08/exampleforcamera2.zip (stretched.scene), I'm not sure how to get the UI to display as pixel-perfect. The script obviously changes the size of the UI, but I'm not certain if the custom canvas scaler should be the same as the reference resolution, or different? I'm also not certain of what size the panel should be, as I can't seem to come up with any size that scales pixel-perfect (with 1.2x height)

    EDIT: I think the custom scaler is stretching the UI out from 428 to 516 (*1.2) and the height from 57 to 70?

    EDIT EDIT: I'm so stupid, use custom scaler and set it to full height match instead of width, then it works awesomely: https://www.dropbox.com/s/iptxh4drputadw1/exampleforcamera3.zip?dl=0
     
    Last edited: Dec 12, 2018
  40. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    @yuanxing_cai Spoke too soon, it messes up the raycasting on the UI :/ Is there a way for raycasting to be taken into account with the extra stretching?
     
    Last edited: Dec 24, 2018
  41. benkropf

    benkropf

    Joined:
    Dec 21, 2017
    Posts:
    1
    Any word on if it's possible to add zooming similar to orthographic size? Or is there a current work around? I'm fine with losing the pixel perfect during zoom.
     
    Lars-Steenhoff likes this.
  42. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    Do you have any idea when the 2D scriptable renderer will be added to the LWRP?
    What I can make up from combining the pixelperfect and LWRP is that the OnPreCull, OnPreRender and OnPostRender functions are not called, are there other callbacks defined in LWRP that can be used instead of these?
     
  43. rdbdog

    rdbdog

    Joined:
    Feb 19, 2015
    Posts:
    4
    Since playing around with this more, my big feature wish would be to change the crop frame color, preferably to clear. I'm making a vertical-screen arcade-style game with a "wallpaper" behind the main game viewport, and having no color covering the screen would be perfect. Naturally I tried editing this in the script, but yeah, protection levels...
     
  44. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Regarding the broken raycasting, here is an example of how the raycasting eventsystem works before the aspect mod:

    and here is how it functions after:

    here's how non-UI elements behave:


    as you can see, it is referring to the position of the raycasts of the scene before it gets adjusted by the aspect ratio mod, it is totally ignoring all pixel-perfect camera adjustments as made by the mod to the viewport.

    it appears to be a scaler issue or a camera issue:


    Here is the example scene above: https://www.dropbox.com/s/rur4glrfjxw76f3/examp.zip?dl=0
    Here's my modified pixel-perfect package:

    my changes are in PixelPerfectCamera.cs make line 189:
    Code (CSharp):
    1. activeRT.filterMode = m_Internal.useStretchFill ? FilterMode.Point : FilterMode.Point;
    in PixelPerfectCameraInternal.cs make lines 156-190:
    Code (CSharp):
    1. internal Rect CalculatePostRenderPixelRect(float cameraAspect, int screenWidth, int screenHeight)
    2.        {
    3.            // This VP is used when the internal temp RT is blitted back to screen.
    4.            Rect pixelRect = new Rect();
    5.  
    6.            if (useStretchFill)
    7.            {
    8.                // stretch (fit either width or height)
    9.                float screenAspect = (float)screenWidth / screenHeight;
    10.                if (screenAspect > cameraAspect)
    11.                {
    12.                    pixelRect.height = screenHeight;
    13.                    pixelRect.width = screenHeight * cameraAspect * 0.8f;
    14.                    pixelRect.x = (screenWidth - (int)pixelRect.width) / 2;
    15.                    pixelRect.y = 0;
    16.                }
    17.                else
    18.                {
    19.                    pixelRect.width = screenWidth;
    20.                    pixelRect.height = screenWidth / cameraAspect * 1.2f;
    21.                    pixelRect.y = (screenHeight - (int)pixelRect.height) / 2;
    22.                    pixelRect.x = 0;
    23.                }
    24.            }
    25.            else
    26.            {
    27.                // center
    28.                pixelRect.height = zoom * offscreenRTHeight;
    29.                pixelRect.width = zoom * offscreenRTWidth;
    30.                pixelRect.x = (screenWidth - (int)pixelRect.width) / 2;
    31.                pixelRect.y = (screenHeight - (int)pixelRect.height) / 2;
    32.            }
    33.  
    34.            return pixelRect;
    35.        }
    If PPC can't be fixed, could it be hacked? By adding
    Code (CSharp):
    1. target.x *= 1.2f;
    to the move-to script in the example, it positions it correctly, so theoretically if the input position was scaled by *1.2, it might work:
     
    Last edited: Dec 25, 2018
  45. Will_ABC

    Will_ABC

    Joined:
    Feb 28, 2018
    Posts:
    1
    Hello, I have an issue, when I attach the script to my main camera I get the error "Assertion failed on expression: 'IsNormalized(normal, 0.001f)'" and my sprites are not shown. I am using Unity vesion 2018.3.0f2 and package version 1.0.1. The size of my orthograpic camera is 162, PPU is 1 on all my sprites and Reference Resolution is set to 576 x 324. (I also selected Upscale Render Texture). Thanks in advance
     
    cjonasw likes this.
  46. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    OK this looks like a real bug. Can you please send us a bug report with Unity Bug Reporter?
     
  47. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,935
    I tried using this in case where user is able to zoom in and out by changing Camera's size property and it didnt work as expected. How should i handle this case where i want camera to remain pixel perfect while im changing the size property?
    Thanks
     
  48. Lowscope

    Lowscope

    Joined:
    Jun 4, 2015
    Posts:
    11
    Hello,

    I'm trying to get the corners of the camera in world space.

    Both 'ViewportToWorldPoint' and 'ScreenToWorldPoint'
    give different results when the PixelPerfectCamera is turned on.

    Could anyone provide advice to solve this issue?
     
  49. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    I'm having very strange behaviour with sprite masks that are caused by the PixelPerfectCamera script on Android devices only (I have only tested the game on PC and Android and it is only being released on Android):
    upload_2019-1-20_15-3-15.png
    As you can see, the sprite mask does not work properly for some reason when stretch fill is disabled.
    What could be the solution to fix this? It is annoying because I have an option in the Options menu to disable stretch fill if the user wants to, as it is a bit of a performance hit (I'm pretty sure) for older phones to have stretch fill enabled.

    Please let me know how to go about fixing this! I will reply as promptly as I can.

    Edit:
    Might as well try and kill two birds with one stone here...
    Another issue I'm experiencing with the camera script on all platforms is when stretch fill is enabled it seems to get rid of the "crisp pixel look" and instead adds an "anti-aliased/bilinear-filtered look" on the graphics, as you can see here:
    upload_2019-1-20_15-11-9.png
    What I want to achieve is the "crisp pixel" look.

    I was able to dive into the code actually achieve this by changing this line of code:
    Code (CSharp):
    1. activeRT.filterMode = m_Internal.useStretchFill ? FilterMode.Bilinear : FilterMode.Point;
    I modified "FilterMode.Bilinear" to "FilterMode.Point", and it worked, however, I noticed it made my phone screen's actual pixels seem to have a weird grid effect and very pronounced. This effect is noticeable in the very first attached image. Any way to solve this?
     
    Last edited: Jan 20, 2019
  50. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Can anyone help me out? Please see my above post...
     
Thread Status:
Not open for further replies.