I'm using XNA 4.0 and VS2010 Express for Windows Phone and Windows Phone SDK 7.1. This is a platform game and I have a map made up of 16x16 textures that is drawn dynamically, tile by tile. When using SpriteBatch to draw my map with LinearClamp, I get artifacts that looks like blurry thin lines. They become visible when the camera moves from one pixel to another and when the camera is still, the artifacts disappear. Here's a small sample of what I mean:

line artifacts

Here's how I draw with the spritebatch:

SBWorld.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, camera.View);

When using SamplerState.PointClamp the game just plays horribly (IMHO), so I cannot use that. Why do these lines appear and how do I get rid of those?

  • Is it possible to move the camera by a fraction of a pixel? If so ensure any offsets are in whole numbers. – ClassicThunder Oct 2 '12 at 16:27
  • Anyways point clamp is the way to go with tile maps what does "just plays horribly (IMHO)" mean? – ClassicThunder Oct 2 '12 at 16:38
  • Yeah, I think I have to use PointClamp, but it doesn't look good. The camera runs real smooth with LinearClamp compared to PointClamp. The camera targets the player lerping into position wherever the player goes, maybe I should do it another way. – Raymond Holmboe Oct 2 '12 at 23:43
  • 1
    Using PointClamp or rounding camera movement to a whole number will result in the same look. If you have this issues with this the most likely answer is you are moving the camera too quickly. The effect should be much less noticeable at lower speeds. If high speeds are necessary then you can implement motion blur to ease the kinda of cross eye effect that comes from scrolling an image too fast. – ClassicThunder Oct 3 '12 at 0:00
up vote 2 down vote accepted

The problem is that the linear interpolation (the Linear part) is interpolating between the edge pixels of a tile and edge pixels from the next tile over, when your tiles do not line up perfectly with screen pixels.

Using the Clamp texture addressing mode would solve this if you had one tile per texture, instead of a sprite-sheet - but that has its own disadvantages (namely: severely decreased performance).

So the only real solution is to add appropriate padding around tiles in your sprite-sheet so that, rather than the linear interpolation taking pixels from other tiles, it takes pixels from the padding.

The other alternative, as mentioned in comments, is to snap the camera to whole pixel positions (providing your tiles are positioned and scaled correctly so that their pixels line up perfectly with screen pixels).

Also from comments: one of the Point addressing modes would turn off interpolation entirely, avoiding this problem. However this will result in artefacts if you have tiles at fractional pixel positions - as you already know.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.