PDA

View Full Version : Single Pixel Lines in Textures Shimmer



coolguyclay
09-30-2008, 08:19 AM
Hey there,

I'll describe this the best I can, let me know if more information would be useful.

The setup:
I have a grid of textures composing an image, say a 10x10 grid of 64x64 textures. The textures are really just a tiled image chunked off into texture memory. The image contains single pixel width lines and looks good on its own. The tiles are positioned on the screen (using glOrtho) to positions not at even pixels. Two bordering tiles might have upper left y coords of 214.4 and 214.6 (as an exmaple, unsure of exact spacing).

The problem:
The image made out of textures draws single pixel lines that are, I presume, less than a pixel wide. (This is not a glLine call, just positioning a texture on the screen). The effect this produces is a shimmer of the lines as the color moves from one side of a pixel to another when the image is panned slowly in any direction. With many lines on the screen it is quite a nuisance.

Ideas:
I am using GL_LINEAR as the texture filter. I have tried GL_NEAREST and while this keeps the single pixel width lines in tact (no shimmer), entire tiles now appear to shift. Almost makes the image appear to "melt" (cool affect, not good to read an image with : ) I would guess putting the texture tiles at fixed pixel positions, the net affect of using the NEAREST filter on the innards of the textures, causes the tiles to not line up quite right at the half-pixel boudaries when using LINEAR filtering.

That's the story. Any way to fix this? The textures are created with sort of a bitmap drawing system, so lines have to be drawn as full pixel colors, no 1.5 width lines. Is anti-aliasing something that would be used here? A way to get the affect of GL_NEAREST while keeping the center of the tiled texture image at the same position so the tiles still line up at half-pixel screen coords?

Let me know if you have any idea.

Thanks!
Clay

ZbuffeR
09-30-2008, 09:01 AM
Try with building mipmaps and using GL_LINEAR_MIPMAP_LINEAR.
Then you can play with texture lod, to blur slightly the texture and avoid the high frequency Shannon aliasing.
Or renter to 128*128 tiles with 2 width lines, then render as half scale. This will shimmer less.

coolguyclay
09-30-2008, 11:13 AM
Thanks for the suggestions!

I like the mipmapping idea but am pressed for texture memory. (this isn't for a commercial PC graphics card). I can't have any mipmaps : (

As for the two-width lines, I would like to stay away from that. The lines look better and makes my images more 'crisp' if they are not too thick. This really comes into play with my "custom" one-width lines that have cross lines, loops, etc built in (they don't work with >1 width lines).

Thanks for your suggestions. Got anything else? : )

Clay

ZbuffeR
09-30-2008, 02:33 PM
I don't get it : you can not expect to have good precision with rasterised bright lines on black, when the texture is resampled at subpixel precision.
You need to first render finely antialiased lines on the texture if you want to stay with 1 pixel width lines.

Oh and by the way, mipmaps are quite cheap, only +33% of texture memory.

If you give more details, screenshots, and your constraints about your application, people will surely have other ideas to help.

coolguyclay
10-28-2008, 11:32 AM
We've been looking into this a lot and I would say you are correct, ZbuffeR. I think the artifact I was seeing was just the way OpenGL handled the texture of a rasterized sinlge-width line.

I'd still like to try the MipMap option, but until then, thanks for your ideas. It did help straighten some things out.

Clay