Sign in to follow this  
WinstonPennypacker

Water/Terrain edging

Recommended Posts

Hey everyone, I'm working on a project that implements a 3D heightmap generated island with an ocean-shaded plane for the water rendered overtop. Its DX9c based. From a short distance away, they both look great, but for this project, the view will be from a distance and likely from high above. When we take the camera out, there's an incredible amount of Z-fighting between the land and the water edges. (Jagged swimming triangles between the land shore and the water edge ). I've seen a lot of terrain and water engines on here and was wondering if someone came up with a solution to this problem they'd be willing to share? I've tried messing with the slope-scale and depth bias, neither seem to work. I've tried increasing the z-buffer format to D24S8 (which normally fixes z issues for me). That didn't work either. The water is being rendered with a shader, and we're not really set up to do any kind of crazy intersection tests with the land and ocean, though... Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Hello,

Have you tried pushing the near plane out further - if you're viewing from high above, and assuming there are not lots of things flying around, you can probably set the near plane quite far away from the camera (ideally, a little bit closer than the nearest thing to your camera).

cheers,
stoo

Share this post


Link to post
Share on other sites
If your view will always be from a distance and high above, try this...

1) Write infinity to the Z-buffer (there is a call meant to do this, use it).

2) If you have visible terrain and objects under the water, render them first with a clipping plane in place to prevent drawing the over-water parts. For speed, disable the clipping plane for objects or map sectors that are deep enough to not touch the water plane.

3) Render the water with z-testing and z-writing disabled.

4) Enable z-test and z-write

5) Draw your land and everything else, using a clipping plane at the water depth to prevent terrain and objects partially underwater from being drawn. Again, for speed disable the clipping plane for objects that are high enough up that they won't touch the water plane.

That works nowhere near as slow as it might sound... the only things rendered twice (once for each half) will be those actually intersecting with the water.

Share this post


Link to post
Share on other sites
As already suggested, you should push your near clipping plane out a bit. You might be amazed how much extra precision you get from a few centimetres of near clipping.

If the project uses a highly-dynamic viewing range, then you should make your projection matrix dynamic to match. When the viewer is on land, you may need to see things a few inches away from the camera, but when you're up in space, nothing will come nearly as close to you. Recalculating the projection matrix a cheap and often-overlooked method of increasing apparent Z-buffer precision.

Admiral

Share this post


Link to post
Share on other sites
Quote:
5) Draw your land and everything else, using a clipping plane at the water depth to prevent terrain and objects partially underwater from being drawn.


Just wanted to quote this one again, since it solved a lot of issues for me on a similar project. If parts of the terrain are underwater and the water's not transparent, there's no point in rendering it anyway. It may be a little harder on the vertex processing, but if you're fillrate limited (i.e. if you have a heavy pixel shader, as many multi-texture terrain implementations seem to have), this one is a lifesaver.

Share this post


Link to post
Share on other sites
if you're using a pixel shader, check out the cryengine 2's per-pixel shoreline rendering technique. It's a ppt file entitled "Real-Time Atmospheric Effects in Games." Should be in the publications section of the ati developer page.

What they do is they render the water, then the terrain under it, and then they use the water depth to alpha blend the water with the terrain. Interesting idea, and it works even though they use a modified form of deffered shading in the Cryengine, which makes alpha blending tough.

If you're using a vertex shader, I strongly recommend rendering water with a pixel shader. It really works alot better.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this