#include "rmannotes.sl" displacement datol( float Km = .3, roughness = .2, txtscale = 1;) { point PP; /* scaled point in shader space */ float csp; /* color spline parameter */ float pixelsize, twice, scale, weight, turbulence; PP = transform("shader", P) * txtscale; pixelsize = sqrt(area(PP)); twice = 2 * pixelsize; turbulence = 0; csp = 0.0; for (scale = 1; scale > twice; scale /= 2) turbulence += scale * noise(PP/scale); /* Gradual fade out of highest-frequency component near limit */ if (scale > pixelsize) { weight = (scale / pixelsize) - 1; weight = clamp(weight, 0, 1); turbulence += weight * scale * noise(PP/scale); } csp = clamp(3 * turbulence - 3, 0, 1); P -= Km * csp * normalize(N); N = calculatenormal(P); }