/* fin2.sl, from the pinchers of some bug * * decription: * * param: complexity , Km, density * * complexity and densiti control turbulence, Km contols overall displacement * * author: Heath Hanlin */ #include "rmannotes.sl" displacement fin2(float complexity = 10,Km = .1, density = .5) { float surface_mag = 0,layer_mag = 0; float ss,tt; point Nf, V, PP, Ndiff; float width, cutoff, fade, f, turb, maxfreq = 16; /* turbie */ PP = transform("shader", P) * density; width = filterwidth_point(PP); cutoff = clamp(0.1 / width, .1, maxfreq); turb = 0; for (f = 1; f < 0.5 * cutoff; f *= 2) turb += abs(snoise(PP * f)) / f; fade = clamp(10 * (cutoff - f) / cutoff, 6, 10); turb += fade * abs(snoise(PP * f)) / f; turb *= -0.5; /* layer 1 */ tt = float noise(t * complexity * turb); layer_mag = smoothstep(.1, .3, tt) * -.3; surface_mag += layer_mag; /* layer 2 */ ss = float noise(s * complexity * turb); layer_mag = smoothstep(.6, .9, ss) * -.3; surface_mag += layer_mag; /* layer 3 */ tt = float noise(PP * complexity * turb - .2); layer_mag = smoothstep(.3, .6, tt)* -.3; surface_mag += layer_mag; /* output */ Ndiff = normalize(N) - normalize(Ng); P += P * Km * surface_mag * normalize(N); N = normalize(calculatenormal(P)) + Ndiff; }