Sign in to follow this  
Aardvajk

Texture atlases and linear filtering

Recommended Posts

Aardvajk    13207
Just wondering if anyone can help with the following problem. I'm writing a 2D platformer with Direct3D and it makes heavy use of procedurally generated texture atlases for drawing sprites to reduce the number of DrawPrimitive calls etc. Trouble is I also really want to be able to use linear filtering as I am scaling the graphics down when running at resolutions lower than the native for the game. This obviously causes colour bleeding from adjacent sprites on the texture when linear filtering is enabled. I've tried putting a border around the sprites in the atlas and colouring the border every possible colour I thought might help but nothing seems to work. Is there a solution to this, or do I need to dump texture atlasing for anything I want to apply a filter to? Thanks.

Share this post


Link to post
Share on other sites
killabi    180
You can severely limit the artifacts by ensuring that your uvs do not go up to the edge of the atlas. I suggest leaving yourself a decent buffer around all of your edges so that your mips will stand up as well. You can do this proceduraly if you scale your image and uvs down slightly when loading it into the atlas.

Share this post


Link to post
Share on other sites
Aardvajk    13207
But what do I fill the "buffer" with? I've tried black with zero alpha and I still get a black tint round the edges of the sprites, I've tried solid black with 255 alpha and the problem is the same.

About the only other thing I can think is to duplicate the edge pixels around the edges, but I'm pretty sure there will still be errors.

Is it just not possible to do linear filtering correctly when using an atlas perhaps? Obviously there is no way the hardware can know what pixels are valid and which are not and so I don't see how you can avoid bleeding when using a filter that does anything other than nearest point.

Share this post


Link to post
Share on other sites
DonnieDarko    251
Quote:
Original post by EasilyConfused
About the only other thing I can think is to duplicate the edge pixels around the edges, but I'm pretty sure there will still be errors.
that does anything other than nearest point.


I think this is close to a working solution, but for better results you want to average surrounding pixels and not take into account pixels that does not belong to the texture surface, those could eg. be described by an alpha of 0. For a more correct approach you need to take into account the texture space polygon edges that border pixels not part of a polygon, so you find the polygon that shares the edge in question and samples pixels along this edge to compute the average.

You need to do this for a buffer around the texture space polys as killabi says, and it needs to be large enough to compensate for averaging of surrounding pixels when down sampling mip maps.

If you are using D3D, the D3DX UVAtlas functions can help you do this (actually also the standalone UVAtlas tool) and this buffer around polys are in those functions referred to as gutter.

Share this post


Link to post
Share on other sites
Drilian    1067
The best thing to do, I believe, is to duplicate the edges of your textures, which is what I had to do to eliminate the cracks in my UV atlased models when filtering was on.

Depending on how many mip levels that you have (if you're even using mip levels), you will need different-sized buffers (you want to make sure that you have enough of a border so that it's still there in lower mip levels).

Hope that helps!

Share this post


Link to post
Share on other sites
Aardvajk    13207
Quote:
Original post by Drilian
The best thing to do, I believe, is to duplicate the edges of your textures, which is what I had to do to eliminate the cracks in my UV atlased models when filtering was on.

Depending on how many mip levels that you have (if you're even using mip levels), you will need different-sized buffers (you want to make sure that you have enough of a border so that it's still there in lower mip levels).

Hope that helps!


Cheers for the link, Drillian. I'll give that a try tonight. Since I'm working on rectangular-based atlas areas, figuring out the skirt colours will be a lot simpler for me than it was for you and I'm not using mipmapping so I should get away with a single pixel border.

Pretty good solution if it works since I should get pixel-perfect original sprites without filtering and eliminate cracks with filtering on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this