Archived

This topic is now archived and is closed to further replies.

red_sodium

Gaps appear in tiled area

Recommended Posts

Hey GDers, I''m using DX9b SDK and ID3DXSprite for a 2D game. The problem is that when I render my tiles in a grid formation, I get 1 pixel wide gaps that look like lines in between tiles, even when they''re the exact number of pixels in position (64 in this case). When I move the camera, the gaps flicker on and off and I get it in between different tiles. Does anyone know why this happens and does anyone know of an easy solution? Thanks Stay Clausal, Red Sodium

Share this post


Link to post
Share on other sites
Is your near plane set to 1.0? Setting it to 0 can cause such things sometimes. Also, there''s another post currently on here about something similar. Basically, your tiles should be powers of 2.

Chris

Share this post


Link to post
Share on other sites
Nope, that doesn''t help. I have the same problem.
Nothing I''ve tried so far works.

The only work-around I''ve found is "padding" color
around your tiles. Make the padding around the texture
coordinates match the color inside the lines. For far
distances, you need to pad it with 2 pixels

Share this post


Link to post
Share on other sites
Glad to see I''m not the only one with these problems.

As I said above, my tiles are 64 x 64, and I tried the FOV fix but it didn''t work.

I do not want to have to pad my tiles: no cheap hacks. Surely there must be some easier way.

I also get a slight shimmer when I move my camera in relation to the grid of tiles sometimes.

Stay Clausal,

Red Sodium

Share this post


Link to post
Share on other sites
Using Radeon 8500? I see the same shimmers. Mine seem to
appear when I try to render one mesh on top of another.
Even with Z-buffering off, the back mesh seems to want to
come through. Farther away I go, the worse it gets.

Let me know if you figure out a solution?

Share this post


Link to post
Share on other sites
Err, nVidia TNT 2, its extremely annoying and I can''t seem to get rid of it. Moving the camera around at an angle doesn''t get rid of it. Please, I really don''t want to have to resort to padding - there surely must be some other way?!

Stay Clausal,

Red Sodium

Share this post


Link to post
Share on other sites
I believe it's actually texture filtering that's doing it.
At least that's what my problem was. It makes sense. It's
using the colors around each color to blend in the filter.
So it's using the transparent color around our tiles. Try
setting these right before you draw your tiles (if you're
using the D3DXSPRITE class, set these after Sprite->Begin()):

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);

I'm not sure why D3DXSPRITE turns on filtering, but it looks
100% better with it. So I'm sticking to padding

[edited by - Jiia on May 20, 2004 9:56:07 AM]

Share this post


Link to post
Share on other sites
That isn't my problem, because the tiles I am using have no transparent areas around them. I tried your code anyway and it didn't change anything. Thanks anyway.

I really, really don't want to use padding. Really. It would feel cheap and hacky and surely many developers have this problem? Any other suggestions?

PS:
quote:
You could try playing with the frustum, that might help.
Read that out aloud, sounds a little, err :S
Anyway, how could I change it in such a way that it might eliminate these problems? Thanks.


Stay Clausal,

Red Sodium

[edited by - red_sodium on May 21, 2004 12:09:21 PM]

Share this post


Link to post
Share on other sites
Are you developing in 2D or 3D?

Do your tiles look pixelated when you zoom in?

If you''re using mip-maps, I think you need to disable
their filtering systems, too. Not too sure about it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
As someone mentioned before it''s the filtering that causes this i can assure you. You need to adjust your uv coordinates by a half texelsize. On the left/top uv add a half texel on the right/bottom subtract a half texel.
This prevents the gpu from sampling texels outside your tile.

(texelsize = 1.0f / texturewidth)

Share this post


Link to post
Share on other sites
Can you give us an executable that we can run to demonstrate the problem, this way if you get a few people test it on different hardware configurations you can confirm if it is the hardware, the driver, or your software.

If you can''t give us a download, can you throw up a couple of screen shots that illistrate the problem. I know what you are talking about, but it makes it a whole lot easier to solve a problem that we can see.

Share this post


Link to post
Share on other sites
You could also post some source code: Where you create your sprites, and how you render them. I would also help if you showed the texture the sprites use.

Mariano Ruggiero
Lead Programmer
ONIRIC GAMES

Share this post


Link to post
Share on other sites
quote:
Original post by red_sodium
Hey GDers,
I''m using DX9b SDK and ID3DXSprite for a 2D game.

The problem is that when I render my tiles in a grid formation, I get 1 pixel wide gaps that look like lines in between tiles, even when they''re the exact number of pixels in position (64 in this case). When I move the camera, the gaps flicker on and off and I get it in between different tiles.

Does anyone know why this happens and does anyone know of an easy solution?



How did you specify the sourcerect in the sprite->Draw() call ? Is it 0,0,63,63 or 0,0,64,64 ?
I think a (windows ) rect is inclusive so it should be (0,0,64,64), counter-intuitive to what you would expect if you are used to arrays or for-loops.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If adding an border to your tiles solves the problem then it''s filtering that casuses the problem. I checked ID3DXSprite and as you say it not possible to set UV with it and then it seems like ID3DXSprite don''t handle the problem and the only way to fix it is to add a border or turn off all filtering or make your own
sprite engine. And im not guessing here...

Share this post


Link to post
Share on other sites
No your all wrong, there is a bug with ID3DXSprite well atleast I think there is..
did you look here?

bounce!

>>>>>
Quote
>>>>>
Sprites drawn with ID3DXSprite are not the same size than their original bitmap. This problem becomes glaringly obvious when you try to tile your bitmaps: tiles will not line up properly if they are bigger or smaller than their target rectangles.
<<<<<
>>>>>

[edited by - ACAC on May 25, 2004 9:58:43 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by ACAC
No your all wrong, there is a bug with ID3DXSprite well atleast I think there is..
did you look here?

bounce!

>>>>>
Quote
>>>>>
Sprites drawn with ID3DXSprite are not the same size than their original bitmap. This problem becomes glaringly obvious when you try to tile your bitmaps: tiles will not line up properly if they are bigger or smaller than their target rectangles.
<<<<<
>>>>>

[edited by - ACAC on May 25, 2004 9:58:43 AM]



That''s not a bug. Fidelio66''s right.

In Windows, RECTs are defined so the upper left corner is included in the rect, but the lower right corner is excluded from it. This may appear to be not so intuitive at first, but once you start using them it makes sense. With RECTs defined like this, you can get the width of a rectangle by using right - left (or get the right of the rectangle by using left + width). If the lower right corner of the rect was included in it, you''ll have to add or subtract 1 in all of your calculations.


Mariano Ruggiero
Lead Programmer
ONIRIC GAMES

Share this post


Link to post
Share on other sites
Okay, screenshots:






I am using a rendering rectangle of (0, 0, 64, 64) for 64x64 sprites. The lines that appear are gaps because when I change the background colour, the line colour also changed. When I move the camera, the lines flicker on and off and at different thicknesses. I''ll see what I can do as to distributing the EXE.

Turning off filtering like so doesn''t solve the problem:

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);

So to fix, are you saying I should keep my rendering rect inclusive or exclusive of the 64, 64 point?



Stay Clausal,

Red Sodium

Share this post


Link to post
Share on other sites
By reducing the distance (along each axis) between the tiles from 64 to 63, this appears to remove the problem. But since the tiles are 64x64, this must be just a cheap hack. Besides, when they are 64 pixels apart, only occassional gaps show.

(The cheap hack)


I really don't want to resort to any cheap hacks or something like this, as this might ruin the collision detection, etc. Rather by doing this I'm hoping it will help give people a clearer image of what the problem is.

Here's the tile I'm using:

Stay Clausal,

Red Sodium

[edited by - red_sodium on May 25, 2004 1:46:49 PM]

Share this post


Link to post
Share on other sites
Are you absolutely sure you turned off all texture filtering? Are you rendering in object-space with D3DXSprite? I know I gave you the first two lines of this, but try it with another line. And make sure you call these every frame after Sprite->Begin():

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

I feel your pain.

Share this post


Link to post
Share on other sites
Ahh, wait! That''s the Z Buffer! I didn''t notice that your tiles are actually colored to have softened borders. If it''s the z-buffer, then padding your tiles will not help. I''m pretty sure you need to reduce your distance from near-to-far clipping planes. Or use a 32-bit Z-Buffer. You need a limit to how far your screen can zoom out on your game.

An alternate solution would be to dump D3DXSprite and make a nice welded set of quads for tiles. Then they will not break apart.

Share this post


Link to post
Share on other sites
quote:
Are you absolutely sure you turned off all texture filtering? Are you rendering in object-space with D3DXSprite? I know I gave you the first two lines of this, but try it with another line. And make sure you call these every frame after Sprite->Begin():

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

I feel your pain.


Jiia, this worked! I think what I was doing wrong before was putting it in my initialization function instead of after ID3DXSprite->Begin(). The first two lines also work just fine. I should''ve paid more attention to your (and other) earlier posts. Oh well, no filtering, but it looks fine anyway from a distance, I doubt I''ll let my players zoom in that far anyway

But just in case, is there a happy medium at all?

Thanks a lot for your help, Jiia, everyone.

Stay Clausal,

Red Sodium

Share this post


Link to post
Share on other sites