Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Pixel Perfect Camera should NOT have bilinear as a filter mode option.

Discussion in '2D' started by exzizt, Aug 3, 2019.

  1. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    upload_2019-8-3_12-30-16.png

    Every time I open up the editor, I have to manually go into this file and modify it to always return Point to ensure that my art actually looks like nice pixel-perfect pixel art. If I don't, it looks like blurry garbage. I don't understand why this is an option to begin with. The whole point of this package is to achieve crisp, pixel-perfect art.

    Please fix this.

    Thanks.
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You can see from the code that the filter mode is set based on the
    m_Internal.useStretchFill
    boolean being true. Why is it true?

    From the blog post about Pixel Perfect 2D:
    https://blogs.unity3d.com/2019/03/1...up-your-unity-project-for-retro-8-bits-games/
     
  3. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
  4. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    We really need the ability to override the use of the bilinear filter mode. I understand why you have it in place but there's no reason to not be able to override it. For my game, I do not want it.
     
  5. Skelly1983

    Skelly1983

    Joined:
    Mar 9, 2017
    Posts:
    17
    Using stretch fill causes the render texture to be stretched to fill the desired resolution, which needs to calculate the required size of the sprites and resize them. Doing this with point filter would be inaccurate as bilinear uses an average to calculate this size.

    If this is not desired disable "Stretch Fill". Could you post some screenshots of your camera view and Pixel Perfect Camera component so we can possibly advise you of your best options.
     
  6. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    The problem is I still require the ability to use Stretch Fill and have the filter mode set to Point. Otherwise, I have to manually edit the script every time I open up the editor and before I build.
     
    antti_partagames likes this.
  7. antti_partagames

    antti_partagames

    Joined:
    Nov 5, 2015
    Posts:
    18
    This feature would be welcomed. I can get it working by editing PixelPerfectCamera.cs myself, but obviously that's not a permanent solution.
     
  8. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    But the issue with doing that is you have to change it every time you open Unity!
     
  9. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I can't believe this isn't permanent any more, and I can't believe it hasn't been added as a toggle. Can I just read-only the file or something?
     
  10. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Like we mentioned in the blogpost, if we stretch an already pixel-perfect image to an arbitrary screen size using point sampling, the pixel-perfectness will be lost, which defeats the whole purpose of the Pixel Perfect Camera.

    I understand that might be tolerable for some use cases, but if you can accept a not-pixel-perfect image (meaning you might get swimming pixels if the camera moves), what is the motivation of using Pixel Perfect Camera in the first place? Are there any 'hidden' benefits you can get from using this component?
     
    KalOBrien likes this.
  11. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Well, the camera is useful for more than just absolute perfectness, it calculates everything properly and is the easiest way of making a pixel-perfectly positioned rendertexture. If it's still not being planned after all this time and numerous requests for it, I'll just fork the folder, remove it from package manager and hack the single line in myself.
     
    NotaNaN and Lars-Steenhoff like this.
  12. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Oh, and also, I don't get "swimming pixels" since I work out exactly which resolution will upscale to integers on a 16:9 1920x1080 screen (really doesn't matter to me on a screen that isn't 16:9 or 1920x1080).

    I think almost anybody making a pixel-art game would rather have swimming pixels and not-so-pixelness to an unbelievably bad bilinear smoothed mess. Seriously, it looks like when you don't upscale old games in Dosbox and it hits your monitor at the original non-native resolution, nobody in the world wants this.

    Of course, you could try to implement the type of bilinear that first upscales to as close as possible by integers, then bilinear smooths the remainder (Sonic Mania does this, Shovel Knight, etc). This has also been mentioned before in great detail (over a year ago on the last thread) but you also don't seem to like that, so I'll just have to change that one line to make a practically useless camera tool into an excellent camera tool.
     
    Last edited: Apr 15, 2020
    NotaNaN and Lars-Steenhoff like this.
  13. JathamTheGreat

    JathamTheGreat

    Joined:
    Apr 15, 2018
    Posts:
    4
    First off that's not an excuse to add an option, non whole number pixel sizes don't "defeat the purpose" of anything. Besides there's already the option to not use upscaled render textures which looks like a slightly scaled down then scaled up version of a normal camera.

    Strectch No Upscale RT.png

    Normal.png

    Even if it is flimsy, it's not even a valid excuse because pixel perfectness isn't even lost, the only difference is whether or not the implied pixels are whole number multiples of the real pixels or not. When emulating older hardware it's preferable that there be no filters by default so you can have a more accurate representation of how they would display on digital displays.

    You can see that even though the implied pixels aren't whole number multiples of the real pixels of my display, it doesn't interfere with the readability of what's being shown.

    Upscale RT No Stretch.png

    Upscale RT + Stretch (B).png

    Upscale RT + Stretch (P).png

    By forcing people to only use bilinear filtering when using stretch fill, your limiting the usability of your tool. It doesn't matter if you personally find it unappealing some people may find a use for it, especially when there's no other way to get that result except by using the pixel perfect camera.

    It took me an hour to figure out why things were being filtered when I used the stretch fill and took me 10 minutes to fix it for myself. It's not difficult and it has a use, the least you can do is just add it
     
    exzizt and Lars-Steenhoff like this.
  14. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    I couldn't agree MORE! What was your solution?
     
  15. JathamTheGreat

    JathamTheGreat

    Joined:
    Apr 15, 2018
    Posts:
    4
    I just copied the folder where the package was saved, changed the PixelPerfectCamera.cs of the copy to my liking, then removed the package then imported my copy
     
    Zebbi likes this.
  16. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    This seems to be the accepted practice for this abandoned(?) package.
     
  17. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thank you all for articulating your rationales behind this. I understand now trading absolute pixel-perfectness for an overall sharper image is oftentimes a valid use case.

    Here's what I'm gonna do:

    - Add an option to disable filtering when Stretch Fill is enabled. This option will be off by default.
    - If you do prefer bilinear filtering when stretching, we'll fix the excessively blurry image when Upscale Render Texture is also used by first upscaling to the closest pixel perfect resolution before stretching to fill the entire screen.
     
    Radivarig, diesoftgames and Zebbi like this.
  18. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Awesome! That second option should be very close to how Sonic Mania (and I think Sonic CD) does it, which makes for a very crisp image, but still smooths out any integer jankiness. I will still keep it totally off by default, but this would allow me to add a pixel-friendly smoothing setting for users that won't blow everything out into a billinear smear.
     
  19. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Sorry to tag along with this, but 2dlight buffer filtermode and shadow (and normal, mask) should also be able to set as point sampling and able to match the screen buffer resolution as well. Right now the light buffer is just set to be screen resolution multiplied by resolution value and all bilinear filtering. We need option to be able select filter mode and match the pixel perfectness set by the pixel perfect camea component.
     
  20. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I just wanted to chime in that this all sounds great, thank you! I'm especially interested in that first point, since not everyone will be on resolutions that can be targeted with perfect integer scales of the reference resolution, being able to offer those players the option of black borders, or stretched with filtering, or stretched with no filtering sounds ideal.
     
  21. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    So I see that some progress is being made for this issue. Do any of us know when this functionality will be available for us?
     
  22. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    No idea, PPC updates take an eternity.

    Any ideas when the update will be available?
     
  23. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Change the PixelPerfectCamera.cs script in
    C:\Users\[username]\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.2d.pixel-perfect@3.0.2\Runtime
    and it will be persistent.
     
    adscomics likes this.
  24. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    You're the man, Zebbi ;)
     
    Zebbi likes this.
  25. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    For any newcomers to this thread:

    Find
    PixelPerfectCamera.cs
    in
    C:\Users\[username]\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.2d.pixel-perfect@3.0.2\Runtime


    Code (CSharp):
    1. activeRT.filterMode = m_Internal.useStretchFill ? FilterMode.Bilinear : FilterMode.Point;
    Change to:
    Code (CSharp):
    1. activeRT.filterMode = m_Internal.useStretchFill ? FilterMode.Point : FilterMode.Point;
     
    nekolyst, EricR971 and adscomics like this.
  26. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    Also for macOS users, you wanna go to
    /Users/[username]/Library/Unity/cache/packages/packages.unity.com/com.unity.2d.pixel-perfect@1.0.1-preview/Runtime
    to find PixelPerfectCamera.cs
     
    Zebbi likes this.
  27. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    NotaNaN and EricR971 like this.
  28. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'll try to do it in the coming weeks.
     
    mudloop and NotaNaN like this.
  29. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    Hai, @yuanxing_cai!

    Any news on when these features might land? :D
     
  30. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    NotaNaN likes this.
  31. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    rypl and NotaNaN like this.
  32. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Last edited: Dec 30, 2020
    NotaNaN likes this.
  33. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    It could be in version 4.0. I haven't used that version though because my game is in Unity 2019.
     
    Zebbi likes this.
  34. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I have no idea, I'm still using the package manager version that's STILL not updated. Still using this one weird trick:

     
  35. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Happy *bump* day.
     
    MousePods, adscomics and NotaNaN like this.
  36. RedHillbilly

    RedHillbilly

    Joined:
    Mar 24, 2014
    Posts:
    39
    Any update on this?
    I've copied the package a long time ago exactly for this issue, but it breaks every so often because other packages work differently (universal render pipeline for instance).

    Btw, a little bit simpler (you don't need the if):
    Code (CSharp):
    1. activeRT.filterMode = FilterMode.Point;
    And if anybody is looking to fix this with the urp, change this:
    Code (CSharp):
    1. internal FilterMode finalBlitFilterMode
    2. {
    3.      get
    4.      {
    5.          if (!isRunning)
    6.              return FilterMode.Bilinear;
    7.          else
    8.              return m_Internal.useStretchFill ? FilterMode.Bilinear : FilterMode.Point;
    9.      }
    10. }
    to this:
    Code (CSharp):
    1. internal FilterMode finalBlitFilterMode => FilterMode.Point;
     
    Zebbi, NotaNaN and Lars-Steenhoff like this.
  37. jgarbeidi

    jgarbeidi

    Joined:
    Apr 2, 2014
    Posts:
    3
    I'm confused, I got the other thing to work, but I'm also using URP. Where does this code fit into it all?
     
  38. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    I suspect that the reason this hasn't been addressed yet may simply be that @yuanxing_cai no longer works at Unity. @Chris_Chu , can you review this simple feature request?

    The code is known (more or less), and yuanxing_cai offered an ideal, non-breaking solution in this reply. Thanks!
     
  39. sonolil

    sonolil

    Joined:
    Mar 15, 2015
    Posts:
    14
    @Chris_Chu Hellooo~~~ this thread would've been hilarious to me if I wasn't in on this wagon~~ It's kind of important? Otherwise I'm just gonna write my own ppu cam because fixing source code just ain't scalable~~

    -----------

    You know what on second thought, I'll just abandon the package and edit the source code and put it in my github with the rest of my collections... seems to be the way
     
  40. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    Supposedly this fix was shipped in 2022.X. I'm on 2021 LTS so I can't confirm. Using my own hacked solution until 2022 LTS comes out.
     
    sonolil likes this.
  41. sonolil

    sonolil

    Joined:
    Mar 15, 2015
    Posts:
    14
    Oh goodie.. yeah I'm still using 2021.3.16f1 myself. Thanks for the heads up
     
  42. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Adding @kennyy_ to the thread as he is overseeing this at the moment.
     
  43. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi, we have added filter options Point and Retro AA when using Stretch Fill. Unity defaults to Retro AA where we upscale to the closest multiple of the target resolution before bilinearly upscaling to maintain pixel perfectness.

    We have also added the Point filter mode for users who don't want the blurriness introduced due to upscaling. Do note if you are using this filter mode, you may lose pixel perfect accuracy on target resolutions that a not a multiple of the reference resolution.

    This is available in 2022.1.0f1 (or later) and URP 13.1.18 using URP Pixel Perfect Camera. This is not available in the 2D Pixel Perfect package as it is in maintenance mode and we will not be introducing new features.

     
    MelvMay, NotaNaN and karliss_coldwild like this.
  44. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    FYI, the documentation doesn't reflect this. It only shows Filter Mode in the docs for URP 15.0+, which tricked me at first because the option only shows up conditionally when you select
    CropMode.StretchFill
    .
     
  45. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    @NobleRobot Sorry for the confusion, and thanks for pointing that out. Will backport the documentation to reflect this.
     
    NobleRobot likes this.
  46. BluishGreenPro

    BluishGreenPro

    Joined:
    May 14, 2017
    Posts:
    8
    If anyone is working in Unity 2021.x, AND is using URP, go here to make the change to make the change instead;

    C:\Program Files\Unity\Hub\Editor\2021.3.29f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.render-pipelines.universal\Runtime\2D