Strange problem in Circular sine wave( ripples) implementation

Started by
0 comments, last by Manpreet 13 years, 5 months ago
hey everyone!

I'm trying to make a basic ripple effect in HLSL. So I'm using the following equation(please correct me if I'm wrong)

Current Vertex Height = A * sin( kr - wt)

with this equation , i am able to generate basic sin waves along x and z axes.

For generating ripples i replaced r with
r = sqrt(x2 + z2) , where x and z are the respective x & z coordinates of the point.


The problem is that when i use this value of r (ie the sqrt one), im getting strange random oscillations which clearly do not look like circular waves , but when i remove the sqrt and instead write this

r = x2 + z2

i get, with some adjustment to the value k , perfect circular waves , although now i have to adjust the value of k with a increment/decrement factor of 0.000001 !!!!(earlier with sqrt it was 0.0001)

the values that i use are(all floats)
A = 25
K = 8
w = pi/2

and one more thing , im incrementing the time t by 0.01 every iteration

and heres the code outline (using HLSL ,by the way)
	.....	ConvertToradians(t);		float term = input.position.x * input.position.x + input.position.z * input.position.z;		float amp = 25.0f;		input.position.y = amp * sin(k*term - (w * t));		output.position  = multiply(input.position,ViewProjectionMatrix);	        .....		



Can anyone please explain why is this happening? I've seen a similar example in the DX SDK Samples and in there they have used the length() function , which i think still calculates squareroot.Even in many other samples that i checked on the net , sqrt is used.

Is this due to the values that I've used??

thanks!

Advertisement


well it seems that the problem was in the value of the angular wave number(ie k) that i had chosen. I had initially set it values like 4.0f , 8.0f etc . But it turns out that choosing 0.1f and then adjusting with a factor of 0.001 is working

Sorry for wasting your time again ,gamedev people :)

And thanks for reading!

If you have anything else you would like to add/comment please do so.

This topic is closed to new replies.

Advertisement