/* * neck_band.sl * * coloring for duck's neck band: * feathers out at slant of band * The feathering can either be via transparency or * by shading in another color, the face_to_color * * M. Geroch * TV Digital Lighting HW 5 * Spring, 1996 * */ #include "/usr/local/accad/shaders/rmannotes.sl" surface neck_band(float topangle = radians(25), bottomangle = radians(25); float Ka = 0.7, Kd=0.7, Ks = 0.2, roughness = 0.1; float bandbottom = 0.05, bandtop = 0.1, divideS = 0.75, top_transparent = 1, bottom_transparent = 0; color fade_to_color = 0; color specularcolor = 1; float fuzz = 0.007, epsilon = 0.07; ) { color layer_opac = 0, surface_color, surface_opac; float tt, ss, D, top_rise, bottom_rise, run, featherFactor; point Nf, V; Nf = faceforward( normalize(N), I ); V = -normalize(I); surface_color = Cs; surface_opac = Os; if (s < 1-divideS) ss = 1 + s; else ss = s; run = abs(divideS - ss); top_rise = run * cos(topangle) + bandtop; bottom_rise = run * cos(bottomangle) + bandbottom; featherFactor = 0.15 * noise(s*50) - 0.075; tt = t + featherFactor; /* feather top of band */ if (tt > top_rise) { D = smoothstep(epsilon-fuzz, epsilon, tt - top_rise); if (top_transparent > 0) surface_opac = blend(surface_opac, layer_opac, D); else surface_color = blend(surface_color, fade_to_color, D); } /* feather bottom of band */ else if (tt < bottom_rise) { D = smoothstep(epsilon-fuzz, epsilon, bottom_rise - tt); if (bottom_transparent > 0) surface_opac = blend(surface_opac, layer_opac, D); else surface_color = blend(surface_color, fade_to_color, D); } /* now calculate the final color and opacity */ Oi = surface_opac; Ci = Oi * ( surface_color * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks * specular(Nf,V,roughness) ); }