Advertisement Jump to content
Sign in to follow this  
Sol Blue

Scaling textures causes flickering lines between tiles (pics)

This topic is 3907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm writing a 2D, top-down game with Direct3D 9. My terrain is a grid of 100x100 pixel tiles drawn with ID3DXSprite. Because I'm not using pre-transformed coordinates (if that's the right term: my camera is in object space), everything is automatically scaled, which I want. However, when I turn on some texture sampling so it looks better, flickering lines appear in between the tiles as the camera moves. They aren't there without the sampling. Here's a screenshot of the no-sampling, correctly-drawn tiles: No sampling, no phantom lines And a screenshot of the problem: With sampling and flickering lines Here's the sampler code I've been commenting and uncommenting:
gDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
gDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
gDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

The white lines are coming from the part of the image that surrounds the tile. (If I change the image file so the background is red, there are red lines.) I know this isn't a lot to go on, but surely this must be a fairly common problem? Does anyone know what's going on, and how to avoid it?

Share this post


Link to post
Share on other sites
Advertisement
You are filtering the neighbouring white texels. To fix this put the texture onto its own page and ensure the TAddress mode is set to wrap (not clamp or border).
If you don;t want to do this then you'll need to dilate out the texture by N number of pixels. The value of N depends on the base siaze and how many miplevels you are likely to drop down.

Share this post


Link to post
Share on other sites
Thanks, Alias, I'm working through that now, and it sounds like it might help. I've made sure the texture address mode is set to wrap. How do I put a texture "onto its own page"? If you mean that the texture should be in its own image file, it is. (Sorry, I'm pretty new to this...)

Share this post


Link to post
Share on other sites
If you want you can also put a 1 pixel (or greater) border around your tiles, with either alpha value of zero or some color that won't look bad when filtered with the actual tile.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
If you want you can also put a 1 pixel (or greater) border around your tiles, with either alpha value of zero or some color that won't look bad when filtered with the actual tile.


Thanks for the advice. I tried this -- having the tile surrounded by an alpha of 0 in its image doesn't seem to do anything; it filters the transparent pixels anyway.

I also tried using a slightly larger tile, and then taking the middle of it -- for example, a 100x100 pixel grass tile becomes 102x102, and the center is used. This looks much better, since it's filtering grass along the edges instead of a solid color, but there is still a bit of flicker where the tiles meet.

Surely there must be a way to make adjacent edges of tiles and the like perfectly flush?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!