Archived

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

adam17

Question about making water

Recommended Posts

im working on a water effect demo (not for the contest) and i need some opinions on what will work, or look better. i am using shaders for the surface to create the illusion of waves. the shaders take animated normal maps to control the refraction. i am left with an extra ray that i need to show the bottom under the water surface. how should i look-up the bottom? should i use a static cube map (will not look good at edges of pool) or is there a way to make it dynamic. when i say dynamic im saying you can place this texture onto any polygon and it will start refracting what is on the other side. make sense? thanks ahead of time.

Share this post


Link to post
Share on other sites
i started thinking about this a little bit more. how is raytracing done? i was thinking that once i found the angle and the vector i could blend it to the texture color of the water surface. im gonna check the render to texture thing in the mean time.

Share this post


Link to post
Share on other sites
Raytracing is a very bad idea if you want a frame rate over 1 fps

I''ve seen nice water made with perlin noise (for waves) and cube map for a "reflective" look.

Share this post


Link to post
Share on other sites
i have been looking around for raytracing and have noticed that it is VERY inefficient like u said Krohm. i have also been researching rendering to textures. if im understanding it right i would have to do a gllookat for every pixel that the water exists on. i think im wrong... is there any way to make the refracted textures dynamic or am i stuck with cube maps? im especially going to need it if a guy falls into the water and hits the bottom. u cant see him if there are only static cube maps.

sry im being so picky

Share this post


Link to post
Share on other sites
quote:
i have been looking around for raytracing and have noticed that it is VERY inefficient like u said Krohm.

I didn''t said it... someone other did.
quote:
If im understanding it right i would have to do a gllookat for every pixel that the water exists on.

No, you are not wrong. You need to look up somewhere to recognize where the ray goes but it is not accomplished using gluLookAt - this is a variant property you have not access to and even if you would, performance would be a real pain.
If you''re using fixed function pipes you''re in bad troubles. If you can use ARB_vp + ARB_fp then you''re more lucky. NVSDK has some demos on refractive and reflective water which is dinamically computed on GPU using render targets. Translating to the new programmable pipelines should be fairly easy.
Once you thought at how you need to make everything work, you''ll figure out you''ll just need a texture indirection to lookup a cubemap (maybe it''s possible to use a 2D texture but I am not sure).
As for having dinamic texturing, this is just a problem of updating it properly every X frames (where X can be every frame). This won''t take so long since the "environment map" does not need to be high resolution (no one will ever pay too much attention on it).

Share this post


Link to post
Share on other sites
I found this quite useful in a water effect I found a while ago..

Its really fast because it doesnt use trigonometric functions.
Also the ripples will reflect on the edges too...

The only downside is that the ripples seem to be slightly diamond shaped.

This can be fixed by altering the weighting on the neighbouring verticies ( 1/distance for each point works best)

http://freespace.virgin.net/hugo.elias/graphics/x_water.htm

Share this post


Link to post
Share on other sites
two questions for you Intamin:
1. i have read articles on creating cube maps. i cant figure how to store them. you wouldnt know how to store them with ipicture or DevIL would you? ipicture doesnt work to well (at least from my experience) for making cubemaps because it uses GL_TEXTURE_2D. anyway none of the articles really explain how to call the cube maps or how to use them. how do you get the components for glTexCoord3f()?
2. what would be a 2D wave equation? sin waves in both the x any z planes?

[edited by - adam17 on October 15, 2003 1:30:39 AM]

Share this post


Link to post
Share on other sites
You can render the cube map each frame without using an image library. If you do a search for "dynamic cubemaps", I'm sure you'll find whatever you're looking for.

It's basically just rendering your scene to a texture 6 times for each cubemap (use a 90 degree perspective and rotate for each face of the "cube").

Nehe has a tut about rendering to a texture that should help you out. I think I have some code that does it, that I could post... if you still can't figure it out.

[edit] I'm feeling especially nice tonight

Set up for rendering:

glPushMatrix();

//Set viewport (doesn't have to be 256 x 256)

glViewport(0, 0, 256, 256);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//Set the perspective to 90 degrees

gluPerspective (90, 1.0f, .01, 100);

glMatrixMode(GL_MODELVIEW);


Now, to store each "face" of the cubemap:


//do your rendering code for each face here



glEnable(GL_TEXTURE_CUBE_MAP_ARB);
//Bind the cube map.

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, CubeMap);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, 0, 0, 0, 0, 256, 256);

glFlush();
//Disable cube mapping.

glDisable(GL_TEXTURE_CUBE_MAP_ARB);


Where it says GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, you need to change that for each face (so that you update the entire texture each frame and not just 1 side) to its coresponding angle.

GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB

Now all you need to do is reset your viewport and perspective to whatever it was before.

That should help some. You have to initialize the cubemap before you can start rendering to it, but I'll let you figure that one out.




[edited by - Halibut on October 15, 2003 4:47:55 AM]

Share this post


Link to post
Share on other sites
thanks alot Halibut. i have one quick favor to ask. can you give me the address(ex: 0x4f37) for GL_TEXTURE_CUBE_MAP_ARB. my card is a gf4ti4600 so i know it supports it.

Share this post


Link to post
Share on other sites
Copy and pasted straight from my code:

#define GL_NORMAL_MAP_ARB 0x8511
#define GL_REFLECTION_MAP_ARB 0x8512
#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A


Hope that helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Halibut

That should help some. You have to initialize the cubemap before you can start rendering to it, but I''ll let you figure that one out.


quote]

Could you tell me how to init it ? Im realy enw Coding Wise and want to kniow a bit moe on this cube mapping

Share this post


Link to post
Share on other sites
Hey guys. This is not meant as a troll or an attack or anything, just a clarification.

Ray tracing is not "inefficient". It produces mathematically correct images, and can be quite fast if implemented properly.

That being said, it still isn''t appropriate for realtime rendering of anything useful...yet. :-)

Share this post


Link to post
Share on other sites