I am actually not using a cube map.
I render the world three times. One extra for reflection and one for refraction. So if I add some models or a dynamic sky, they would be nicely reflected/refracted too.
It goes something like this:
m_pbuffer->enable(); //Should probably use the new OGL 2.0 stuff, which I don't //remember the name of right now.m_camera->LookReflect(m_waterHeight);glEnable(GL_CLIP_PLANE0);glClipPlane(GL_CLIP_PLANE0, m_reflectPlane);Render_Things_That_Should_Be_Reflected();m_reflectTex->CopyFromViewport();//Then same thing for refraction, but set the clipping plane to only render underwater stuff//Then render everything like normal and the water with a pixel/vertex shader
The reflection and refraction textures are then distorted with a normal map.
This is the fragment (I'm using CG...) shader:
float3 dir = normalize(eyeDir.xyz); // I don't use this yet float3 normal = tex2D(normalMap, t1.xy).xyz - tex2D(normalMap, t2.xy).xyz; t0.xy += normal.xy * eyeDir.w; // Reflection coordst3.xy += normal.xy/2.0f * eyeDir.w; // Don't want to distort the refraction too much... float3 reflect = tex2Dproj(reflectMap, t0).xyz;float3 refract = tex2Dproj(refractMap, t3).xyz; col.xyz = lerp(refract, reflect, 0.7f) + float3(-0.05, 0.0, 0.05); //Just to make it a little more bluecol.a = 1.0;
This is a quite simple shader and I haven't worked much on it. The normal map isn't as good as I want and I should also add some fresnel stuff like skittleo suggested.
[Edited by - MickePicke on July 1, 2005 12:41:57 PM]