Advertisement

3D Water

Started by May 22, 2000 12:46 AM
20 comments, last by Jallen 24 years, 8 months ago
You could ry using the old 2d water effect. A good explanation is on Hugo Elias''s web page.

http://freespace.virgin.net/hugo.elias/graphics/x_water.htm

You could either write the results to a texture, or you could turn it into a 3d heightfield and actually move the vertices up and down.
You could use a quad tree sort of thing and just change some of the vertical points to do waves, ripples, and stuff. And remember to use triangle strips when rendering your water (you won''t loose so much performance).

Morgan
Advertisement
Hi Jallen!

Water in Half-Life:

You start out with a grid of vertices. This is basically a heightmap of your water. You animate it using a sin()-function (use lookup-table). This will make the y value of each grid vertex oscilate. Now, you definitely want to put some randomness in there, or otherwise it looks crap. For example, neighboring vertices shouldn''t move up at the same time, etc... Please, don''t try to use bezier patches for water, they are a bit overkill.

I guess two alternatives to this technique exist:

1. If you want the water to be interactive, you will probably have to resort back to the 2D Water method, and use the intensity for your y-value. A link explaining 2D Water has already been posted, so you should have enough information on this subject matter.

2. Procedural textures ... Ever played Unreal/UT. There, they use the 2D water effect to distort a texture. In OpenGL you would have a texture object for your effects texture. For each frame, you would update the effect texture, then select the texture object, use glTexSubImage (I think there was a 2D in there somewhere, like glTex2DSubImage...) and upload the updated texture to the card. So, it IS possible, to do procedural textures, even when you are using texture objects.

I''m not sure if this was such a big help, but it should clarify a few things. Environmental bump-mapping is a bit too hardware specific for my taste (some goes for all hardware bump-mapping techniques), so you shouldn''t go that way. Try something simple first (although you DID start with bezier surfaces).

Happy coding,

Marco Koegler
Thanks for all the replies people , I really appreciate it.

rivit: I don''t quite understand what you are saying, make a moving texture at various stages and write it to a file (water001.bmp, water002.bmp, etc..) then just use a different texture every frame to make it look like the water is moving? This idea has some possibilities.

Anon: thanks for the link, there is some good stuff on that website, I am definetly gonna look at this, see if its any good.

Morgan: whats a quad tree? not familiar with that structure

MK42: I''m not really interested in having interactive water although this would be a very cool thing to have. I am mainly interested in having semi-realistic texture-mapped moving water that is fast, yet still looks good.

I will look into your idea of using sin/lookup tables. I had previously done this but couldn''t get the result to be random enough, look fairly stupid. The hardest thing is making it look good, its certiantly fast enough (with lookups especially).

For procedural textures do you mean updating only certian parts of the water texture using glTex2DSubImage or replacing the whole water texture as rivit was suggesting, using different water frames?

I agree with you on the bump-mapping part , not what I want to do. Your ideas have helped and thanks again.

Jason A.

---
I write code.
---I write code.DelphiGL (http://delphigl.cfxweb.net)
Quad trees are ways of dividing up the space your objects are in by sub-dividing it by four each time.
so you start off with an area this is divided into four equal segments. If any of those segments contain objects they are subdivided into four segments and so on.

It''s something that came before BSP trees.
Octrees were more common, but quad trees are similar...

Check out my shadows page
and send me some feedback
Check out my shadows page and send me some feedback
Yes, that''s what quadtrees are, but you can also use them to create meshes for terrain, water, etc (check out http://www.gamasutra.com/features/20000228/ulrich_pfv.htm as an example).

Morgan
Advertisement
Cool, while browsing Game Developer''s magazine source code section i found a up to date version of the 2d water effect mention above by Anonymous Poster. Here is the link (wish I know how to make it a actual link but oh well).

ftp://ftp.mfi.com/pub/gamedev/src/dec99.zip

Inside is the full source code to a MFC application that demonstrates all the principles of this effect. You can click on the image to add a water drop which ripples outward and looks very cool.

Jason A.

---
I write code.
---I write code.DelphiGL (http://delphigl.cfxweb.net)
you sort of have it ,but i ment....what functions i found on bryce 4 conserning wireframes..[openGL/stee3D/direct3D]
i normaly draw with defalt wireframe salected.but if to say i did my animation of a slab of water that has a slight rippl to it, as well as the rippl i put light or eddit the texture batween sertin fraims ,thus adding more movement of the water,(I use terrains for water slab as you can get better efects in animation,as well as it looks more real)
yousing openGL would that not just fit nicely into place?

im not sure im on the right track,but its a thort..
Do you mean using textures or somehow get the actual wireframes from Bryce?

Jason A.

---
I write code.
---I write code.DelphiGL (http://delphigl.cfxweb.net)
Jallen:

With the procedural approach you have a 128x128 or 256x256 texture. This will be your working texture. Every frame you draw the 2D-Water distortion into this texture. Then in OpenGL you have a texture object associated with this effects texture. Normally you can free the texture memory after passing the data to OpenGL, but not for this texture, since you need some space where you can store the 2D-Water effect output. glTexSubImage2D (<- correct name) replaces the data OpenGL associates for a texture object. So, it allows you to modify the contents of a texture. You use it to upload the updated version of your effects texture to the card. Short example:

Frame 1:

Generate initial water effects texture.
Download it to texObject1

Draw water surface

Frame 2:

Update water effects texture in memory
Use glTexSubImage2D to update texObject1 data

Draw water surface

...

Pretty simple. The hard part is makeing the "Update water effects texture" fast enough, which can be hard. This is usually the basic 2D water algorithm applied to a texture map.

Hope this clarifies some things,

MK42

This topic is closed to new replies.

Advertisement