Nice UC, pretty handy yes smile smile
When looking at a water shader, their are 2 things I immediatly look at since they are quite important for a proper water shader:

- Fresnel term
- lerp function

1) Regarding Fresnel, the function you used isn't fully correct although it is an approximated version but abit rough wink wink
This is a better approximated version of the Fresnel term:

// Schlick's approximation, accurate to within 1% ^^
const float FRI = 0.01f; // FRI is the Fresnel reflectance index of the material at normal incidence
float F = FRI + (1 - FRI) * pow((1 - N.V), 5.0f);

Important note is that this function is mostly used for outdoor scenes but it would fail in indoor games. The reason therefore is that attenuation is used for indoor light sources.

2) Regarding the lerp function, it's better to combine your color calculations within the pixel shader via lerp. Look at the beaty of the methode:

lerp(a,b,c)
// returns a + c.(b-c)
// when c = 0, a will get returned
// when c = 1, b will get returned

Thus when using this as a final calculation with water, you should input the corresponding parameters relative for a water shader to achieved a plausible output:

color = lerp(reflectColor,refractColor,F);

Not that your code was ineffective since the effect looks pretty nice but just to enhance the importance of little intrinsic functions smile smile

Thanks in progress

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB