• Advertisement

Archived

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

Fairly simple water

This topic is 4963 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

I don''t really want to invlove things like shaders or render-to-surface in my water, but I''d like it to move and look quite nice. The physics will be OK but I''m thinking about rendering. If I texture the water with a standard water texture, but set the transparency based on the vertical angle from viewpoint to each vertex, and use standard specularity - will this look ok? Obviously things under the water won''t ''ripple'' as they should but will it look horrible or just not as nice as environment-map-reflected water? But out of interest can you point me to tuts on how to make objects underwater ''move'' as surface moves and how to get reflections, transparency etc as well. If it could be done with vertex shaders I might consider it... [Edited by - d000hg on June 23, 2004 6:27:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
That depends on your definition of "horrible"

Seriously though, you can''t simulate realistic water without reflections and refractions, since those two components are the main properties of any transparent liquid.

But you can get something that a human observer will generally interprete as "watery", even without using reflections and/or refractions. Simple water as in Quake is easy, and doesn''t require any shader magic. Unfortunately, it''s not very attractive. You can get more or less acceptable water by using a simple transparent mesh displaced by your physics function. You''ll get a lot of sorting artifacts, but it''ll look like water. Specularity can help, but can quickly make your water look like a moving plastic plane.

I''d suggest you look at least into reflections. Even without refractions, water can look really good using reflections alone (either by a cubemap, or better by a projective render texture). You can perfectly do it on vertex level only, no pixel shaders are required to get a nice effect.

Share this post


Link to post
Share on other sites
get a nice skydome, and reflect that, that alone will make it look very purty!

Share this post


Link to post
Share on other sites
Thanks guys. Quake water is not good enough, QuakeII was quite nicely transparent but didn''t move. I presume the artifacts you refered to come from rendering transparent polys in the wrong order?
How exactly do you do a cubemap for a sea? Is it not different than for a body (like the DX teapot)? I quite like the idea of ''reflecting'' my sky ino the water, to get either transparent or sky image depending on viewing angle.

Something about rendering refraction has always puzzled me. When you look at a pixel/vertex you need to get the view-ray and bend it to a new angle and follow to see what it touches, right? But if the sea floor is not flat is it not very expensive to find the intersection of the ray and mesh? Or is this done totally differently?

Cheers.

Share this post


Link to post
Share on other sites
quote:
Original post by d000hg
I presume the artifacts you refered to come from rendering transparent polys in the wrong order?


Yes.

quote:
Original post by d000hg
How exactly do you do a cubemap for a sea? Is it not different than for a body (like the DX teapot)?


It's the same. You'll use a cubemap representing a large scale environment around your water surface. It's important that you don't add local geometry or details into the cubemap, because that will lead to artifacts (if you want local reflections, for example a boat, terrain, or some vegetation, then you'll have to use the render-texture approach). When rendering the water surface, you do this:

* bind the cubemap
* for each vertex, compute the reflection vector taking into account vertex position, normal, and view vector.
* use that reflection vector to index the cubemap.

You might want to add some blending, so the water gets semi transparent, otherwise you'll have a liquid metal look.

Once you have that working, you can attempt to add the so called Fresnel effect: that's the ratio of reflection to refraction, depending on the view angle. Instead of true refraction, you can simply modulate the transparency.

quote:
Original post by d000hg
Something about rendering refraction has always puzzled me. When you look at a pixel/vertex you need to get the view-ray and bend it to a new angle and follow to see what it touches, right? But if the sea floor is not flat is it not very expensive to find the intersection of the ray and mesh? Or is this done totally differently?


As many other things in realtime 3D, you use an approximation here. The ocean floor (or any other object below the surface) is assumed flat. That makes the intersection calculations very easy. Since refraction is a visually very complex effect, the human brain will not notice physically inaccurate refractions, as long as the general behaviour is reasonably well approximated and the refraction index difference between liquid and air is not too big.

Refractions are generally either done by projective render textures, or by vertex deformation of the geometry below the water plane. Since they are almost always local, a cubemap approximation doesn't work very well for refractions.


[edited by - Yann L on June 9, 2004 4:28:54 PM]

Share this post


Link to post
Share on other sites
Many thanks. What exactly is projective render texture? And would both this and vertex translation work for underwater objects?

Share this post


Link to post
Share on other sites
i know you're thinking simple, but id start thinking "good implementation" and pair down from there. since Yann is aprticipating in this thread it reminds me of the lecture he gave on water.

Here
is a link
to the lecture


Here is a link to Yann explaining some questions about it.


it's a good read, and is easily bastardized to an easier implementation if you decide that's too much

Dredd
________________________________________

"To die with your sword still in its sheath is most regrettable" -- Miyomoto Musashi






[edited by - Dreddnafious Maelstrom on June 10, 2004 8:48:10 PM]

Share this post


Link to post
Share on other sites
Thanks for the links - most useful. I''m thinking good physical modelling and simple rendering. If it moves well and actually interacts (good splashing stuck on afterwards) with stuff then as long as there''s transparency close to you and sky reflections far away it should be nice. If the water is in a breeze you can''t see anything under the surface anyway unless just below when you get a blur of colour!

Share this post


Link to post
Share on other sites
@YANN:

Just read the lecture mentioned above (well skimmed of rendering section some as only have 30min) and very impressed. One question about the lecture - how much was it cut''n''paste from a prepared lecture and how much on-the-spot writing? Off-topic but I also wondered if your simple NSE approximations would easily adapt to a large island (a mile across maybe) and if so would we se waves get steeper and taller in shallow water, would they break (I guess not in a heightmap!).

I took a course on NSE in final year of my degree so hopefully can implement this - I was particularly interested in the idea of melding it with a LOD system since otherwise it''s a huge waste of power for a land based game with water mainly as eye-candy! Although I would at sometime like to implement water interacting with things like slowing cars, physically modelled river flowing properly...

Share this post


Link to post
Share on other sites
Hi d000hg

I'll suggest you'll just implement the render-to-tex approach. It's really not that difficult!

Take a look at these screenies:

Screenies

You're more than welcome to email me, if you have any questions.

Best regards
Roquqkie

EDIT: Hmmmm.... Try direct-linking instead

[edited by - Roquqkie on June 12, 2004 4:44:36 AM]

[edited by - Roquqkie on June 12, 2004 4:46:03 AM]

Share this post


Link to post
Share on other sites
I don''t have much time right now, so I''ll be brief. If you have additional questions, I''ll be back after the weekend.

quote:
Original post by d000hg
Just read the lecture mentioned above (well skimmed of rendering section some as only have 30min) and very impressed. One question about the lecture - how much was it cut''n''paste from a prepared lecture and how much on-the-spot writing?


Heh, 100% on the spot Well, except the code that I wrote a couple of hours befoee the lecture, iirc. For the math part, I had the equations printed out.

quote:
Original post by d000hg
Off-topic but I also wondered if your simple NSE approximations would easily adapt to a large island (a mile across maybe) and if so would we se waves get steeper and taller in shallow water, would they break (I guess not in a heightmap!).


Yes, they break, they create interference, etc. Note that it''s not really an NSE anymore, it''s a simplified version of hydrostatic pressure equations (which are related to the NSE, of course, but much simpler). The main difference is, that the system I presented doesn''t take turbulence into account. The system works on any scale, but you have to be careful about stability. For the sake of simplicity, I used an Euler integrator, with all the stability issues that come with it. If you want to use that code in a production environment, you should replace the integrator (different options come to mind: Runge Kutta 4 would probably work, Verlet integration works fine).

quote:
Original post by d000hg
I took a course on NSE in final year of my degree so hopefully can implement this - I was particularly interested in the idea of melding it with a LOD system since otherwise it''s a huge waste of power for a land based game with water mainly as eye-candy! Although I would at sometime like to implement water interacting with things like slowing cars, physically modelled river flowing properly...


That''s partially possible with the simple 2.5D model I presented, but you should use a simple NSE solver that includes a turbulence vector field. For full fluid dynamic simulation, you''ll need a 3D simulator. There are a few papers linked in the forum FAQ (I guess, haven''t checked it since last year).

About projective texturing: take a look at this thread, where I posted some code.

Share this post


Link to post
Share on other sites
@Roquqkie:Maybe I'd be more impressed if I could see the pictures...

@Yann: Thanks for that. When people talk about Euler integrals they mean analogous to x=x0 + v.dt right? I normally use this with the '+0.5*a*dt*dt' part too which is a lot more accurate. Is 4th order R.K just this with 3rd+4th derivative parts added from the expansion or more complex? And what is this verlet integration I keep hearing about?
RE: river etc - this is not planned to use 2.5D but what will be used I don't know yet! Without going over your maths I can'y tell but it could still be NSE - you can make it very simple with a few key assumptions and yet it still is NSE, just running on the model of the liquid you select (like having no viscosity etc). Less accurate but still NSE, just being picky though!

[edited by - d000hg on June 11, 2004 6:21:30 PM]

Share this post


Link to post
Share on other sites
Hi d000hg

LOL, 10 minutes after I posted my screenshots, the server where I''ve stored them, closed down direct-linking to pictures... Try the link now

Best regards
Roquqkie

Share this post


Link to post
Share on other sites
Yep working fine and looking pretty. What''s the minimum kind of spec you''re running that on? My desired game min spec is about 700MHz Geforce1/TNT2 mainly because I''m developing on a GFMX2 - that was fairly low end when first started playing about 18months ago, maybe I''ll dig out that ATI8500 and make that bottom spec if I get carried away with pretty effects or maybe wait until more game mechanics in place first!

Share this post


Link to post
Share on other sites
That''s a really good lecture. Considered a teaching job, Yann?

And it appears that Yann still knows everything

Share this post


Link to post
Share on other sites
Quote:
Original post by d000hg
@Yann: Thanks for that. When people talk about Euler integrals they mean analogous to x=x0 + v.dt right?

Correct, although there are implicit and explicit kinds of Euler integrators. It depends on how you use it. In the case of the water, it's explicit (because it uses the previous results of accelerations and velocities of the field to update the current timestep), and that's what makes it unstable.

Quote:

I normally use this with the '+0.5*a*dt*dt' part too which is a lot more accurate.

That would actually be 2nd order RK, depending again on how you use it in the context of the remaining ODE.

Quote:

Is 4th order R.K just this with 3rd+4th derivative parts added from the expansion or more complex?

RK4 is basically RK2 with the error terms from the 3rd and 4th derivative added. You just have to be careful with the weights of the higher order terms, several combinations are possible. The most common general form is this one:

k1 = f(x(n), y(n))*dt
k2 = f(x(n)*dt/2, y(n)+k1/2)*dt
k3 = f(x(n)*dt/2, y(n)+k2/2)*dt
k4 = f(x(n)+dt, y(n)+k3)*dt

y(n+1) = y(n) + k1/3 + k2/6 + k3/6 + k4/3 (+ ErrorTerm)

For RK4, ErrorTerm should be O(dt^5), ie. everything over and including 5th order derivatives.

You can theoretically add as many derivatives as you want to this series, elevating it up to any order. You get higher accuracy with that, but it will take much more performance. Usually 4th order works pretty well in practice, and is reasonably fast to compute.

(Note: RK4 equations from the top of my head, might contain erros. Google to be sure).

Quote:

And what is this verlet integration I keep hearing about?

Verlet is similar to Euler, but recomputes the previous velocity from positional difference at each timestep, instead of directly updating it with the acceleration. This makes it an implicit method, and makes it more stable. There are various different Verlet algorithms, have a look at this page.

Quote:

RE: river etc - this is not planned to use 2.5D but what will be used I don't know yet! Without going over your maths I can'y tell but it could still be NSE - you can make it very simple with a few key assumptions and yet it still is NSE, just running on the model of the liquid you select (like having no viscosity etc). Less accurate but still NSE, just being picky though!

Well, if you strip down the original Navier Stokes equations, how long can they still be called NSE ? It depends a little on your terminology, I guess :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can make reasonable looking water without reflections or refractions.

I've been playing around with the World of Warcraft beta recently, and even though I've never implemented anything I'm about to describe, I'm fairly sure I understand what they're doing, and it produces reasonable results.

For reference, witness it in this screenshot

It looks good there, and FAR better in motion, as the specular highlights move properly with motion of the water and the camera.

Everything in WoW is fairly low-polygon (of course, that doesn't keep performance from sucking even on my Athlon64/GeForce5700 Ultra), but they're getting some impressive looking specular lighting which I'm fairly sure is coming from bump maps.

The actual water is not transparent at all, and does not reflect the surrounding area, and I believe that it is completely flat, without waves (I'll check tonight). My guess is that they have a sequence of bumpmaps that they apply in turn, probably something as simple as dot3. The result, while not FarCry, does look good, and not too hard to implement.

I think the hardest part will be the artistic side, actually creating a sequence of bumpmaps that both tile and can wrap around in sequence.<

Share this post


Link to post
Share on other sites
I couldn't see any water, just a shiny red concrete/plastic thing where water should go... oh you're saying that IS the water ;) I really hope it looks a lot better animated!
Quote:
k1 = f(x(n), y(n))*dt
k2 = f(x(n)*dt/2, y(n)+k1/2)*dt
k3 = f(x(n)*dt/2, y(n)+k2/2)*dt
k4 = f(x(n)+dt, y(n)+k3)*dt

y(n+1) = y(n) + k1/3 + k2/6 + k3/6 + k4/3 (+ ErrorTerm)
I don't quite get this, there seem to be no derivates anywhere! Could you give a 1D example of RK4 maybe?

Share this post


Link to post
Share on other sites

  • Advertisement