/* * First we declare a pattern function. crackle form x suits our needs * pretty well, from the POV docs: * "Another commonly-used form is <1,0,0>, corresponding to the distance * to the closest point, which produces a pattern that looks roughly like * a random collection of intersecting spheres or cells." */ #declare f_crackle_form = function { pattern { crackle form <1,0,0> } } /* * To get that linear 0 -> 1 curve a bit more interesting, declare * a "crater-shaped" spline function through which to put the pattern. * A bit of tweaking will probably make it look better. */ #declare f_crater_spline = function { spline { cubic_spline 0.0, 0.4*x // From the center... 0.01, 0.3*x 0.03, 0*x 0.12, 0.1*x 0.24, 0.2*x 0.3, 1*x 0.4, 0.9*x 0.6, 0.7*x 1.0, 0.5*x // ...outwards. } } /* * Next we create the actual crater field pattern. It is basically * a 1/f fractal pattern, similar in principle to how granite or * f_ridged_mf work internally. It adds together several layers of * the crackle pattern, varying the frequency (scale) and amplitude. */ /* * First, declare some variables to parametrize the pattern creation. */ /* * The octaves, ie. the number of fractal layers to use. */ #declare O = 6; /* * The "lambda" or "lacunarity" value. The multiplier used to * determine the frequency/amplitude "gap" between octaves. */ #declare L = 2; /* * Build the pattern with a #while loop. */ #declare f_craters = function { #declare I = 0; #declare M = 1; /* * The 1-exp(-x) function is just used to keep the value * below 1 (its limit in infinity is 1). I don't think it is * actually needed if the function is not used in a pigment, * but... Again, this needs more experimenting. */ 1-exp(-( #while(I < O) #declare M = L * M; + f_crater_spline( f_crackle_form(x * M, y * M + I, z * M) ).x / M #declare I = I + 1; #end )) } /* * Here's the final function to be used with a height field * or an isosurface. */ #declare Craters = function { pattern { function { f_craters(x,y,z) } /* * Apply some turbulence. Could use some tweaking. */ scale 100 warp { turbulence 0.4 } scale 1/100 } }