PDA

View Full Version : [OpenGL] Water & the Stencil Buffer



WILL
12-03-2009, 11:02 PM
I've been looking into the Stencil Buffer lately in an attempt to make my first actual 3D effort with a little water demo. Any tips, etc would be appreciated as this is rather new to me. I've read the Red Book somewhat but it's still fuzzy to me how it works. Anyone care to break it down into an easy explanation? :S

Ultimately I'm going to be putting my generated water into Garland's Quest after I'm done. So you kind of get the idea of what type of effect style I'm going for. More a lake or pond type of water than an ocean type of water.


Here are some resources I'm reading to get my information:

Stencil Buffer overview (http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node117.html)
a brief 'How to do water' (http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node332.html)

a glscene demo's way I'm trying to follow using the stencil buffer (http://glscene.cvs.sourceforge.net/viewvc/glscene/AdvDemos/Archipelago/Unit1.pas?revision=1.10&view=markup)

a whole shpeal on Perlin noise (http://freespace.virgin.net/hugo.elias/models/m_perlin.htm) <- I think this is supposed to be more ocean water than lake or pond type water?
GameDev.net article about how to do it, but the effect is more so for rain or water-drop effects than a tidal water motion (http://www.gamedev.net/reference/articles/article915.asp)

a Very Cool Caustics Generator program that creates those really neat lighting effects on the bottom of a pool or shallow clear waters (http://www.dualheights.se/caustics/) <-- I've made up textures to use from this as the effect is very nice.
The Volition demo's water here looks great but I'm not sure I want to dig right in there and try to extract and recreate it... (http://www.sulaco.co.za/opengl.htm)

Anyhow comments and sugestions or heck, simple code! would be well appreciated. ;)

WILL
15-03-2009, 02:34 PM
I did it! This is also my first 3D program btw! 8) Yay for me... updated my blog with the details and a link to a little demo of it. Have a look for yourselves. ;)

http://redantproductions.blogspot.com/2009/03/i-made-water.html

noeska
15-03-2009, 06:07 PM
Looks good, but kind of plastic though.

For 3das i took a more basic approach. I just took a water texture aplied that to a plane that i made transparent. That was enough for me back then.

Basicly a stecil buffer is what it is&#160; a stencil.
E.g. take a piece of paper. Cut a round shape in the middle.
Apply it on another piece of paper. Get some paint and paint over the top paper completely even over the hole.
Now when you remove the top paper you have painted round shape on bottom piece of paper.

For opengl look at this classic example:
http://www.opengl.org/resources/code/samples/mjktips/Reflect.html

Andreaz
15-03-2009, 08:35 PM
I wrote a demo a while ago using some nice water in Glxtreem, it was ages i touched it so i'm kindof rusty of what i did, but take a look anyway!

http://phoenixlib.net/files/glxWater.zip

WILL
16-03-2009, 04:34 AM
Well this is going into Garland's Quest (http://www.pascalgamedevelopment.com/forum/index.php?topic=3793.msg45335#msg45335) so I don't think that a little surrealism will hurt. :) I just have to remove a funny little glitch that appears along the edges.

As for the Stencil Buffers well that's something to tackle down the road I think. Thanks for the explanation and links. I'll be bookmarking and looking it up in the near future I'm sure. ;)

Next thing I think I need to learn is lighting and how to make better use of light... it would add to the shine and watery look would it not?