The essence of a realistic water shader is the sine wave.
By layering sine waves of different sizes from different directions and then animating each one, a realistic rippling surface can be created.
|
|
wave_sample
/* displacement magnitude */
(float Km = 0.1,
/* number of waves in one uv tile */
macro_freq = 5,
/* offset to animate */
phase = 0.5,
string coordsys = "object";)
{
float hump = 0; normal n = normalize(N);
/* create the basic wave */
point p = transform(coordsys, P);
float wave_macro = getWave(s, macro_freq, phase, 0, p);
hump = wave_macro;
P = P - n * hump * Km; N = calculatenormal(P);
}
LIBRARY FUNCTION
float getWave(float angle, freq, phase, chop; point p)
{
return sin((angle + phase) * 2 * PI * freq);
}
|