Sign in to follow this  

Problems with texture bleed using Microsoft.DirectX.Direct3D.Sprite class

This topic is 3729 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

I have this texture page with a bunch of sprites. Around the sprites is a grid of lines which is very useful for editing the texture pallet. Anway, these images are 32x32 (not including the grid lines). If I use the Sprite class (C#, Direxct9) I get some bleed around the edges of the sprite, which looks like the texturemap is mixing in the grid lines. I did some searching and was told to CLAMP the texutres. I am not sure I did this right, but what I did was: device.SetSamplerState(0, SamplerStageStates.AddressU, 3); device.SetSamplerState(0, SamplerStageStates.AddressV, 3); in the render loop. It didn't do anything. The next thing I heard about was that textle alignment should be offset by -0.5. The problem here is that I have no idea how I am suposed to change this with the Sprite class. I had done all this previous work with making my own sprites before I found the sprite class, and now it looks like all this new work using it may have to go out the window. This really sucks. Is there some way I can get this sprite class to work right with a texture page and not bleed on the edges?

Share this post


Link to post
Share on other sites
Texture bleeding is a real pain. The only ways that I know of to solve it are:

1. Use one texture per primitive, with texture clamping enabled. This is a trivial fix, as there is now nothing to bleed into, but it has the potential to destroy your batching efficiency.
2. Use point-filtering. Obviously, this is only viable in very specific situations - notably, 1-1 texel-pixel mapped sprites at integral screen-positions that never undergo scaling or rotation.
3. Disable anisotropic filtering and ensure that texture boundaries are aligned at powers of two. Technically, this should do the trick, but I found it to be ineffective on my old GeForce 4400 Ti. Exercise caution.
4. Provide sufficiently large gutter areas between atlas components.

These all assume that your texture coordinates are centrally aligned (that's the half-pixel offset you mentioned - I think D3DX's Sprite class takes care of this for you). As you can see, none of the solutions is a one-line fix. As a rule, if you want maximum generality and full image-quality, then guttering is your only option.

The size of the gutter depends on the size of the texture. I've found that 4 pixels of gutter is sufficient for a 512x512 texture. You may get away with fewer, but there's not much performance to be gained in doing so.
If you employ guttering from the beginning of the project, the only annoyances are new non-uniform texture coordinates and the inability to use your image editor's grid. The former is an easy fix with a tiny bit of extra arithmetic, and the second can be ameliorated using a manually created grid-overlay during the editing phase.

By the sounds of things, the grid you are using may be adapted to serve as a gutter in itself if you were to use alpha-blending to your advantage. I'm not sure on your blending operations or precalculated-alpha situation, but you may find that setting the grid area to have zero alpha will fix your problem. This way, the bleeding will still occur, but the bleed will be into a transparent zone. Beware that if your rendering technique blends colour and alpha separately, with post-multiplied alpha, this won't entirely eliminate the artifacts.

Admiral

Share this post


Link to post
Share on other sites
I can only have one alpha color right? Right now I am using hot-pink. As for filtering, I tried turning it off, and it doesn't seem to change anything (neither does turning it on).

While my main texture is 512x512, I am really using 32x, 64x and 128x textures from it.

You said texture boundries must be aligned by a power of 2, do you mean even the sub textures I am using from the texture page or just the bigger texture? I am not sure how I am suppoed to manage the sub-texture page like that.

Share this post


Link to post
Share on other sites

This topic is 3729 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.

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