Sign in to follow this  
Prune

Good 2D ripple

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: http://www.youtube.com/watch?v=MV_xkz5D22w 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 this post


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


Link to post
Share on other sites
Something like was discussed here:

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

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
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?

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


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

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