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

## Recommended Posts

Im looking for a way to apply a sine wave deformation on a texture since Im using very few vertices I would like to achieve this with a fragment shader

##### Share on other sites
What's the problem? Just call sin() in the shader

##### Share on other sites

What's the problem?

The problem is that I have no idea how to "actually" pull it off

##### Share on other sites
there's too little information in your initial post for us to know what you want, what you got and what you need. Make those three points clear to us and we might be able to help. Note that we cant do mindreading so you need to provide as much details as possible for us to understand you.

##### Share on other sites
It sounds as if you're after something along the lines of displacement mapping, I don't know how to do that myself, but it might give you a place to start searching, at least.

##### Share on other sites

my only problem is that the waves are very slow. I am not sure if this is because Im using rendermonkey or maybe its my code

anyways heres the code

uniform float fTime0_X;
uniform sampler2D Texture0;

varying vec2 texCoord;

void main(void)
{
vec2 aux = texCoord;

aux.x = aux.x + (sin(aux.y*fTime0_X*.5)*0.05);

gl_FragColor = texture2D( Texture0, aux );
}

##### Share on other sites

....
my only problem is that the waves are very slow. I am not sure if this is because Im using rendermonkey or maybe its my code
....

the speed get's determined by fTime0_X*.5, the sin function takes radians as input, one periode (so 1 wave: pixel moving to side, to other side and back) takes 2*pi which is somewhere around 6.28, assuming fTime0_X is measured in seconds, one wave will take just over 12,5 seconds because you multiply it by 0.5.
So you should change that 0.5 to alter the speed, the higher the value the faster the waves (unless you go over the framerate offcourse, then it will look like it goes slow in the other direction, just like the blades of a helicopter look like to change direction a few times when starting up but i don't want to confuse you ).

To calculate the value use factor = (2*PI) / s where s is the number of seconds you want it to take to complete one wave.

EDIT: There is also an error in your calculation that will (probably) cause unintended behaviour, you have aux.y * fTime0_X * .5 which should be aux.y + fTime0_X*.5 the way you have it now aux.y also defines the speed, but instead it should just specify the offset, i made an image for you in which i try to explain the functions of the different parameters and the effect they have on your animation.
I'd suggest implementing the formula as i put it in the image and toy around with the different factors to see the effect they have on the result.

I love you

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×