View Full Version : Texture filtering

04-21-2002, 09:40 PM
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).]

Rob The Bloke
04-21-2002, 09:43 PM

04-21-2002, 10:12 PM
Originally posted by Rob The Bloke:

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! :-)


04-22-2002, 01:13 AM
Have you tried using a background color similar to the other texture colors?

04-22-2002, 02:05 AM
Use alpha channels for your textures and enable blending with (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA).

04-22-2002, 02:17 AM
If your texture does not contain semi-transparent texels, then use alpha testing and it should do the trick.

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.

04-23-2002, 10:49 PM
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.


04-24-2002, 02:12 AM
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.