Sprite filtering: Point/Bilinear
Asked Answered
P

2

0

I’m currently working on a pixel-art type of game (using Unity 4.3’s new 2D feature), and I would really like the graphics to scale well so I can zoom around and do other crazy camera stuff.

If I set the Filter Mode on my sprite to Point, it scales up very nicely, but loses a lot of fidelity and looks outright broken when it starts to scale down. On the other hand, when I use Bilinear filtering, the sprite scales down nicely, but looks blurry when up close.

Here’s a picture I made to illustrate (please excuse the programmer art):
19709-spritefilter.png

My main question is this: is there any way to cause the sprite to change filter modes depending on how large it appears onscreen? (i.e. point at x2 scale and above, bilinear anywhere below that)

Alternatively, is there a better way to display pixel art?

Patino answered 6/6, 2023 at 2:55 Comment(0)
C
0

You can set a texture’s filter mode programatically.

See: Texture2D.filterMode for an example.

Cerussite answered 6/6, 2023 at 1:29 Comment(1)

That'll work, thanks! Good to know I'm on the right track. I'll accept in a few days if nobody has a more elegant solution.

Patino
A
0

Awaken ancient thread!

There are a number of settings on Texture that can cause them to become oddly pixelated.

For me, not having TextureFormat.RGBA32 was the troublesome one.

Here is some loader code that worked for my situation:

   static public Texture2D LoadTexByPath(string pathedFName) {
    byte[] pngBytes;
    try {
      pngBytes = File.ReadAllBytes(pathedFName);
    } catch(System.Exception e) {
      Debug.LogWarning($"DocsWin.LoadTexByPath: {e.Message}

No {"{pathedFName.Replace(Application.streamingAssetsPath,"")}"}. Using DocImages/Placeholder.png."); pngBytes = File.ReadAllBytes(“{Application.streamingAssetsPath}/DocImages/Placeholder.png”);
}
Texture2D tex = new(2, 2, TextureFormat.RGBA32, false) {
filterMode = FilterMode.Point,
anisoLevel = 0,
requestedMipmapLevel = 0
};
tex.LoadImage(pngBytes);
return tex;
}

Antonia answered 27/7, 2022 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.