PDA

View Full Version : GL_REPEAT and interpolation problem



Topquark
04-11-2005, 10:24 PM
Hello

I'm writing a volume rendering engine and I want to use cubic interpolation as described in http://wwwvis.informatik.uni-stuttgart.de/vmv01/dl/papers/8.pdf. I managed to get this algorithm working (in 2D for now), but there is a problem:
I have two textures, 'A' is texture to be filtered and B is single 'tile' of filter kernel. In each pass the filtered texture is mapped onto a quad (say it's extending from (0,0) to (1,1)) with texture coordinates also (0,0), (1,1) (these coords are actually differently translated in each pass, but it's not important here). It's modulated with texture 'B', which is repeated across the quad so one 'instance' of 'B' covers exactly one texel of 'A'. Texture 'A's filter is set to GL_NEAREST and 'B's to GL_LINEAR. But texture 'B' has different luminance levels on opposite edges (white and black), so 'B's texels along 'B's edges undesirably interpolate with neighbouring 'instances'. How can I avoid this?
Notice: texture 'B' must be GL_REPEAT'ed along the quad (that's the point of algorithm used) and definitely should be linearly interpolated (with GL_NEAREST problem disappears of course). But I want single 'instance' of 'B' to behave like it was GL_CLAMP_TO_EDGE'd.

'Shrink texture coordinates so that border texels are not drawn' trick won't work (texture is repeated and it wouldn't cover A's texels), nor texture with pixel borders (it falls back to software on my R9600 Pro).

Thanks in advance for any suggestions.

Relic
04-11-2005, 10:35 PM
This is the usual texture atlas problem. There is no setting to limit the linear interpolation in mid-texture. That's how the hardware works.

You can work around the issue by using nearest filter texture lookup in a fragment program which calculates the texture lookup modulo your texture tile size and position and does its linear filtering manually.

Topquark
04-12-2005, 06:28 AM
Thanks for the advice, I suspected too that it can't be done with regular OGL functionality.
So it seems I'll need an 'if' instruction to check if current tex coords are in range (0.5/texwidth; 1-0.5/texwidth)... I hope this won't lower performance much.

3B
04-12-2005, 12:02 PM
If I read correctly, you aren't actually doing a texture atlas, so you don't need any complicated math in the shader. Seems like setting GL_CLAMP_TO_EDGE and then using a shader to chop off just the fractional part of the texcoord and use that to sample the texture should work.

Topquark
04-12-2005, 03:44 PM
I've just implemented it just like you wrote, 3B, and it's working perfectly.