/* * duck_bill_shape(): displacement shader for duck bill shape * * M. Geroch * TV Digital Lighting HW 5 * Spring, 1996 * */ #include "/usr/local/accad/shaders/rmannotes.sl" displacement duck_bill_shape( float Km = 0.02; float ridge_height=0.3; float scrunch = 10; ) { float D, finder; float fuzz_slope=0.005; float s_fac, t_fac, ridge_fac; float fuzz=0.005; float magnitude = 0; /* center_slope from sides to top of bill */ if (s < 0.25) s_fac = 0.5*pow((4*s), 2); else if (s < 0.5) s_fac = 0.5*pow((4*(0.5-s)), 2); else s_fac = 0; /* taper slope near tip */ s_fac *= 1-2*abs(t-0.5); /* steep slope to join at head */ if (t < 0.5) t_fac = 16*pow(t, 4); else t_fac = 16*pow((1-t), 4); /* taper slope near sides */ if (s < 0.5) t_fac *= 1 - 4*abs(s-0.25); else t_fac = 0; /* very small center ridge at bill, tapered at tip */ ridge_fac = 0.1*pulse(0.24, 0.26, fuzz_slope, s) * (1-2*abs(t-0.5)); D = (ridge_fac + s_fac + t_fac)/2.0; magnitude += D * ridge_height; /* poke in for air holes */ D = 1 - smoothstep(0.02-fuzz, 0.02, sqrt(pow((s-0.17), 2) + pow((t-0.61),2))); magnitude -= D * ridge_height * 0.2; D = 1 - smoothstep(0.02-fuzz, 0.02, sqrt(pow((s-0.33), 2) + pow((t-0.61),2))); magnitude -= D * ridge_height * 0.2; /* make it slightly irregular all over */ magnitude += Km * noise(s*scrunch, t*scrunch); /* now displace the point */ P += magnitude * normalize(N); N = calculatenormal(P); }