/*************************************************************************** Gardner's cloud shader *****************************************************************************/ surface gcloud (float octaves = 8.0, lacunarity = 2.2, txts = 1.0; float fading = 4.0, Kd = 1.0, Ka = 1.0) { float i, value, frequency, pixel_size; point p0 = txts * transform("shader", P); vector Nf; /*pixel size is the limit for iteration */ pixel_size = sqrt(area(p0)); value = 0.0; frequency = 1.0; /*fBm*/ for ( i=0; ipixel_size; i+=1 ) { value += (2.0 * noise(p0*frequency) - 1.0) / frequency; frequency *= lacunarity; } value=clamp(abs(value),0,1); Nf = faceforward( normalize(N), I ); /*opacity*/ Oi = value * pow(abs(Nf . normalize(I)),fading); Ci = Oi * Os * ( Ka*ambient() + Kd*diffuse(Nf) ); }