Ocean opacity

Started by
6 comments, last by Paradigm Shifter 10 years, 9 months ago
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 ...
PALaJkr.png
... but very unrealistic result from other angles as you can see bellow :
A1NBKvm.png
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 sad.png
Current approach :
TTy2DLW.png
What i need :
jbFuV8D.png
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 :-)
Advertisement

I think you are looking for a Fresnel shader.

Here's a page about that and other water effects

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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 !!!

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 ;)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Yeah it worked !

TMsWStj.png

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 !

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).

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

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.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement