Sign in to follow this  
mickeyren

rendering water, zfighting issues?

Recommended Posts

Hi Please see screen shot: I'm trying to achieve an irregular shape terrain island by resting the terrain on top of a flat grid water. Basically I'm trying to do something similar to this: I have a terrain where the sand vertices has varying heights between 0.0 - 1.0f. I put a large grid for the water rendering at height/y 0.2 for instance. I render the water grid last, with alpha blend enable. I was wondering what is the correct way of doing this so artifacts or any zfighting issues doesn't pop out? Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by mickeyren
Hi thanks for your insights.

But if anyone could tell me the reason why sands are poking through?

This is what I'm trying to achieve (screen shot from the Hydrax engine):



I should think that would be obvious-- bits of the mesh you're using for the sand are poking through the water surface! :)

EDIT: Sorry, circular definition. The heights of some bits of your terrain are distributed in such a way that they produce the odd little patterns you're noticing there.

Also, I would suggest just dropping the alpha blending/fixed-function thing right now and learn HLSL. If you're going after something like the Hydrax shot you posted, you're really only doing yourself a favor. I'd recommend looking into implementing some sort of environment map, (possibly precomputed) the Fresnel effect and MRT for some nifty depth-dependent effects. Caustics aren't too hard either, if you're clever with it.

Share this post


Link to post
Share on other sites
Hi

Both my terrain grid and water grid are implemented in seperate HLSL. And no I'm not implementing something similar to Hydrax.

This is the last puzzle I'm trying to solve and my scene would be complete.

I just don't want to have a square shaped terrain for my demo scene.

I toyed with both zenable and the z compare functions, but didn't helped.

The range of the sand vertices are from 0.0 - 1.0. I put the water grid at height 0.3.

Would that be the reason that the heights are so close to each other?

Share this post


Link to post
Share on other sites
well it is because a lot of sand 'hills' are higher then your sea level, so you should implement some sort of secondary ring with a lower range of height difference, in which it makes it possible to only have height differences between 0,0 and 0,2.

Share this post


Link to post
Share on other sites
Here's an image, in 2D, which should make it clear what people are saying:



The blue line is the water level, the yellow is the sand. See there's two verticies which "poke through"?

It could be z-fighting, it's a little hard to tell from a static screen shot. Does the problem disappear when you get closer to the water for example?

Share this post


Link to post
Share on other sites
If those holes go away when you move the camera closer then the z buffer accuracy is the problem. To fix that double check that the near and far clip planes are set to reasonable values. For the highest z buffer accuracy you want zFar / zNear to be as small as possible.

If the problem is that the ripples on the water are making the water mesh go below the land mesh in places then there's a few options, here's some simpler ones off the top of my head:

- Make the land under the water have a steeper slope, so you don't get large shallow areas.

- Regardless of the actual z position of the water use the same Z value everywhere for depth testing purposes - the water height. Just output this fixed z from the pixel shader and keep the real one in the vertex shader.

- Use smaller ripples. You could make them get smaller closer to land but that's much more work (one option is to store the max ripple height per vertex in the water mesh based on the height above the bottom). This would obviously also give the possibility of making the water get whiter when it's shallow too.

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