Water... I need help

I searched the forums (maybe not hard enough :? ) looking for help with adding water to my scene.  Didn't find anything.  Does anyone have some source code to add water with reflections and such?  I was going to read the technical article on the projected grid stuff, but my math skills in that area are, um, lacking.

MonkeyWorld3D already has some water and it's open source, I believe - don't know if that's fancy enough for you…

MrCoder has done that incredible projected grid water effect but it was not released to the public (yet?).

i'm working on making the simple version jME enabled as we speak…flat waterplane but with reflections etc. shadersupport needed though. the projected grid version will follow if i get permissions from work…

This is very funny.



I just ment to as MrCoder for something like that.



We have some real simple water in MonkeyWorld3D, but could do with something that



handles reflections or more.



I am busy with the terrain realtime texture painting, and must say things are going



good!

Sweet.

I’ve been meaning to put this up for a while - I’ve got most of a shader based water surface in aircarrier, but it was in an older game framework, and I set it aside to concentrate on getting the game working rather than fancy effects.



However, if you check out the project at aircarrier.dev.java.net and run net.java.dev.aircarrier.CarrierTerrain you should get reflecting/refracting/rippled water, which looks quite nice (there is a screenshot on the page). The game itself is not right, I just hacked it about enough so it would run and show the water. If you want the game running properly, run CarrierSimpleLevel - no water there though :wink:



The water does most stuff and looks quite shiny, but it is missing:


  1. Fresnel. At the moment, reflection and refraction are equaly intense across the whole surface, reflection should be stronger at lower angles ( view glancing off surface) and refraction at steeper angles (looking into the water). The tutorial I lifted the shaders from had this, but I could never get the shader to work out the angles correctly, and I'm not at all sure it was even slightly physically correct even if it had worked.


  2. Depth effects - fogging with water depth or ideally length of view ray through water. For extra points, refraction depending on depth. This shouldn't be too difficult at all.


  3. Moving ripples - there are ripples, but they are static. There is some mojo involving moving the two maps at different rates that will make the water ripple. Again this should be reasonably easy if you can find out how the trick is meant to work.


  4. Specular reflection - personally I don't see the point, since with reflection and the skybox, it already looks nice, and to my mind a simple "white" specular highlight looks far less realistic. I'd leave this out frankly.


  5. Fancy waves with fancy foam. Damn you MrCoder, and your fancy, fancy waves in code I can't get!



    All in all, not as good as MrCoders water, but you can have it right now :stuck_out_tongue_winking_eye:

excellent stuff!! more versions = better … plus we can steal from each other and improve on our watercode :wink: well done

Maybe we can have a water competetion.



Ill post 5 dvds packed with 3dmax models to the winner.

cool idea…but it's hard to judge with so many things to judge by…performance, features(reflection/refraction/depth based/fresnel/foam etc), ability and easyness to work together with other objects(that should be reflected/refracted etc), how advanced shaders are needed, texture units used, water surface features(single plane/grid/can have different heights at different places etc), if it works under water…



but sure it can be done :slight_smile: if it pushes people to produce more it's good…



i have started write a 3 part tutorial to post here or somewhere as they get done.

they will contain something like this:

Part 1 - Simple water plane with reflection

Part 2 - Adding depth based refraction

Part 3 - Projected grid water



perhaps split them up even more depending on how hairy they get :wink:

There also things to take into consideration eg, a stream is a different beast to the sea unless its done really cleverly.



Ill have a ponder, between us all we can come up with acceptable rules for the water.



BTW, all the models are royalty free  XD

I guess I really don't need anything too fancy.  I could even do without reflections I suppose.  I'll take a look at the MonkeyWorld3D code for now.  That will probably do the trick as long as it has the methods for grabbing the height at a given location (which I suppose it does assuming it is a trimesh or something like that).  Most of the game play will be on the water, if not all of it.  Thanks for the help!

Glombool said:

That will probably do the trick as long as it has the methods for grabbing the height at a given location


and in a "simple" water that height will just be a fixed number...

Great to hear you are going to make a tutorial MrCoder :slight_smile: My water is a bit of a hack, I'm looking forward to seeing a neat way of implementing it :slight_smile:



Glombool, my water is just applied to a quad, any non-flatness is just faked by the ripple textures, so it won't look good when you are very close. It relies on an approximation that the actual waves are small enough that their height can be ignored, and only the angle counts. For my game, it's fine since you probably won't get too close to the water, but for a water based game it wouldn't be great. I think MrCoder's projected grid water would be ideal though. I have to say I don't really have any idea how a shader based method handles refraction through a trimesh, so it will be interesting to find out :slight_smile:



Oh also - I forgot another thing missing from my water (the list is so long): Fogging. It would be great to have fog that would line up with standard GL fog, and I think it should be quite simple, just another thing I couldn't quite work out :slight_smile: Makes me think actually, a tutorial about shaders based on JME and with more than the usual very brief explanation would be very very useful, especially if it covered replacing the fixed function pipeline features in shaders. When I've got air carrier playable I plan to get back to making it look nice, and I'll have a look at documenting what I do, but it might not be for some time.

refraction/reflection is handled exactly the same way as with the flat water, just add the trimesh normal to the normalmap normal…nothing amazing



replacing the fixed function pipeline is kind of hard, if you want to support a variable number of lights etc…works out only in shader model 3 with "real" branching


shingoki said:

For my game, it's fine since you probably won't get too close to the water, but for a water based game it wouldn't be great.


It should work fine in my game too.  It is "water based" but the angle and distance of the camera make the fancy ripple stuff not-so-necessary.  For now, I just want to get something implemented.  I can always change it before the production release if I need to.