|
/* Shader description goes here */
surface
water(float Ka = 1, /* ambient brightness */
Kd = 0.5, /* basic brightness */
Ks = 0.7,
kenv =0.5,
cap_cutoff = 0, /* hilite brightness */
roughness = 0.1; /* hilite spread */
color hilitecolor = 1,
capcolor = 1,
capcolor2 = 1; /* hilite color */
string envname = "" ,
envspace ="object")
{
color ambientcolor, diffusecolor, speccolor,
surfcolor = Cs;
/* STEP 1 - make a copy of the surface normal one unit in length */
normal n = normalize(N);
normal nf = faceforward(n, I);
/* STEP 2 - set the apparent surface opacity */
Oi = Os;
/* STEP 3 - calculate the lighting components */
ambientcolor = Ka * ambient();
diffusecolor = Kd * diffuse(nf);
vector i = normalize(-I);
speccolor = Ks * specular(nf, i, roughness) * hilitecolor;
color envcolor = 0;
if ( envname !="") {
vector R = vtransform( "world", reflect(n,i));
envcolor = environment (envname, R)* kenv;
}
//get caps value
float height = 0;
if (displacement ("caps", height) == 1) {
if(height > cap_cutoff)
//surfcolor = capcolor;
float blend = smoothstep(cap_cutoff - 0.05,cap_cutoff + 0.05, height);
surfcolor = mix(capcolor,envcolor,blend);
}
/* STEP 4 - calculate the apparent surface color */
Ci = Oi * surfcolor * (ambientcolor + diffusecolor + speccolor+ envcolor);
}
|