TIGSource Forums

Developer => Technical => Topic started by: SelfTitled on October 27, 2013, 05:04:45 AM



Title: Tile map drawing issue (float precision?)
Post by: SelfTitled on October 27, 2013, 05:04:45 AM
Hi
I've been making a game with tiles. My tiles are 32x32 and I draw them from a sprite sheet but I am having an issue where the edge of the next tile in the sprite sheet is bleeding into my current tile.

I have a feeling this is a float precision issue but I was wondering if someone could help shed light on this issue for me, possibly point me in the right direction as to solving the problem.

Below is an image of what I mean:
(http://selftitledgames.co.uk/images/TileMapIssue.png)


Title: Re: Tile map drawing issue (float precision?)
Post by: Christian Knudsen on October 27, 2013, 05:37:34 AM
You need a 1 pixel border around all your tiles on the sprite sheet.


Title: Re: Tile map drawing issue (float precision?)
Post by: henzenmann on October 27, 2013, 05:43:36 AM
I would suspect an off-by-one/rounding/implicit-conversion problem in the code calculating the tex-coords. Float tex-coords are very common, and at least I personally have never run into problems with float precission using them in OpenGL...


Title: Re: Tile map drawing issue (float precision?)
Post by: nikki on October 27, 2013, 06:30:44 AM
To me that doesn't look like bleeding.
It looks more like a lightblue background that isn't covered totally by your tiles.

What happens if you, instead of your textures, draw red rectangles?
What happens if you add 0.5 to the locations where you draw those tiles?


Title: Re: Tile map drawing issue (float precision?)
Post by: SelfTitled on October 27, 2013, 06:56:59 AM
To me that doesn't look like bleeding.
It looks more like a lightblue background that isn't covered totally by your tiles.

What happens if you, instead of your textures, draw red rectangles?
What happens if you add 0.5 to the locations where you draw those tiles?

If I draw just a single 32 x 32 texture it works fine no gaps. The blue is the background because the adjacent tile is blank.
I'm using xna and spritebatch draw so I can only specify my source rect in ints.

Thanks for everyones help :)


Title: Re: Tile map drawing issue (float precision?)
Post by: Christian Knudsen on October 27, 2013, 07:17:52 AM
I am having an issue where the edge of the next tile in the sprite sheet is bleeding into my current tile.

The blue is the background because the adjacent tile is blank.

Does this mean that you don't have transparency in your sprite sheet? That the light blue is the 'empty' color on the sprite sheet? If so, you need to change that to be transparent. (And still have a 1 pixel border around the sprites on your sprite sheet to avoid bleeding from adjacent sprites.)


Title: Re: Tile map drawing issue (float precision?)
Post by: SelfTitled on October 27, 2013, 07:30:02 AM
found this on xbligs forums

Quote
Any time you apply a non-identity pixel transform to a texture, it will get filtered. You have many options to prevent bleeding when this occurs:

    Don't apply non-identity transforms at the pixel level (no scaling, no rotation, only integer destination positions)
    Use point sampling (and put up with the significant loss of visual quality)
    Don't use sprite sheets, just have a separate texture per sprite (and put up with the resulting loss of performance)
    Or (my personal recommendation) include a one-pixel padding around the edge of each sprite in your sheet


Padding your sprite borders is the only way to make sprite sheets work with texture filtering while avoiding bleeding. Check out our recently released Sprite Sheet Sample for one approach to automatically setting up the necessary borders.

It turns out its the scaling on my camera (zooming in and out). So going to go with your original suggestion of the 1 pixel border, means redoing all my sprite sheets :(


Title: Re: Tile map drawing issue (float precision?)
Post by: InfiniteStateMachine on October 27, 2013, 07:31:59 AM
It's possible the filtering is causing that. Do you have your SamplerState set to PointClamp?

EDIT: nanoed :X


Title: Re: Tile map drawing issue (float precision?)
Post by: moi on October 27, 2013, 07:38:30 AM
I don't know the specifics of XNA but:
check the clamp mode of the polygon if you're using polygons. Aka the way the texture wraps on the edges of the polygon, also play with the UV zooming on the polygon (zoom on the texture by less than a pixel or sthg like that


Title: Re: Tile map drawing issue (float precision?)
Post by: Christian Knudsen on October 27, 2013, 07:43:15 AM
Also, if none of that works like you want, you might be able to implement zooming by drawing the zoomed area to a texture (without zooming) and then rendering that texture to screen (and scaling it accordingly to get the zooming effect).


Title: Re: Tile map drawing issue (float precision?)
Post by: SelfTitled on October 27, 2013, 09:54:47 AM
I change Sampler state which had no affect but adding the 1 pixel border worked well. Not sure how that may affect the tile transisions though.

Thanks again for the help :)


Title: Re: Tile map drawing issue (float precision?)
Post by: Anti! on October 27, 2013, 12:33:33 PM
Like already said: To avoid texture bleeding, copy the first/last row and top on the 1px border of your sprite with increased size. That should do the trick. If you're using AA or Mipmapping even larger borders may be necessary.

My advice: Build your sprite atlas on the fly and fill the gaps using your own code.