Water transparency related to depth... ??

I’d like to draw some geometry over one existing, and setting the transparency inversely proportional to the difference of z values in depth buffer (alpha proportional)…

In other words, I have a terrain then I’ll draw some water surface. I want to see the terrain under but not where the water is deep, in a continuos fashion.

I think I’ll need to set the alpha value for blending according to the difference of zwater-zterrain in the zbuffer… how??

There is a way to do this, or maybe a trick to obtain the same result?

Thanks in advance!!
fz

Will a blue-green volumetric fog solve ur problem? Use it to fill out the water.

There’s an article on gamasutra about vol fog which uses difference of depth values.

You may be able to get vol fog without explicitly finding zwater-zterrain.
Use z fog and with a subtractive blend u can get a fog color proportional to zterrain-zwater.Beware of clamping though

[This message has been edited by tarantula (edited 08-25-2002).]

Thanks for the reply!
I looked at the article, but it assumes that I can use the “w” of each projected pixel as alpha, but I can’t… or at least I don’t know how

I tried to draw water in stencil, then draw multiple planes at different heights with little alpha, then draw water surface… the result looked ok, but the framerate dropped too much…

I think using zfog as a trick will give me the same fps because i need to draw the terrain under the sea with a different fog setting, so before I need a stencil pass on water, then finally redraw the water with subtractive blending… sigh!

However, thanks a lot!
fz

Originally posted by Teofuzz:

I think using zfog as a trick will give me the same fps because i need to draw the terrain under the sea with a different fog setting, so before I need a stencil pass on water, then finally redraw the water with subtractive blending… sigh!

Or, u can draw the water (while setting the stencil) and then use src-dest blending… if your card supports it.So u dont have to draw water twice.

Originally posted by Teofuzz:
I looked at the article, but it assumes that I can use the “w” of each projected pixel as alpha, but I can’t… or at least I don’t know how

If you are using vertex programs (or something similar) you just need one move instruction at the end of the vp to copy the w coordinate to alpha.

You could calculate it by hand by making a vector product of the vertex with the last column of the projection matrix, but I guess that would be too slow on cpu.

Thanks all!
I’ll investigate more on fog while waiting for a card that supports vertex programs!
fz

Changing the transparency of the terrain depending of the deepness could be a solution ??
Or just making it darker on deeper underwater vertexes ??

Just brainstorming…

Building on the idea of rIO… if you give the vertices of the underwater scenery a color which get’s nearer to the water color as deeper they get. Then you can use a static transparency for the whole water to achieve the effect… I think so at least :wink:

Kilam.

It’s a good idea, but the terrain vertices are less than those on the water surface.

I wanted to achieve this effect primarly for the waves that “break” on the beach, so the intersection may have shapes that does not fit the triangles.
So the effect has to be “per pixel”…
However, I think it’s good for the deepest water!
thx
fz