volume blendfog ( float maxdistance = 1.0; color background = 0.5) { float d; float x, y, z, dist; /*x = xcomp(P); y = ycomp(P); z = zcomp(P); dist = sqrt(x*x + y*y + z*z);*/ dist = length(I); /* EXPONENTIAL FOG */ d = 1 - exp( -dist/maxdistance ); /* LINEAR FOG */ /* d = clamp( 0.0, 1.0, dist/maxdistance);*/ Ci = mix( Ci, background * Oi, d ); /* Oi = mix( Oi, color (1,1,1), d );*/ }