Wednesday, January 09, 2008

X-Plane Water - Now and the Future

Randy forwarded me a very detailed email message from the features list about water. First a few notes:
  1. I don't read the features list - I'm only blogging this because Randy forwarded it my way.
  2. Procedural water (that is, procedural waves with the sky as a reflection) is a default shader option because when we first looked at it, it seemed to be "low cost". Some hardware really chokes on this option. But one trend that's clear: I have not seen any hardware that can do volumetric fog but has trouble with water. When it comes to expensive computations, vol-fog is the the heavy effect. If your card can run with vol-fog even remotely well, you're not going to get any kind of fps boost by turning off water. So the question of whether procedural water can be optional is one of whether the water looks good (which I will discuss below), not one of performance.
  3. I've received plenty of emails about how we can "cheat" on the reflections to make them faster. To be honest, these ideas aren't very useful...you really need to know how the rendering engine works on a low level to find good ways to cheat on reflection quality.
(It's not enough to make the reflection texture less good looking, you have to do so in a way that makes it take less time to render! We've basically already taken all the optimizations we can - that's what that water reflection detail popup does. Keep it on a lower setting.)

So with that in mind I'd like to bring up three issues with the reflective water and give you some idea of the roadmap. I should say that when I list features as coming in the 9.xx or 10.xx time frame what I really mean is: some depend on new global scenery and some do not. It's possible that we may do a ton of water work in 9.1 or we may not do any more for five years. I can't really make a good prediction on future features after 9.0, except that they'll be, um, really cool. :-)

Water Weather Settings (9.00)

X-Plane currently provides a global wave height setting. X-Plane 9 beta 15 ignores this setting and simply creates calm water. This is simply a link-up between the physics and the shader that I had not gotten to until now. I believe that beta 16 will address this; the water wave height will match what you dial in. This still is only a baby step, but there will at least be a workaround for the mos common complaint (the ocean looks like glass) in that you can set the wave height to 10 meters.

Water Properties (9.xx, 10.xx)

Now Peter brings up an important point: the properties of how the water look vary with their location. First I must point out an architectural issue: you can't do a great job of computing "fetch" (open runs where wind builds up waves) in the sim because the area adjacent to the current water may not be loaded. That is, if X-plane doesn't have the pacific ocean loaded, how can it know that the waves hammering San Francisco can be pretty big? So I have always viewed fetch as something to pre-compute into a DSF mesh.

(This does bring up an architectural issue...how can we have properties on open ocean with no DSF mesh? The answer might end up being that we do have to provide water-only DSFs for bays and inlets that are large enough to cover a whole tile.)

Now it turns out that (secretly) the DSFs have contained a very crude version of fetch since 8.20. In version 8 we didn't really have the shading power to visualize it (I did have some experimental code once) and in version 9 it is not yet hooked up. The fetch calculation isn't very good, but it does exist. In the long term, we've talked within the company about including bathymetric data (water depth) and even water properties like clarity and the color of the goo in the water. Improving the water metadata would be a next-global-scenery feature, and we don't recut global scenery very often.

(The DSF format is flexible...you can encode just about as much extra data into the mesh for water as you want - it's not a format change.)

So I think you may see some improvement in the water as we utilize existing fetch data in the mesh, and some improvement as we encode more meta-data into the mesh. Note that to do any of this we need to change the sim a bit...right now it assumes a constant wave height - this would no longer be true. I think these kinds of improvements will start during the 9.x run but not be in 9.0.

Filtering Errors (9.xx)

This is the most technical issue with the water, relating to how the graphics hardware works. The problem is that the way the far-view of the water is computed is too reflective due to down-sampling.

In real life, if I am in front of a body of water with 6 inch waves, I will see two things:
  1. Near me, I will see the waves themselves. Part of the waves will be dark, because their surface normal faces me, so the Fresnel equation says I see down into the water, where I see the bottom (or if it's deep enough, darkness). Part of the waves will be at an angle to me and act reflective, picking up colors from the sky and maybe surrounding terrrain. So my waves are going to be a mix of the sky color and some kind of dark color, with the color contrast allowing me to see the shape of the wave.
  2. Farther out, the waves will be smaller than my eyes can distinguish and I'll start to see a more consistent water color, which is a mix of all of the various sky color inputs and darkness. The particular mix might depend on the chop and shape of the waves and angle to the sky. The important thing is: there is scattering of the reflection at a level smaller than my visual acuity, so I see sky color, but I don't see a sky reflection, and that color is darkened by the Fresnel equation.
Now in X-Plane the problem is this: the water waves are built up procedurally from a noise texture. As we get farther away, that wave texture is reduced in quality. Unfortunately, the graphics hardware averages together the wave shape, not the resulting color from the wave shape.

So instead of getting sky + deep = darker blue for the water, I get peek + trough = flat water! In other words, at a far distance the waves are canceling each other out before color lookup, giving us a perfect mirror in the far-ground.

This is fundamentally an implementation problem - I bring it up only because it's a counter-intuitive one. In the immediate future, the "glass lake" problem will become less because filtering only kicks in like this when the waves become less than one pixel - with the option for taller waves coming, the waves should be visible farther out. In the longer term we'll probably put in new shading code to address filtering problems.

Reflection Positioning Bugs (9.0, 9.xx)

As of beta 15 I thought I had fixed most of the reflection positioning bugs (that's what happens when something reflects in the wrong place in the water) - the geometry for this is made complicated by the Earth being round. I don't expect to nip all of these bugs in 9.0 but I do hope to get most of them, and I will keep working on this as bug reports come in.

Wave Shape (9.xx)

Finally, our wave shapes are quite primitive - it's just shaped procedural noise designed to look tolerably like water. We have a framework into which we can insert more complex wave equations (at the cost of some framerate). I don't know what the future will bring in this area. The v9 water sets out a new foundation onto which we can do more complex water. But we have to crawl before we can walk.

5 comments:

Anonymous said...

Modeling waves seems as if it could become a huge simulation project in its own right, beyond just the issue of 'fetch'! For example, refractions and and reflections based upon islands and bathymetry, and the local small-scale interactions of wind and water.

For example, waves are often one of the most visible elements of micrometeorology (eg. ripple patterns on oceans and lakes based upon wind gusts around other objects such as hills/islands), or due to down-draughts from convective activity. It is easy to see many of these for real when flying over the San Juan islands up here in the Pacific NW.

It would be great to prioritise some of these issues to determine inter-relationships with issues that truly affect flight (eg. local wind variations) and which might also impact visual features (eg. waves, which of course also impact float plan operations). An example might be the down-draughts downwind of a runway that ends in a steep drop (eg. KTEX) which is a real attention getter in a real aeroplane on final approach!


- Robin

Anonymous said...

also give some thought to partially submerged items as b15 renders a reflection of an item that is below the water's surface. Not usually a problem with seaplanes, but it is happening.

Anonymous said...

Good stuff!
I see you have lots of interesting things planned for the sea in x-plane. As mentioned before, the subject is vast can easily become extremely complicated but I would be really happy to see some sort of fetch affecting wave height as this would add a lot to seaplane operation (arguably it's pretty much a key element).
I am glad to see you are looking into it as well as into the 'perfect mirror water syndrome' which has been bugging me in pretty much every computerized representation of water I have seen lately (since we have hardware that can do reflective water anyways...)
One more thing to consider would be the effect of smaller scale ripples that really tone down the reflectivity of water even up close as wind increases (i.e. you really don't see any shapes reflected anymore if there is more than about 10kt of wind, even if you are right next to them).
Bathymetry data would be great to have and would really enhance the overall experience of flying (not just seaplanes) especially in certain parts of the world (thinking about flying in the Bahamas for example...)

Keep up the good work! I'll be following this closely...

Murmur said...

Hi Ben,

I noticed water in some conditions (night, rough water, etc.) reflect only (or mainly) light sources and nothing else:

http://static.flickr.com/110/296301868_10e33d99a6_o.jpg

http://www.mchenrycountyblog.com/uploaded_images/Crystal-Lake-Main-Beach-House-reflecting-in-water-8-16-7-dusk-736129.jpg

http://www1.istockphoto.com/file_thumbview_approve/2663631/2/istockphoto_2663631_light_reflection_on_water.jpg

http://farm1.static.flickr.com/179/364417721_0293f5df4e_o.jpg

http://www.phili-photo.com/images/blog/Seattlewaterfront.jpg

I don't know if X-Plane already does that, but it would be a good idea? Also for users with low specs , allowing reflections of light sources only would give a nice visual effect at only a fraction of computing cost.

Finally (I'm sure you're often asked this :) ) what are the plans about reflective wet runways?

Marco

dan31 said...

And what about the reflexion of the atmosphere when "flying" in a Shuttle in space ?