Ideas for adding water to our engine?

Started by
4 comments, last by GalacticCrew 5 years, 8 months ago

I am the lead developer on a D3D11 game (using pixel and vertex shaders) that has water done as a flat mesh with textures on it (we use something similar to bump mapping to produce the water effect as well as scrolling the texture) but we want something better. Are there any tutorials on how to get cool looking water in a game? Particularly I am interested in refraction (whatever it is that lets you see what's under the water but the water obscures/distorts it a bit) and that kind of thing rather than reflection or wave motion.

 

Advertisement

You can copy the final image to a buffer. Render the water plane converting the 4 coordinates to screenspace so that the water plane matches the final texture exactly. Then run a distortion image to distort the  underlying objects. This can be as simple as a black and white texture that is a noise texture and you can offset the current pixel by the noise texture amount. As long as you keep depth testing on etc, it will only distort pixels where water renders.  Honestly, it depends on what technique you want to mimic. I would look at some games or youtube water rendering demos and see which one is easiest that you like.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

It's Java and OpenGL but the concepts are the same regardless of API, should be very simple to transfer over to D3D11.  It's an 8 part series:
 

 

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This all depends on what kind of effect are you going to achieve.

 

There is vast difference between dynamic water (flooding, etc.) and static water (ponds, lakes, ocean, rivers, puddles, etc.). I assume you want the latter - focusing on rivers, ocean, etc. You will find out that (if possible) you will need a separate solution for each case (at least in my engine it has been separated), each using a bit different shaders and maps - ends up in acceptable result. There is no solution that would 'rule them all'.

 

Generally each water surface will have refrection & reflection. For larger water surfaces you will need to calculate also color (greenish/blueish effect that depends on depth of water), some will require large waves (ocean - I believe tessellated FFT based ocean is still state of the art), smaller just bump maps. Rivers will also require flow maps and particles. Fluid dynamics can make this more alive.

For reflection you want to use cubemaps (puddles, rivers) and plannar reflections (ponds, lakes, ocean) ... or raytraced/voxel based if you can afford those (cheap screen space ray tracing works too).

For refraction - just render your scene without all water, that should be enough for refraction - use camera matrix to project this to water surfaces when rendering those, and with help of normal/dudv/flow maps - do a distortion.

Mixing between refraction and reflection should be based on fresnel.

 

If you have any particular question - feel free to ask specifically (i.e.'How to do reflection' or 'How to animate rivers'). I'll try to answer in detail.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Hi, I'd like to link you this tutorial and also this tutorial! They include reflection, moving water, etc.

This topic is closed to new replies.

Advertisement