PDA

View Full Version : Texture filtering



clunis_immensus
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
Replace GL_LINEAR with GL_NEAREST

clunis_immensus
04-21-2002, 10:12 PM
Originally posted by Rob The Bloke:
Replace GL_LINEAR with GL_NEAREST



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

Karthik

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

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

vincoof
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.

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.

clunis_immensus
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.

thanks!
Karthik

vincoof
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.