/*perturb.sl by wooksang*/ #include "rmannotes.sl" surface perturb( float Ks=.5, Kd=.5, Ka=1, roughness=.1; color specularcolor=1; string image="grid.tx";) { normal Nf; vector V; float ss,tt; point PP; color surface_color; PP = transform("shader",P); ss = s+snoise(PP*8)*0.2; tt = t+snoise(PP*10)*0.2; surface_color = texture(image,ss,tt); Nf = faceforward( normalize(N), I ); V = normalize(I); Oi = Os; Ci = Os * ( surface_color * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks * specular(Nf,-V,roughness) ); }