• Advertisement

Archived

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

Water with reflections

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to add ''kind of'' realistic looking water to my program, so I thought I would make some simple water and add the cool complicated stuff when I get this running normaly. So the water I want to implement right now could be like this: no refractions, fresnel & stuff, just reflections and waves. To make it simpler for now - just reflect the skybox not the actual geometry in the scene, and also have the water as one big quad - since I dont want to change the Y coords of the actual mesh, atlweast for now. So I thought I could do something like this each frame: 1) Use Perlin noise or something to generate the water heightmap. 2) Calcualte normals from that map and store them in a normalmap. 3) Bind the normal map to an OpenGL texture. 4) Calculate the quad where my views frustum intersects with the water plane. 5) Draw the water with a Cg pixel shader whose pseudo-code would be something like this: a) Normal=getNormalFromNormalmap(NoiseMap,Position*noisescalefactor); b) TexCoords=reflect(EyeVector,Normal); c) Color=getCubeMapColor(SkyCube,TexCoords); What I''ve got now is steps 4 & 5 (I use a normalmap created in a paint program). So I have a couple of questions: Should I use Perlin noise or is there something better (runs faster when implemented) for the height map? Or can I somehow generate the normalmap without creating the heightmap? And how can I update (bind) the normal map fast each frame (calling gluBuild2DMipMap... every frame doesnt sound very fast to me ) And also if I have to use Perlin noise, how can I make the noise be ''tiling'' or ''repeating'', and also how can I do perlin noise generation so the noise is ''a bit modified'' noise from the previous frame, not a completely new noise each frame?

Share this post


Link to post
Share on other sites
Advertisement
I cant answer all your questions as I know nothing about OGL, but...

>>Should I use Perlin noise or is there something better (runs faster when implemented) for the height map?

Perlin noise can be optimized to run fairly quickly. Theres a number of "fake" Perlin noise algos out there. I dont have a link or anything but you could try a search. Really though, your noise could be generated at load time, so it may not be an issue anyways.

>>Or can I somehow generate the normalmap without creating the heightmap?

Not really.

>>And also if I have to use Perlin noise, how can I make the noise be 'tiling' or 'repeating', and also how can I do perlin noise generation so the noise is 'a bit modified' noise from the previous frame, not a completely new noise each frame?

Both of these issues are addressed by adding another dimension to your noise. This extra dimension can be though of as time. So you'd have a 3D noise map. x, y, and time.

[edited by - Corroded on May 7, 2004 1:55:54 PM]

Share this post


Link to post
Share on other sites
I''m not sure what you mean by:

Perlin noise can be optimized to run fairly quickly. Theres a number of "fake" Perlin noise algos out there. I dont have a link or anything but you could try a search. Really though, your noise could be generated at load time, so it may not be an issue anyways.

How can I pre-calculate the water heightmap and have an animated water? Generate a few maps and then interpolate between them or something? And how fast can a perlin noise be? I tried to rip some code from one and got a 5 octave 256*256 map in 0.13 sec (on a P4 2.5 Ghz) - slow to say the least, but how fast can you possibly get it?

Share this post


Link to post
Share on other sites
Perhaps you could go with one static "perlin-noise-map" and manipulate the texture matrices each fram and animate them in some fancy way?

Good luck


--Spencer

"All in accordance with the profecy..."

Share this post


Link to post
Share on other sites
Any ideas for the "fancy way" ? All I''ve tried result in that the water becomes wave-less at times and there is always some kind of unnatural-repeating wave pattern.

Share this post


Link to post
Share on other sites
Could someone just point me in the direction to keep working on? What good water implementations have you done/seen? Should I do per frame height/normal map calculations? Precalculate them for a series of frames? Precalcualte for like every 0.2 or something seconds and interpolate?

[edited by - Bouga on May 8, 2004 4:21:19 PM]

Share this post


Link to post
Share on other sites
I''ve looked but I cant find the links I had for the "fake" perlin noise. There are other kinds of noise that can be run faster, but in general perlin noise looks best.

It all comes down to adding the time dimension to your 2D noise map, effectivly creating a 3D noise map where the z element of the map is incremented by a timer. This way, your map can be generated a load time, since the water animation is effectivly calculated for as long as you want to store it. I suppose once you reach the end of your time dimension, you could loop backwards again. I''m not sure how this would look, you''d have to test it. Alternatly you could somehow ensure that your last time-dimension map, matched your first one, and you could simply restart from the begining.

This is Ken Perlins Improved implementation:
http://mrl.nyu.edu/~perlin/noise/

And the origional:
http://mrl.nyu.edu/~perlin/doc/oscar.html

I seem to be missing a bunch of my bookmarks somehow, because I once had a site which described this in great detail. ... Wait on second... Aha! I did a google search and found it again:

http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

That site explains how to use a 3D Noise Map with a time dimension.

HTH

Share this post


Link to post
Share on other sites
With a properly sized gradient lookup table and decent interpolation, the noise will be contiguous over the boundaries. "Ping-ponging" the animation is not a good thing, the best way to see why is to test it

Share this post


Link to post
Share on other sites
Thanks, I''ll see what I can do with some precalculated height maps and some interpolation.

Share this post


Link to post
Share on other sites

  • Advertisement