sine wave shader

Started by
6 comments, last by EvilNando 12 years, 9 months ago
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
Advertisement
What's the problem? Just call sin() in the shader

What's the problem?


The problem is that I have no idea how to "actually" pull it off
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.
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.
rendermonkey1.png

I finally made it happen...

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 );
}


....
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

This topic is closed to new replies.

Advertisement