kRogue

02-15-2011, 01:39 AM

Hi all,

This might seem like an odd request and I also have concerns about if it can be reliably implemented.

Here goes: to derive the "texel relative location" from a texture coordinate, what I mean here is how far

across the nearest texel to use is for a texture coordinate.

Naively one could try this:

texel_location=fract( textureSize(my_sampler)*normalized_texture_coordin ate);

to get values in the range [0,1]. However, the above is horribly numerically unstable

near the boundaries of the texels.

Replacing the above though a texture look up to remove the integer part:

/*

pos_sampler is a texture with all filtering set to GL_NEAREST

and the image data as point p is the value at p

*/

texel_location= textureSize(my_sampler)*normalized_texture_coordin ate - texture(pos_sampler, normalized_texture_coordinate)

However this is moderately unstable too, as when one scales one can see "shimmers" (but much less than fract)

The ugly issue is naturally near 0 and 1. Indeed if the nonnormalized value is near an integer, then a small difference can dramatically affect the value in both approaches.

The goal here is to get that interpolation value consistent with from which texel the GL implementation samples, it is ok if different implementation choose different texels in the boundary case, but I want to have a way of getting that interpolate reliably across GL implementations.

This might seem like an odd request and I also have concerns about if it can be reliably implemented.

Here goes: to derive the "texel relative location" from a texture coordinate, what I mean here is how far

across the nearest texel to use is for a texture coordinate.

Naively one could try this:

texel_location=fract( textureSize(my_sampler)*normalized_texture_coordin ate);

to get values in the range [0,1]. However, the above is horribly numerically unstable

near the boundaries of the texels.

Replacing the above though a texture look up to remove the integer part:

/*

pos_sampler is a texture with all filtering set to GL_NEAREST

and the image data as point p is the value at p

*/

texel_location= textureSize(my_sampler)*normalized_texture_coordin ate - texture(pos_sampler, normalized_texture_coordinate)

However this is moderately unstable too, as when one scales one can see "shimmers" (but much less than fract)

The ugly issue is naturally near 0 and 1. Indeed if the nonnormalized value is near an integer, then a small difference can dramatically affect the value in both approaches.

The goal here is to get that interpolation value consistent with from which texel the GL implementation samples, it is ok if different implementation choose different texels in the boundary case, but I want to have a way of getting that interpolate reliably across GL implementations.