# Good 2D ripple

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

## Recommended Posts

I've only done 3D this far, and I'm trying to figure out how to make a good quality 2D ripple effect, with multiple ripples of course. Something like this:
">
I know how to create 3D ripples as displacements based on sine waves and distance from the ripple point, on a heightfield grid representing the surface, but how would I do this 2D effect instead, morphing smoothly the high resolution 2D layers underneath in real time? The only idea I have is to have the ripple in a GLSL shader and displace texture coordinates by a proportion of the gradient of the ripple surface--but how to calculate said gradient? [Edited by - Prune on March 4, 2008 10:04:56 PM]

##### Share on other sites
Why wouldn't the math be the same, but you don't need Z axis now. Just calculate xyz and use the two axes you need?

##### Share on other sites
Something like was discussed here:

http://www.gamedev.net/community/forums/topic.asp?topic_id=483575&whichpage=1�?????????

##### Share on other sites
Quote:
 Original post by MARS_999Why wouldn't the math be the same, but you don't need Z axis now. Just calculate xyz and use the two axes you need?

Because there's only Z displacement in a 3D wave. XY are not displacements of the surface; the warp of the texture underneath in the 3D case comes because the normal of the surface is changed and the lookup into the environment map moves.
So, I still don't know how to compute the normal from the Z displacement (least of all efficiently--do I take partial derivatives of the sine/circle function used for the waves and plot those, or take values of the function at offsets and get derivatives by differencing, or add another pass and store the heightfield and then get the differences by dFdx() and dFdy()?)

##### Share on other sites
Never mind, I got a good result.

Just one thing I'm not sure of: if I'm using a non-square texture, then the change in texture coordinates for a given world space distance is not the same for one direction vs the other. So should I multiply one of the offset directions by the texture aspect ratio? Specifically, in my case I have texture that's mapped to a plane covering my screen, but sampler2D() uses 0-1 texture coordinates, and when I add offsets to the texture coordinates, shouldn't I multiply the Y one by the width/height ratio of the screen then, since the X texture coordinate moves more in world space for a given offset than the Y?

1. 1
2. 2
frob
20
3. 3
Rutin
17
4. 4
5. 5

• 13
• 10
• 9
• 18
• 9
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007035

×