Advertisement Jump to content
Sign in to follow this  

OpenGL ARB Vertex Program: Reversing Tex Coords?

This topic is 4968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a vertex program for water, and what I want to do is have ripples flowing in opposite directions. I have the texture coordinates flowing in one direction by modifying the tex coords outside of the fragment program using standard OpenGL calls, and I figured I could simply multiply fragment.texcoord[1] by a negative value and make it flow the other direction. Apparently that isn't the case, or I'm doing something wrong. I can multiply it by different values and change the scale, but if I try to use negative numbers, the flow continues in the same direction as when they were positive. I've tried negating each component individually as well as various combinations, but nothing seems to work. Is my logic wrong, or can this simply not be done?

Share this post

Link to post
Share on other sites
I don't get what you're trying to do but try 1.0-fragment.texcoord[1]. Maybe that's what you want.

perhaps a clearer explanation would help me out...

Share this post

Link to post
Share on other sites
Ok, it looks like it wasn't doing what I thought it was doing.

Let me show some screenshots to better explain. I have a reflection texture that I'm distorting. I changed the distortion texture to be just an arrow, so you can see what it's doing.
The texture is "flowing" in the direction the arrow points.

This is what happens when I scale it by 10:
Now the arrows are smaller, as one would expect. But then, when I scale it by -10, I get this:
The texture is flipped, as you would expect, but it still flows in the same direction (not the direction the arrows are pointing).

Soooo.... my logic is just wrong. How would I get it to flow in the opposite direction without adding another texture unit with a new set of coords?

Here's the program, by the way:

PARAM half = { 0.5, 0.5, 0.5, 0.5 };
PARAM inv = { -1.0, 1.0, 1.0, 1.0 };
PARAM scaleFactor = { 4.0, 4.0, 4.0, 4.0 };
PARAM testScale = { -10.0, -10.0, 1.0, 1.0 };
TEMP distortColor;
TEMP distortColor2;
TEMP texcoord1Inv;
TEMP distortCoord;
#SUB texcoord1Inv, half, fragment.texcoord[1];

MUL texcoord1Inv, fragment.texcoord[1], testScale;
#MOV texcoord1Inv, fragment.texcoord[1];

TXP distortColor, fragment.texcoord[1], texture[1], 2D;

TXP distortColor2, texcoord1Inv, texture[1], 2D;

#ADD distortColor, distortColor, distortColor2;
MOV distortColor, distortColor2;
SUB distortColor, distortColor, half;
MUL distortColor, distortColor, scaleFactor;
ADD distortCoord, distortColor, fragment.texcoord;
TXP result.color, distortCoord, texture, 2D;

Don't mind the mess -- lots of testing. Half the code doesn't do anything. This is the first time I've touched fragment programs.

Share this post

Link to post
Share on other sites
I figured out how to do it -- just passed an offset parameter. Sorry, I'm new to fragment programs. A whole whopping 2 days of experience. ;)

I'm making good headway, though, but I've run into something that baffles me. Currently I'm using 2 textures. One that reflects and one that distorts. I bound a 3rd texture -- I haven't enabled it or changed any of the fragment program code at all. I just bound it. Yet, somehow, it's changing the effect of the fragment program.

Before (2 textures bound):

After (3 textures bound, 3rd completely unused):

(the distortion is considerably more subtle)

I don't get that. Why should binding a 3rd texture have any effect whatsoever?

Edit: Nevermind. I'm not sure what I did exactly, but I fixed it. Something with the way Q2 handles multitexturing -- it was setting it to the wrong texture unit.

[Edited by - jitspoe on June 15, 2005 12:35:41 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!