Archived

This topic is now archived and is closed to further replies.

CO

Under water effect

Recommended Posts

I created a 3D scene and draw the water as a simple plane. If the camera is under the water the scene should be drawn in a blue color... (remember: it''s possible that the camera is not complete under water) How could I create such a ''under water effect''? I''ve tried out several ideas but couldn''t find the solution... maybe one of you had done this before...

Share this post


Link to post
Share on other sites
Maybe a real camera can be half under water, but an opengl camera is a point, so it''s either under or not under.

To make it look like its under water try this:

  
if(amIUnderWater())
{
// draw quad covering scene that is transparent blue

}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is an untested idea, so it might not work. This is also
the first time I''ve ever tried posting here.

I believe you could use Clipping Planes to describe the surface
of the water. In OpenGL, the function is glClipPlane. You just
have to describe the plane in the form Ax+By+Cz+D=0. When the
plane intersects the camera, OpenGL will restrict drawing to
the appropriate portions of the screen.

You could then draw everything underwater first with a blue
ambient light. Then draw everything abovewater with the right
sky color.

You could also use the clipping planes to write into one bit of
a stencil buffer to distinguish between abovewater and
underwater.

This method also has the advantage that newer hardware, such
as the GeForce and the Radeon, support this on the video card.

Share this post


Link to post
Share on other sites
The method descibed above might work, but I think it would really slow. All you really have to do is calculate where the plane interects the back face of the camera''s viewing volume, and then use the method of drawing a transparent quad like wolfman8k says. the quad wouldn''t be covering the whole screen, but it would cover the part that is underwater. you would use the planes normal to figure out whether you draw the quad above or below the center of the screen, and you would use the line of intersection to determine the other side.

Share this post


Link to post
Share on other sites
Why use a transparent texture when you can just use a glColor3f() to tint the texture blue?

I would personally use Anons method, as otherwise you are restricted to flat water. The only modification would be to draw the above-water stuff first (to fill the depth buffer), then draw the below-water parts as most of it won''t get rasterised due to the depth buffer, saving time. If you drawn the below-water stuff first, each pixel will be rasterised twice, which is not an ideal solution.

The clipping plane idea closely mimics how a real camera works. In a real camera the aperture is very close to being a point (less than 1cm across), like the OpenGL camera. The ''half above, half below'' effect we have all seen on TV is due to the lens (which is much bigger) acting as a clipping plane to the water.

Dan

Share this post


Link to post
Share on other sites
A cheap way to do it is to enable FOG. SO when you drop into the water, you enable a nice blueish/green fog. It does work pretty good.

Share this post


Link to post
Share on other sites