Archived

This topic is now archived and is closed to further replies.

Moe

Water in games?

Recommended Posts

I have really been thinking about how they do water in games lately. In my game/engine I would like to have an island surrounded in water, and perhaps an inland lake. I have been thinking of the various ways of actually drawing the water. I think the best method by far would be to use large patches of triangles, kind of like a heightmap, but for water. The water could have waves, which would look a lot better than a giant textured plane. The problem with using patches of triangles for water is that they would need to interact with eachother. Suppose the one chunk of water had a wave in it, and that wave was going to splash into the next chunk of water. How would this be handled? I recently had the chance to see a game called ''Jak and Daxter'' for the PS2. I think they did a pretty good job of the water in the very early levels. The water had waves, and wasn''t square against the shore. How is it that water is done in games like this, and like Halo?

Share this post


Link to post
Share on other sites
er i think to make this problem not an issue you could just not use patches just use one big patch and put it in a quadtree or something.

-David-

Share this post


Link to post
Share on other sites
Gamasutra had an article on this, i practically passed-out when reading the math. And i think it''s very hard (read impossible) to do realtime.

Article

----------------------------
"Quotes are cool" - Me

Check out my game Asteroidz, it rules !!!

Share this post


Link to post
Share on other sites
gamasutra''s article was for crazily realistic water - the screenshots looked like photographs, almost.

There is a kind of simple method that Baldur''s Gate and some other games use. They represent the water as a heightfield, as you suggested, and then in every frame, they go through each segment of water and move it towards the average of the segments around it. To make a wave, all you have to do is depress one square and let go. The next frame, the segments surrounding it will go down and the original segment will go up. The next frame, the third ring of segments will go down, and the inner segments will behave in the same way they did before - eventually the wave will start to repeat, and you get a ripple.

To make a straight wave, just depress a whole line of segments to begin with, etc. This works pretty well for modelling characters walking through ponds and such, but it has some limitations - waves can never crest, for example, and you''ll have to use a separate particle engine or something if you want splashes.

Share this post


Link to post
Share on other sites
Yeah, I have seen that article before, but I never took a very deep look into it (sorry for the pun). It is pretty crazy looking water. I think i will do something simple like specular lighting with a sphere map. If I wanted something a little more crazy looking I would go for a bump map and gloss mapping, perhaps with a cube map thrown in.

The problem is connecting the patches. David20321 had an interesting suggestion by using one giant patch with a quadtree or something. The problem with this is that it would be hard to determine where the water was under the terrain, and when to render it. It could end up taking alot of time telling whether the water was under the terrain or if it was above.

Moe''s Site

Share this post


Link to post
Share on other sites
I think you shouldn''t store every vertex of the water, but rather generate them from a "wave" algorithm. Just give a starting point and height, and move through the "square" from that point on. And just use rectengular pathces ^_^

-Maarten Leeuwrik
=================
[Illiad] J.R.R TOLKIEN ACHIEVES 40,000 RPM IN GRAVE

Share this post


Link to post
Share on other sites
I''ve also been looking into the water thing. Besides the (really nasty) article on gamasutra, you may want to check out the past programming contests on flipcode - there was one devoted to water effects. Also search on www.siggraph.org. Some really good stuff there.

---
Matt Benic

"Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning."

Share this post


Link to post
Share on other sites
Yeah, I remember the contest at flipcode. I will have to check that out in greater detail and perhaps fire of a few e-mails to the coders of the entries.

Moe''s Site

Share this post


Link to post
Share on other sites
The article on Gamasutra isn''t that evil. It''s pretty neat, if you get the concepts. And you don''t have to implement every bit they described, since it is a collection of different wave synthesis algorithms, just pick the one you need. I tried the first one, the FFT. The math isn''t that bad, it''s just more or less standard fourier transforms with a frequency/phase generator. And the results are extremely good, you can do some shortcuts (replace some of their expensive equations with simpler and faster ones) and it will still look very good.

I also tried to write a 2D Navier Stokes solver. It works rather nice (very realistic interaction with objects), but unfortunately it is rather unstable. Making it stable with the method they suggested (adaptive relaxation) dropped the FPS from 52 to 3...

The shallow wave thing in the article is somewhat overkill IMO. I didn''t try to implement it.

Share this post


Link to post
Share on other sites
There is one problem of mine that the article doesn''t cover, and thats mixing terrain with the water. I need a way to figure out when I should be drawing the water and when I shouldn''t.

I think the water in that article looks especially good because of the fancy textures.

Moe''s Site

Share this post


Link to post
Share on other sites
> There is one problem of mine that the article doesn''t cover, and thats mixing terrain with the water. I need a way to figure out when I should be drawing the water and when I shouldn''t.

What do you mean ? HSR on the water ? Or cutting out the outlines ?
If you mean the later, then it depends. It can be very easy to extremly difficult. If your water is heightmap based, then just don''t draw the tiles that won''t be in an external outline, with some overlap with the terrain, to avoid holes.

I had very big problems, when it came to include objects floating on the water. Eg. a simple boat. Since the boat has geometry under the waterline, the water surface would always pass through the boat object, very ugly, looked as if it would fill with water and sink any moment I still didn''t solve the problem 100%, since it would require a realtime boolean operation between the boat object and the water plane...

> I think the water in that article looks especially good because of the fancy textures.

Hehe, the water in that article isn''t textured... It''s gouraud colour shaded with an additive bumpmap (using a realtime NSE bumpmap), and reflection + refraction maps. But there is no ''standard'' texture map on the water.

Share this post


Link to post
Share on other sites
Hi,

I dunno, if this of any help to you, but i remember reading some article on a flipcode members site about a realtime raytracer, he had produced water by creating a large plain of small triangles and altered the normals of the triangles in a pattern to create the effect of water with the reflected light

Share this post


Link to post
Share on other sites