PDA

View Full Version : water question



JanHH
10-22-2003, 07:18 PM
Hello,

I am planning to do water (ocean size, not pond) simply as a dark blue bump mapped surface (bump mapping of course with shininess) with the wave surface shape as the bump map (no reflections, environment mapping etc.). This sounds quite easy, so I wonder what you guys (and girls) think about it!? Is there a chance of getting a good result?

Thanks
Jan

Zeno
10-22-2003, 08:45 PM
Unfortunately, I think your water will come out looking like plastic if you just make it a bump-mapped surface with specular.

IMHO, the single most important optical phenomena in water is the Fresnel reflection. You have to have at least that to get it to look right. If doing the actual reflection is too much for some reason, I bet it would still look good just using the Fresnel term to interpolate between 2 colors (approximate sky color and upwelling color).

JanHH
10-23-2003, 03:17 AM
I already thought about "might it look too much like plastic?", but somehow I have the impresion that "ocean" water does in fact look like plastic a bit (for example http://www.cs.utah.edu/~michael/water/deepWater1.jpg), and at least it would be a starting point, I do not know anything about water rendering, have never done bump mapping (and of course don't know what the fresnel equation ist *g*). Isn't it quite hard to do the "actual reflection"? How would that be done anyway, environment mappint? What is _the_ way to do cool water at the moment?

Sorry for my lack of knowledge and thanks,
Jan

AdrianD
10-23-2003, 04:52 AM
i don't think the water in this screenshot looks like plastic...
however, if you need more infos about water rendering try this:
http://www.gamasutra.com/gdce/2001/jensen/jensen_pfv.htm
(an article called "Deep-Water Animation and Rendering")

SirKnight
10-23-2003, 05:01 AM
This guy has a really cool ocean demo based off of that gamasutra articles and a few others. Here's the link: http://meshuggah.4fo.de/ He uses vertex programs and register combiners for all of it.


-SirKnight

JanHH
10-23-2003, 05:59 AM
thanks :-) in the gamasutra article, the guy also talks about rendering the surface to a bump map. So I guess I could at least _start_ with this? Or is this a totally useless effort and I will have to rewrite all of it later?

Jan

SeskaPeel
10-23-2003, 07:08 AM
For information, you can see here what I made with Fresnel, bump mapping, cubic reflection, and cubic diffuse lighting : http://dev.succubus.fr/Shot1.JPG

All this runs in a heavy pair of vertex/fragment program.

SeskaPeel.

vember
10-23-2003, 09:12 AM
You probably want to incorporate the fresnel effect in some way, even if it's only done at the vertex level.

And to continue on the theme of this thread, this is what my current water implementation looks like at the moment:
http://claes.galaxen.net/ex/images/demo_october2.jpg

There is a dx9-demo (nv20+) as well if you look around, but it might be a little weird atm as it is a work in progress..

I'm using a fresnel texture-lookup, cubemap and all calculations are done in a linear-colourspace. The geometry is based on a perlin noise derivative, and done on the CPU with a projected-mesh concept that i'm developing.

[This message has been edited by vember (edited 10-23-2003).]

Zeno
10-23-2003, 09:18 AM
Well, geez, if everyone else is going to post screenshots, I better get mine in too:

http://www.sciencemeetsart.com/wade/Projects/WaterFX2/

JanHH
10-23-2003, 09:28 AM
thansk for all your replies http://www.opengl.org/discussion_boards/ubb/smile.gif. zeno, your screenshots show about what I'm trying to achieve. I'm still naive enough to believe that simple bump mapping (with specular of course) and the bump map constructed from the water surface geometry should look at least a little bit like that, am I so wrong?

Jan

Zeno
10-23-2003, 10:12 AM
Only one way to find out, right? http://www.opengl.org/discussion_boards/ubb/smile.gif

I don't think it'll look horrible, it just won't look like a liquid. Look at the subtle coloration of the water in this shot: http://www.sciencemeetsart.com/wade/Projects/WaterFX2/WaterFX2_03.jpg . Notice how you see more of the water color nearby and more of the reflected sky color at a distance? If you use just a diffusely lit bump-mapped surface, your shading will look the same everywhere. This issue will become more apparent when the surface is animated.

You have to decide what is right for your project depending on how good you want the end result to be and what hardware you're running on.

JanHH
10-23-2003, 01:42 PM
the problem is, the most advanced OpenGL feature I have used until now is multitexturing, I am totally new to bump mapping, and good water seems to be a lot more complex than that, so I have to start with something.. and I guess this is a good place to start.

jwatte
10-23-2003, 02:47 PM
Simple specular bump is a fine place to start.

Btw: nice cresting effect in that WaterFX image (#3). Cresting is notoriously hard.

JanHH
10-23-2003, 03:27 PM
another simple question: assuming that the vertex normals of my water plane and the light vector are in the same coordinate space (and they are, world coordinate space, no transformations or rotations), and I create a normal map which is also in the same coordinate system (x pointing to the right, y pointing up, z pointing backwards along the plane), I do not neccessarily need the tangen space stuff!?

thanks
Jan

JanHH
10-23-2003, 03:56 PM
and one more question (sorry that this is in the advanced forum, i guess it is rather beginner level): if I got it right, I load the first texture unit with the normalization cube map (with the light vector as tex coords) and the second one with the normal map (with "standard" tex coords) and set the texture combine mode for the first texture unit to GL_COMBINE and for the second one to GL_DOT3_RGB_ARB. this will do a dot product of the two "colors" resulting from the textures. And the I would like to load the material texture ("image" texture, not normal) to the third texture unit and modulate it with the dot product which results from the preceeding operation. but how is this done?

thanks a lot,
Jan

JanHH
10-24-2003, 01:29 AM
I more and more get to thinking that all bump mapping efforts are useless if I do not fully understand how the texture combiners work (GL_COMBINE_EXT, not register combiners, this is still too advanced for me *g*). But I cannot find any real documentation.. plz someone help, I am getting desperated http://www.opengl.org/discussion_boards/ubb/wink.gif.

Another thing that puzzles me: When computing a dot product between to vectors, I am expecting to get a single number as result. But what happens in OpenGL? Do I get a color value?? If so, is this a shade of grey?

thanks
Jan

satan
10-24-2003, 04:05 AM
Originally posted by JanHH:

Another thing that puzzles me: When computing a dot product between to vectors, I am expecting to get a single number as result. But what happens in OpenGL? Do I get a color value?? If so, is this a shade of grey?

thanks
Jan

The result of the dot product is put in the rgb(a) components of the output. This means all components have the same value, which is a shade of grey.

knackered
10-24-2003, 04:53 AM
Originally posted by vember:
You probably want to incorporate the fresnel effect in some way, even if it's only done at the vertex level.

And to continue on the theme of this thread, this is what my current water implementation looks like at the moment:
http://claes.galaxen.net/ex/images/demo_october2.jpg

There is a dx9-demo (nv20+) as well if you look around, but it might be a little weird atm as it is a work in progress..

I'm using a fresnel texture-lookup, cubemap and all calculations are done in a linear-colourspace. The geometry is based on a perlin noise derivative, and done on the CPU with a projected-mesh concept that i'm developing.

[This message has been edited by vember (edited 10-23-2003).]

vember, I've had a look at your projected-grid stuff - demo and papers. I have to say it looks very impressive - makes every other height-map LOD scheme redundant as far as I can make out. It's a similar approach to one I've been considering for a while - sort of rasterizing a height map as if it were a polygon in screen space with perspective-correct texture mapping concepts thrown in for good measure.
But having read your papers, I'm still confused as to what your concept actually is exactly. Could you try to explain in a few sentences exactly what you're doing?

vember
10-24-2003, 06:42 AM
Originally posted by knackered:
vember, I've had a look at your projected-grid stuff - demo and papers. I have to say it looks very impressive - makes every other height-map LOD scheme redundant as far as I can make out. It's a similar approach to one I've been considering for a while - sort of rasterizing a height map as if it were a polygon in screen space with perspective-correct texture mapping concepts thrown in for good measure.
But having read your papers, I'm still confused as to what your concept actually is exactly. Could you try to explain in a few sentences exactly what you're doing?

sure, i'll try to be more clear (and will update the papers at a later point). When you've had your head around something for a while it seems much more obvious than it actually is.. http://www.opengl.org/discussion_boards/ubb/smile.gif

The basic idea is really simple. I wanted a grid that looks just like a uniform grid on screen, but I wanted it in worldspace so i could displace it. This will be something like a continous LOD by retaining the perspective properties of the camera transform.

To do this I project an uniform grid with the inverse view-proj matrix of the camera to get their coordinates in worldspace. If you look at it from the outside, it will look exactly like a regular projector but casting geometry instead of light. In fact, it was designed so that it all could be done by a rasterizer and stored in a vertexbuffer.

The problem is only that this does only work as it should if no pixels of the cameras is of a direction that is pointing away from the plane and no displacement is used. (If aimed away from the plane the vertices will backfire through the camera and the geometry will be broken)

This is where all the real work comes in, I solve this by creating a projector that I can aim (by setting it's direction and x/y-range of the originating grid in screenspace) and move to make it cover the intersection of the cameras frustum and the displaced surface volume. It is supposed to do this in a way that avoid discontinuities and distribute the geometry in a decent way. I'm still working on this, but the current implementation works fairly well (especially if you set the levitation parameter to around 3, this limits the projector from coming to close to the plane).

A note about the implementation is that the wave-generation and projection is done in software at the moment (the hardware path is broken). It was designed to be 100% hardware though, and the thing that is holding it back is that current API's cannot use a vertexbuffer as a rendertarget, which forces it use AGP reads which ruins the performance completely because it stalls the pipeline.. I wouldn't mind if überbuffers where around by now :P ..

Don't hesitate to ask if you're wondering about something..

-claes

[This message has been edited by vember (edited 10-24-2003).]

vember
10-25-2003, 01:56 AM
oh, and by the way. I forgot to mention that i do the projecting on the plane by setting up an equation of a line that goes through a point on the view plane (like ray-tracing) and use the plane-equation to see where it intersects in world-space.

JanHH
10-31-2003, 01:57 AM
so, I got it.. for sure not the best looking water ever rendered by a computer, but for a start (and my first program EVER with anything above OpenGL 1.2 http://www.opengl.org/discussion_boards/ubb/wink.gif ), it is quite ok (it's animated, looks great, at least so do I think *g*).. what do you think? I would appreciate any comments.. please be honest http://www.opengl.org/discussion_boards/ubb/smile.gif.
http://de.geocities.com/westphj2003/water.html

Jan

Ysaneya
10-31-2003, 02:57 AM
You want an honnest answer? Ok :)

To me it looks like a simple texture mapped plane with a kind of "glow" effect. Maybe it's better animated, but it certainly does not look like water at the moment. It does not even look reflective.

Y.

JanHH
10-31-2003, 04:53 AM
hm. I really think it looks (at least a little bit http://www.opengl.org/discussion_boards/ubb/wink.gif ) like water in an ocean viewed from a certain distance, like flying over it in a helicopter. It is not texture mapped at all and is bump mapped with specular hightlights, I don't know if one would call that "reflective", and the waves are moving (perlin noise). I really think it looks quite like water http://www.opengl.org/discussion_boards/ubb/wink.gif

Jan

DJSnow
10-31-2003, 08:35 AM
at the first view i thought the same as ysanyena; but the other screenshots looked more real, if you ask for my opinion.
but i think a video or executable for everyone here wouzld be the best way to make a real pic of your algorithm.

JanHH
10-31-2003, 04:23 PM
posting an executable is impossible as it is part of a copyright protected piece of software, and it would be a lot of megabytes, too http://www.opengl.org/discussion_boards/ubb/wink.gif. But I would like to capture a video if only I knew how? Is there a program that captures what's going on on the screen and stores is as an mpeg file, and does all this under linux?

The algorithm is extremely simple, it's a 2D Perlin noise function generating a heightmap, which is turned into a normal map, which is rendered in two passes (diffuse and specular), using tex_env_combine_arb (or whatever it is called http://www.opengl.org/discussion_boards/ubb/wink.gif ), no nv register combiners, no vertex or fragment programs, only me learning to do bump mapping http://www.opengl.org/discussion_boards/ubb/wink.gif. And then, there's not one but 100 normal maps, generated from 100 heightmaps (kind of an animated perlin noise function) which are cycled, so it looks really moved, like an ocean with heavy weather and strong rain.. If it's possible I would really like to capture a video and post it.

Jan

ioquan
11-03-2003, 05:02 PM
I did not read the whole thread, but I wanted to reply to some of the things I saw in the first few posts, and give some advice based on my experience with implementing water rendering.

First of all, fresnel refractions are only applicable to shallow water in which you can see through to the bottom, and therefore are not used in oceans at all. Plus, the technique used to achieve them is best suited to man-made geometry like a swimming pool, and not for things like shallow ponds. Fresnel refractions arent what make the water look less plastic. In actuality, water looks plastic if the intensity of the cube map (cube maps are used for reflections and other coloration effects - see Jensen's article) is too high. This can be reduced by using alpha transparency and fiddling with texture combine settings with GL_ARB_texture_env_combine.

As for real-time generated bump maps (or precalculated ones, for that matter), what Jensen is referring to is EMBM using a bump map and a cube map. I have not been able to implement the EMBM technique because my video card does not support the neccessary extensions, but this will give you a huge improvement over a cube map with normals specified per vertex.

A note on calculating bump maps, waves, etc. I would not suggest trying to calculate this stuff in real time. I found an open source demo that implements many of the techniques described in Jensen's paper. I hacked it to do two things: create an animation that will repeat after a certain amount of frames, and write this animation (wave geometry and bump map) out to a binary file which is then loaded by my program. If anyone is interested, I will make my hack available on my website. Using the precalculated animation is much easier to implement, and runs much faster, but it requires a significant amount of memory.

I would say that you can count on at least using one texture unit for a cube map. The cube map should be taken from your skybox, and modified in an image program to add a transparent gradient over the skybox image which will give you different colors based on the viewing angle. After you do this, the cube map for the water will be darker/bluer/greener than your actual skybox image. You can then "re-burn" in the image of the sun to get highlights from the sun.

Btw, here are the latest screenshots of my water engine (top 3 are newest) http://users.ms11.net/~ioquan/j2.html .

I was going to write a tutorial on water rendering, but I was never satisfied with the results I achieved. This is mainly because I couldnt do the EMBM effect with my video card.

ioquan
11-03-2003, 05:07 PM
just looked over the rest of the thread..

A couple of you guys have some realllly nice screenshots. They kind of put mine to shame.

Just wait til I get a hold of hardware that can do vertex, texture, and fragment programs though http://www.opengl.org/discussion_boards/ubb/smile.gif

JanHH
11-03-2003, 05:23 PM
loquan i almost did the same as you, I just don't have a reflection but simple blue color and bump mapping with white specular hightlist, but the water surface (=normal maps) are precalcuiated and simply cycled. I agree that an ocean is not translucent at all if it's not very shallow, so if you think of the sky being simply blue, a simple blue bumpmapped plane is not so wrong http://www.opengl.org/discussion_boards/ubb/wink.gif.

what is your water animation based on? I implemented some kind of "animated perlin noise".

Jan

vember
11-04-2003, 08:05 AM
ioquan:
you misunderstood what the fresnel-reflectance is. It gives the relation between how much light is reflected and how much light is refracted in a point of the surface, depending on the normal and view-vectors.

If you don't want to use refraction because of the reasons you mentioned, then just set the refracted part to a constant colour (which will be the colour of your water).

You say one should fiddle with the intensity of the cubemap. Fresnel is _the_ physically correct way to calculate this. If done right, it will look flawless.

JanHH
11-04-2003, 01:59 PM
do you have any links regarding fresnel? I couldn't find anything I understood http://www.opengl.org/discussion_boards/ubb/wink.gif.

Jan

ioquan
11-04-2003, 02:23 PM
vember, doesnt the Fresnel term also determine the direction of the reflection or refraction vector?

In my case, since I dont have access to fragment programs, texture programs, or vertex programs, I simply use a cube map with GL_REFLECTION_MAP to do reflections of the sky. The amount of reflection or refraction (refraction is simulated with an animated texture) in my demo comes from the alpha channel encoded into my cube map which is used in texture combining operations.

vember
11-05-2003, 12:04 AM
yes, I mistakenly supposed it was covered by another formula, but both the reflectivity and refraction angle/vector can be derived from it. (the reflection angle is trivial because it doesn't depend on the IRO, aka 'index of refraction')

I didn't find any nice url to explain it all but you can have a look at my matlab-code that I use to generate tables for this use.

This will build a table of 256 values that represent the range [0..1]. It should be fed with the dot-product of the normal and the vector between the camera and the point on the surface being rendered. If used as a 1-D texture, it should be clamped to the [0..1] range.

% fresnel reflection
n = 1.33; %IOR of water

for a=0:254
alfa = acos(a./255);
theta = alfa./n;
F(a+1) = 0.5.*( (sin(alfa-theta)./sin(alfa+theta)).^2 + (tan(alfa-theta)./tan(alfa+theta)).^2);
end
F(256) = F(255); % will go crazy otherwise

Tom Nuydens
11-05-2003, 12:18 AM
Originally posted by JanHH:
do you have any links regarding fresnel? I couldn't find anything I understood http://www.opengl.org/discussion_boards/ubb/wink.gif.

Seen the NVidia paper? http://developer.nvidia.com/object/fresnel_wp.html

-- Tom

JanHH
11-05-2003, 12:30 AM
thx http://www.opengl.org/discussion_boards/ubb/smile.gif but what is the difference in the screenshots in the paper? to me they all look the same http://www.opengl.org/discussion_boards/ubb/wink.gif

Jan

Tom Nuydens
11-05-2003, 02:16 AM
Yeah, the shots don't really highlight the effect. What you'll get if you implement fresnel is that the water will look translucent if you look straight down at it, and reflective if you look at it from a grazing angle.

-- Tom

henrikd
11-10-2003, 02:46 PM
For more on the Fresnel Equation, you could also try to read this article (assuming you have access to ACM or a library with old Siggraph's):

@Article{Cook82,
author = {Robert L. Cook and Kenneth E. Torrance},
title = {A Reflectance Model for Computer Graphics},
journal = {Transactions on Computer Graphics, ACM Press},
year = 1982,
volume = 1,
number = 1,
month = {January},
}


Or try to find one of these books, where the topic is also discussed:

@Book{watt92,
author = {Alan Watt and Mark Watt},
title = {Advanced Animation and Rendering Techniques: Theory and Practice},
publisher = {Addison Wesley},
year = 1992,
}

@Book{Foley96,
author = {Foley and van Dam and Feiner and Hughes},
title = {Computer Graphics: Principles and Practice},
publisher = {Addison Wesley},
year = 1996,
edition = {2nd},
}

/Henrik