Ocean opacity

This topic is 2172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi there,
I'm trying to add water in a voxel engine i am working on. My naive first approach was to send with each vertex the depth of the water just bellow that vertex.
The deeper it is, the closer the alpha value gets to 1.0f.
It gives acceptable results from above looking down ...

... but  very unrealistic result from other angles as you can see bellow :

So i guess what i need to do is to cast a ray from the camera to each vertex on the ocean grid and calculate how much water there is between the vertex hit by the ray,
and triangle hit by the same ray at bottom of the ocean. But it sounds very expensive

Current approach :

What i need :

In you opinion, what is the most efficient way to do that ?
Or maybe there is a completely other cheap way of faking ocean depth you can point me to ?

Thanks :-)
Edited by Yann ALET

Share on other sites

I think you are looking for a Fresnel shader.

Here's a page about that and other water effects

http://habibs.wordpress.com/lake/

Share on other sites

I think you are looking for a Fresnel shader.

Here's a page about that and other water effects

http://habibs.wordpress.com/lake/

Ohhhh so this is what Fresnel is !

I came accross this word as i was looking into other ocean shaders, but have not looked it up yet, thanks !!!

Share on other sites

Fresnel term isn't really to do with water depth, it's to do with the angle you view the water at, it looks more reflective/opaque looking down at the water and more transparent the shallower the view angle. It looks pretty good though.

EDIT: I may have that the wrong way round though ;)

Share on other sites

For the blue shift component of it, you're going to need to compute the ray from the vertex or pixel to the camera, then work out how far along that ray you hit the water surface. That distance value can be used to lerp between water color and object color. Fairly straightforward to do in a shader. Note that the correct approach is to subtract a mostly red color, rather than to interpolate towards a blue color.

Edited by Promit

Share on other sites

Yeah it worked !

But it's still using blending states for the "transparency", so no refraction/reflection, caustic ect ...

Time to start working on that i guess.

Anyway, thanks a lot folks !

Share on other sites

Oops, well, looks like this is solved already.

If somebody still wants to try the original concept in a cheap way but accounting for the angle, don't forget that one could always just use the depth buffer to retrieve the depth below the water without any extra calculations (just make sure the water renders after everything else). This could be used to create a fog-like effect.

The above trick assumes this is done in the pixel shader, but hey, it's a rather simple one :P Also would work for pretty much anything where you want to make a fog effect (in fact, water doing this is pretty much for the same reason fog happens in the air, so it's literally fog).

Share on other sites

Yep, combining Fresnel with a fog like effect would be good too. Fresnel is really meant for controlling the reflectivity component I think. Adding a scrolling bump map for the water surface looks good too especially if you combine it with specular highlights from the sun/moon.

• 9
• 17
• 10
• 11
• 18