Sprite filtering

So you’ve rotated or scaled your sprite and it looks all pixelly and blocky:

What do you do to counteract this? The solution is simple. On your sprites (or via Gorgon.GlobalStateSettings) you can enable filtering on your zoomed/rotated sprites to keep the edges looking smooth.

 

To enable filtering:

YourSprite.Smoothing = Smoothing.*

(or from the global state setting)

Gorgon.GlobalStateSettings.GlobalSmoothing = Smoothing.*

Where Smoothing.* can be one of:

  • Smoothing.None – No smoothing applied (This is the default setting).
  • Smoothing.MagnificationSmooth – Smooth only when magnifying.
  • Smoothing.MinificationSmooth – Smooth only when shrinking.
  • Smoothing.Smooth – Smooth for both.

Why are there 3 modes for smoothing?

Well filtering (or smoothing if you’d prefer) can be an expensive process {this of course depends on your video card} and there are situations where you might not care about the aliasing when you shrink or expand a sprite, so you can opt only to apply filtering when one scaling direction is taking place.

 

Texture bleeding.

Unforuntately there’s another issue: Texture bleeding. This happens when you’ve got several sprite images packed tightly together on an image and you apply filtering to a sprite that’s using that image. What you might see is a line appear along the edge of your sprite in such a case. What’s happening is that your video card is sampling the neighbouring pixels when it’s filtering to smooth out the image, so what happens when you have to images right next to each other? That’s right, the other images get sampled into your sprites image.

To correct this, note the above image. See how the right image has a space between the box and the circle? This will keep the card from sampling the neighbouring pixels of the accompanying images. In an ideal situation, you’d have this extra space with an Alpha of 0. If you were to pad it with the color the of outline of the sprite you could probably bleed into another sprite that has filtering enabled.

Leave a Reply