Sign in to follow this  
EvilNando

sine wave shader

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 this post


Link to post
Share on other sites
[quote name='rdragon1' timestamp='1311640833' post='4840298']
What's the problem?
[/quote]

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
[IMG]http://i38.photobucket.com/albums/e121/evilnando/rendermonkey1.png[/IMG]

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

[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 );
}[/code]

Share this post


Link to post
Share on other sites
[quote name='EvilNando' timestamp='1311718563' post='4840838']
....
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
....
[/quote]

the speed get's determined by [b]fTime0_X[/b][b]*.5[/b], the [b]sin[/b] 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 [b]fTime0_X[/b] 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 [b]factor = (2*PI) / s[/b] where [b]s[/b] is the number of seconds you want it to take to complete one wave.


[b]EDIT:[/b] There is also an error in your calculation that will (probably) cause unintended behaviour, you have [b]aux.y [u]*[/u] fTime0_X * .5[/b] which should be [b]aux.y + fTime0_X*.5[/b] 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.

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