Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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.
     
    SVC-Games and antti_partagames like this.
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,768
    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:
    8
    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:
    420
    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:
    325
    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?
     
  11. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    420
    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.
     
    Lars-Steenhoff likes this.
  12. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    420
    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
    Lars-Steenhoff likes this.
  13. JathamTheGreat

    JathamTheGreat

    Joined:
    Apr 15, 2018
    Posts:
    3
    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:
    3
    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:
    420
    This seems to be the accepted practice for this abandoned(?) package.
     
  17. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    325
    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.
     
    diesoftgames and Zebbi like this.
  18. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    420
    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:
    1,872
    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:
    69
    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:
    5
    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:
    420
    No idea, PPC updates take an eternity.

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

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    420
    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:
    5
    You're the man, Zebbi ;)
     
    Zebbi likes this.
  25. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    420
    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;
     
    EricR971 and adscomics like this.
  26. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    5
    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:
    420
    EricR971 likes this.
  28. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    325
    I'll try to do it in the coming weeks.
     
unityunity