Sign in to follow this  
jyk

Strange texcoord scroll problem

Recommended Posts

jyk    2094
Hi, I have a strange problem with texture coordinate scrolling. I'm trying to implement simple scrolling as a function of time, like this: glMatrixMode(GL_TEXTURE); glPushMatrix(); glTranslatef(scroll[0] * time, scroll[1] * time, 0.0f); Now if I normalize time first, like this: time -= (int)time; It works fine. But if I leave time unnormalized (i.e. any arbitrary value), I get strange tearing and jittering artifacts - the texture shakes back and forth as it scrolls, and tears at the triangle edges. Very weird. I've studied several other engines that incorporate texture scrolling, and most of them do not normalize the time. So I guess I must be doing something else wrong? I imagine quite a few of you have implemented this sort of texture scrolling as part of a Q3-style shader system. Has anyone else encountered this problem?

Share this post


Link to post
Share on other sites
Lutz    462
I had a similar problem with texture jittering. The reason could be is the following:

The time function I know measures the seconds elapsed since 1970 or so, so it's usually a very very large number. The texture coordinates on the GPU are only stored in single precision and only the fractional part of the texture coordinate is important for texturing (I assume you have GL_REPEAT enabled). But the integer part of time is a very large number, so the fractional part does not have enough precision to be properly resolved. Even if your "time" is double, it gets converted to float by glTranslatef and the precision problem arises.

If time is e.g. 1000000.25, the next machine number greater or equal to time might be 1000000.30, so your texture coordinates would scroll in 0.05 steps, which is much too much for smooth scrolling.

Normalizing time is completely feasible I guess.

Share this post


Link to post
Share on other sites
jyk    2094
Thanks for the very helpful reply! I was under the impression that on my system (Mac), time is measured in microseconds since machine startup, but I should double check that.

In any case, precision issues could definitely be to blame. Most of the other Q3-based engines I've looked at don't normalize the time, though. And normalizing the time does seem to cause problems with some combinations of scrolling and turbulence (the texture 'jumps' occasionally). I guess I'll just have to keep messing with it.

Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this