Water/Terrain edging

Started by
8 comments, last by WinstonPennypacker 17 years ago
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!
Advertisement
Take a look here

Maybe you can find a solution in their source.

Good luck
www.nextdawn.nl
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
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
im not that into the topic.. but why not simply add transparency to the water based on its depth... at areas where the water and terrain meet will be fully transparent and u wont notice any artifacts...
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
Ring3 Circus - Diary of a programmer, journal of a hacker.
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.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
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.
Thanks a lot everybody, these are all some great suggestions. I'll repost once we get a chance to test some out.

I really appreciate the help!
Okay, increasing the camera's near clip completely fixed our problem. Thanks a lot for your help everyone.

This topic is closed to new replies.

Advertisement