Texture filtering

My texture maps have lots of “background” pixels in them. I use paletted textures, and these are set to (0,0,0,0).
My problem is, when I use glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN/MAG_FILTER, GL_LINEAR), those non-zero texels that are adjacent to zero-texels are affected by the filtering. Is there any way I can avoid this?
i.e. I don’t want the zero-texels to have any contribution.

many thanks,
Karthik Balasubramaniam

[This message has been edited by clunis_immensus (edited 04-22-2002).]

Replace GL_LINEAR with GL_NEAREST

Originally posted by Rob The Bloke:
[b]Replace GL_LINEAR with GL_NEAREST

[/b]

should’ve mentioned this: GL_NEAREST quality is unacceptably poor. I need to use GL_LINEAR, preferably without the boundary-filtering artefacts. I’d like to have the cake and eat it too! :slight_smile:

Karthik

Have you tried using a background color similar to the other texture colors?

Use alpha channels for your textures and enable blending with (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA).

If your texture does not contain semi-transparent texels, then use alpha testing and it should do the trick.

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0f);

Otherwise replace your (0, 0, 0, 0) by the value of the adjacent texel colors but with a zero alpha channel.
For instance, if your texture is the following 4x4 2D texture :
(1, 0, 0, 1) (1, 0, 0, 1) (1, 0, 0, 1) (1, 0, 0, 1)
(1, 0, 0, 1) (0, 0, 0, 0) (0, 0, 0, 0) (1, 0, 0, 1)
(1, 0, 0, 1) (0, 0, 0, 0) (0, 0, 0, 0) (1, 0, 0, 1)
(1, 0, 0, 1) (1, 0, 0, 1) (1, 0, 0, 1) (1, 0, 0, 1)

Then replace the center texels by (1, 0, 0, 0).
Note that this sample texture is a good example because all colored texels are red. But if the texels follow a complicated paelette, eg rainbow-style palette, then results won’t be very good.

I personally recommend alpha testing.

Originally posted by vincoof:
[b]If your texture does not contain semi-transparent texels, then use alpha testing and it should do the trick.

My textures are semi-transparent, and I am already using blending, with alpha-testing. This results in the background texels (i.e. RGBA = (0,0,0,0) ) not being drawn.
When using GL_LINEAR texture-filtering, the problem is, the colour of a pixel is affected by all texels in the filter-footpint, regardless of whether the texel values are above the alpha threshold or not. What I really want is an alternative to GL_NEAREST and GL_LINEAR that gives me control over the filtering. Is there an Nvidia extension that can achieve this?
Right now, I don’t generate the mipmaps myself. If I did, I guess I could do the filtering myself then. The problem is, my texture changes (actually, the texture-palette) in real-time, so this won’t work.

thanks!
Karthik

If you have semi-transparent texels, then that’s annoying because in OpenGL your texture magnification is either linear or nearest, but you can’t say “that part of the texture uses linear” and “that part of the texture uses nearest”.

Though, you could use another texture unit which would work as a mask, with a nearest magnification for cutting edges. This new texture would just contain an alpha channel to modulate the alpha channel of the previous texture unit. Because this new texture would be maginified with “nearest”, the mask would not be smooth and that would do the trick.