#include "rmannotes.sl" /* * perturbed_noise(): */ surface perturbed_noise(float octaves = 6, lacunarity = 2, nscale = 3, pscale = 6, brightness = 0, contrast = 1, distort = 1, ratio = 0.5; float Ks = 0.4, Kd = 0.6, Ka = 0.1, roughness = 0.1; color specular_color = 1.0; string texmap = "" ) { float i, size; vector perturb; color noisecolor; point Psh; normal Nf; vector V; Nf = faceforward( normalize(N), I ); V = -normalize(I); noisecolor = 0.0; perturb = 0.0; size = pscale; Psh = point(s*size, t*size, 0); for (i=0; i < octaves; i+=1) { perturb += (( vector noise(s*size, t*size)-0.5 ) * 2.0) / size; size *= lacunarity; } perturb = ((perturb + (brightness - 0.5)) * contrast) + 0.5; size = nscale; Psh = point(s*size, t*size, 0); Psh += perturb * distort; for (i=0; i < octaves; i+=1) { noisecolor += (( color noise(xcomp(Psh)*size, ycomp(Psh)*size)-0.5 ) * 2.0) / size; size *= lacunarity; } noisecolor = ((noisecolor + (brightness - 0.5)) * contrast) + 0.5; Ci = ratio * noisecolor + (1.0-ratio)*Cs; Ci = Ci * (Ka*ambient() + Kd*diffuse(Nf)) + Ks*specular_color*specular(Nf, V, roughness); }