1
\$\begingroup\$

I want to do a simple simulation of water drops producing waves in OpenGL with C/C++. I calculate height for each point of my plane grid in Vertex Shader with formula enter image description here but it seems wrong at the beginning. I will atach a photo to ease the understanding:

enter image description here

This is how the grid looks like at time = 0 (when the drop touched the water). The waves weren't generated only near the touch point and gradually advance. In the corners of the grid (and far from the touch point) there should be no change until a created wave approaches.

\$\endgroup\$
  • \$\begingroup\$ That's expected to happen. \$\endgroup\$ – user3042253 Dec 20 '16 at 16:20
1
\$\begingroup\$

Try using a variable for amplitude (max height of wave). Pass it to shader. Vertex shader in your case. Multiply it to vertical component. (Some people use y-axis as vertical axis, while others use z-axis as vertical axis)

Initially set it to 0. When ball falls in fluid, set it to a value. And then multiply the that variable by constant less than 1 (for instance 0.97). Multiply it every frame. This will emulate decay.

Edit: for 's stated goal "In the corners of the grid (and far from the touch point) there should be no change until a created wave approaches."

Create a function such that

if 0 < r < attenuation distance then

Final height = amplitude variable (from above) * sqrt( power(x - ball.x,2) + power(y - ball.y,2)) / attenuation distance

If r > attenuation distance then height = 0

\$\endgroup\$
1
\$\begingroup\$

You could try to multiply the height by 0 outside the (increasing) radius of the 1st wave.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.