Selectively applying anti-alias/ bilinear filter

Is there a way to turn on anti alias based on how far an object is from the camera?

For example, if I have a pixel art plane that is laid as a floor, and the camera is looking at the plane at a 45º angle

is there a way for the pixels that are farther away to get anti-aliased, (instead of getting downscaled by nearest neighbour)

BUT

keeping the parts of the floor that are closer to the camera rendering as nearest neighbour

thanks

What kind of antialias are you using?

If using MSAA, there’s no way to do this as it’s hardware based. If you’re using TAA, FXAA, or some other software based antialiasing, you could modify the antialiasing shader to exclude regions of the screen based on whatever criteria you need.

Hmm… what you’re talking about here is not antialiasing at all, antialiasing happens on the borders of primitives and works to reduce jaggedness on the edges of objects. I think you’re referring to texture filtering (either nearest neighbor, bilinear or trilinear). There’s no way to change it depending on distance since (like multisample antialiasing) it’s built into the hardware.

You could however easily write a shader (or make one with ShaderGraph) that performs filtering manually, and switches/blends between different sampling methods based on distance to camera.

ye, I mention this because I saw a dev saying that they were processing pixel art that was scaled down due to being far from the camera with bilinear filter and keeping nearest neighbor for pixels that were close to the camera to keep the pixel art feel

however they were not using unity for this, it was their own custom made engine

they said they even had a % float of a spectrum between bilinear and nearest neighbour that they were applying based on distance

Pixel art should stay pixel art. Any sudden change would cause a very weird splitting line. What you usually want to do is using mipmapping so the texture is properly downscaled. When you use a texture atlas, it’s important that the tiles in the atlas are aligned properly and that you limit the number of mipmap levels so it never goes beyond 1 pixel == 1 tile. Otherwise the next step would mix between tiles. So the classical Minecraft atlas had 16x16 pixel tiles and had 4 mipmap levels (16,8,4,2,1).

Yes, this is entirely possible to do (and actually quite simple): you just have to use a custom shader that either does the filtering manually, or sample the same texture twice using two different samplers (one set to bilinear and the other set to nearest) and interpolate the resulting colors (this is the% spectrum part) based on distance.

Not if you interpolate based on distance, same as you can do with mipmaps. Still, the area where you interpolate between nearest and bilinear could look weird depending on the contents of the texture.

This would get rid of aliasing issues/moiré patterns in the distance, but maybe OP just wants the texture to become slightly blurry when far away?

the purpose was to reduce pixel swimming when camera moves and areas far away from the camera are visible in the distance. Since they are far away the pixel art gets scaled down a lot , well, its understandable

(not pixel perfect btw)

anyway, it seemed like an interesting solution when I was listening to the devs so I wondered if it was possible in unity

That’s my take away. It sounds like they are using very small, high contrast textures which could look very ugly at a distance. Probably the simplest thing to try first is simply enable mip-mapping and see if that works (assuming they haven’t already done that)

That’s what mipmapping is for? it uses scaled-down versions of the texture when far way, to reduce pixel swimming as you call it.

I think we would understand the problem better if you showed an example of the issue you’re trying to avoid.

Yeah, you can do this in any engine. But the thing is why? If the goal is to alleviate aliasing in the distance, mipmapping solved that a very, very long time ago and it’s built into all GPUs. In Unity, you can enable it per-texture in the texture import settings.

here is the link for what im talking about

with timestamp

maybe in the words of the dev you will understand better, i dont really know how to explain well

another timestamp

this would apply on objects that imo are much closer than what mip maps would be for, which would be for something really really far away, this is still kinda close to the cam, but far enough to jitter

Oh ok, so this is definitely a case of making the texture blurrier. Mipmapping won’t help here at all.

The solution is indeed to sample the texture twice, once using bilinear and once using nearest, then interpolate based on distance. This is trivial to do either in a handwritten shader or in ShaderGraph. If you’ve never dealt with shaders before I’d recommend checking out ShaderGraph and start from there.