Jump to content
  • Advertisement
Sign in to follow this  
DrewGreen

OpenGL Breaking waves on shorelines

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, The other post on here about shorelines reminded me of a feature I would like to implement for my game but am not sure about. I was inspired by this image and would like to replicate the surf, except in realtime. Bit of background about my program screenshot here and here.. be nice, it's nowhere near finished The landscape uses a standard heightmap, and I currently have a single quad covering the visible terrain acting as water. I see no reason to increase the polycount of this to produce a wave effect as it will not add much to the overall visuals & will just be wasting polygons I could put to better use elsewhere (and there is a lot of stuff to put into this yet) The helicopter is constantly moving across the terrain, in a similar fashion to Virus or Zeewolf, the game I am trying to do a remake of. I have thought that one such way of doing this would be to have a particle system periodically shoot a few polys out from the shore with a textured image of some surf according to where the water plane intersects with the shoreline, and if all else fails this is the method I will choose to use, although I can't think of a good way to make the individual particles look more like one big piece of water instead of just a load of particles. I would like to pick your brains on whether there is a better way to achieve this effect? How would you do it? I'm not looking to model water movement accurately, just good enough. It would be nice to see the surf gradually move into deeper water & blend together in the same way as shown in the deviantart image although this may be more trouble than it's worth, and it's a feature I'm willing to scrap. I am using OpenGL if it matters, and would like to avoid using shaders if at all possible. Reading back over this I suspect I've answered my own questions (at least the ones in my head) but I'm clicking submit anyway, if anyone's got any tips/suggestions or has done something similar I'd really like to hear from you. Many thanks, Drew

Share this post


Link to post
Share on other sites
Advertisement
Pass the elevation of the terrain into the pixel shader and animate a surf texture over time.

Share this post


Link to post
Share on other sites
Thanks for that, it makes a lot of sense, however I have no knowledge of shaders (this is a separate question though). Guess I'll go and find out!

Share this post


Link to post
Share on other sites
Hi,

This old forum post might be of interest for creating surf/foam
Foam

Sadly the pictures are no longer available, but I have an offline copy I can send you if you like. PM me with an email address.

BTW. You'll want to tessalate your water quad at some point as a single big quad over a terrain of smaller quads/traingles is likely to exhibit zbuffer precision issues.

Share this post


Link to post
Share on other sites
Modelling water at the shore is an extremely difficult task and I am not aware of any work actually succeeding in this (at least in realtime on common hardware). The work by noisecrime gives brilliant results and I suggest you to implement that technique for its simplicity. I think FarCry uses a similar approach.

Personally, I am investigating a novel technique to model the behaviour of water at the shoreline, where a different physical model (other than the FFT-based one) applies. My idea is that of modelling the shoreline with a spline. The spline control points are estimated in the neighbourood of the intersection between the water plane and the terrain.

Water is usually drawn (at least in my engine) as axis aligned quads but, ideally, it should be oriented point by point in the direction of the spline (that is, the shoreline). This alignment affects both the geometry (waves roll towards the shore) and all texturing effects (foam included). This requires a parametrization that remaps every (x,y) point of the quad to two parameters (u,v), where u is the distance from the spline, and v is the distance along the spline. These (u,v) parameters are used in place of the (x,y) for texturing. The required remapping is explained in <url>http://wscg.zcu.cz/wscg2005/Papers_2005/Full/C61-full.pdf</url>
We can store these parameters (u,v) in a texture. Additionally, we can store in this texture the depth of water, useful to distinguish shallow and deep water in the shaders.

For a foam effect, this texture is then accessed and the u,v parameters are used to align an animated foam texture to the shoreline in a pixel shader. On shader model 3.0 we can also access this texture in the vertex shader and use the water depth to change the appearance of the waves (i.e. waves become steeper and steeper until the break). Trochoids are quite handy for this.

Hopefully in the future I will find the time to try this approach in my engine.

Share this post


Link to post
Share on other sites
Just like to point out the foam tutorial was not written by myself, or anything to do with me at all. I just posted the link to the thread since it was something I had remembered and thought would be of interest.

Share this post


Link to post
Share on other sites
Thanks for the replies, I'll definitely look into those two. I checked out Cg & got a couple of free shader designer programs but as I suspected, my card doesn't support very many modes unfortunately.
As for the z-fighting, I fixed that by modifying the view frustum before drawing the water. It's not perfect but it works for my needs.

explanation here - http://www.codemonkeysoftware.net/content.php?article.1

I have just been playing the age of empires 3 demo & got some ideas from that as well. From what I can tell just by looking, the foam is a static image, and a plane moulded to the shoreline shape moves across the water. As it does so the texture coordinates are shifted in the opposite direction to the movement (so the foam appears not to move), and fades out on the trailing edge. It does look quite good but you can sometimes see hard edges which give the technique away. (useful for me!)


edit: also I went looking for that paradise island demo & it's now at http://indago.gamez.lv/i2004/?incl=sala.html .. I'm jealous :D

[Edited by - DrewGreen on September 8, 2005 9:30:41 PM]

Share this post


Link to post
Share on other sites
Moving waves along the beach would be very difficult to make without additional geometry. Or really shader intensive.
You could tesselate your grid, and store texture coordinates for the wave texture - one coordinate is the distance to the shore, but the other is not so trivial to compute.
On second thought - you can tesselate the water into regular grid, evaluate distance to the nearest shore for every vertex (those that are beneath the terrain are 0).
Then, get the vertices that are 0 (beneath the terrain), but have non-0 neighbours - and make a contours from them.
Then collect their neighbours, with 0 < x <= 1 values - create contours from them too.
And so on - extract as many contours, as you want. Like onion.
Then, walk each contour, compute length from the start and assign U-texture coordinate. V texture coordinate will be the number of the onion-contour.. :)
This can be made to look good, especially if contours are smoothed (their u,v-s) by spline.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrewGreen
As for the z-fighting, I fixed that by modifying the view frustum before drawing the water. It's not perfect but it works for my needs.

explanation here - http://www.codemonkeysoftware.net/content.php?article.1
Actually, pushing out the near plane is the preferred method of combating depth buffer issues. You should try to have the near plane as far away as possible and the far plane as close as possible, but the far plane distance doesn't have as much of an effect on depth precision as the near plane distance. Read here for more info. It's OpenGL-centric, but it applies equally to Direct3D.

Share this post


Link to post
Share on other sites
Breaking waves curl on top of other water; therefore, a heightfield is incapable of representing the geometry. There are all kinds of research to check out going back decades. It's not easy. Good luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!