/* fin3.sl * * displacement for the wood shader * */ #include "rmannotes.sl" displacement fin3(float ringscale = 10, Km = .01) { float surface_mag = 0,layer_mag = 0; point Nf, V, PP, Ndiff; float r, tmps, tmpt, ss, tt; float col, row, noi, freq = 100; float fuzz = .04; point center; float radius; float d; /* layer 1 */ PP = transform("shader", P); PP += noise(PP) * 0.5; r = distance((0,ycomp(PP),zcomp(PP)), (0,0,0)); r = repeat(r + noise(r), ringscale); layer_mag = smoothstep(0,0.8,r) - smoothstep(0.83,1,r); surface_mag += layer_mag; /* layer 2*/ ss = s + snoise(3 + 912) * 5; tt = t + snoise(3 + 333) * 5; col = whichtile(s, freq); row = whichtile(t, freq); noi = noise(col * 30 + 0.5, row * 30 + 0.5); tmps = repeat(s, freq) + udn(noi * 500, -0.35, 0.35); tmpt = repeat(t, freq) + udn(noi * 450, -0.35, 0.35); rotate2d(tmps, tmpt, radians(udn(noi * 777, 0, 360)), 0.3, 0.3, ss, tt); center = (0.5, 0.5, 0); radius = .7; d = distance(center, (ss, tt, 0)); layer_mag = 1 - smoothstep(radius - fuzz, radius, d); surface_mag += layer_mag; /* output */ Ndiff = normalize(N) - normalize(Ng); P += P * Km * surface_mag * normalize(N); N = normalize(calculatenormal(P)) + Ndiff; }