the imagesa and code
color Scatter(color Cbase;
point P; /* The point being shaded */
point Porig; /* P before displacement */
normal N;
float Kd;
string mapname;
float scatterWidth;
color scatterTint;
output float __overrideDerivs;/* Message passing to the light shader
*/
output float __derivA

/* Use this area for the filterwidth*/
{
color Idiffuse = Diffuse(P,N);
color Iscatter = 0;
varying point Pworld = transform("world",Porig);
varying normal Nworld = normalize(ntransform("world",N));
/*
* Read in any maps that haven't been read
* Keep pointers to them for future calls
* Free any cached information from the previous grid.
*/
ScatterDSOReadMap(mapname);
/*
* For each grid point, search the octree and create
* a cache of nearby samples. Return the grid point's
* index into this cache. At the same time, build a
* queue of nearby samples that still need to be shaded.
*/
float grid_index = ScatterDSOAddGridPoint(Pworld,
scatterWidth);
/* Irradiate all samples in the queue, filling
* the grid with more samples if necessary.
*
* prman will run the light shader on all grid points
* in this grid, even if called on only one grid point.
* If we were to serialize this portion of code (by
* running only on the first grid point, it would thus
* be extremely inefficient.) To thwart this, we'll always
* fill an entire grid. If there aren't enough samples
* in the queue, we'll use any old samples we can find.
* (cause we'll probably need to shade them eventually)
*/
varying point Psample = point(0,0,0);
varying normal Nsample = normal(0,0,0);
varying float Asample = 0;
varying color Isample = color(0,0,0);
__overrideDerivs=1;
while(ScatterDSOGetSample(Psample,Nsample,Asample) ) {
__derivA = Asample*length(transform(?world?,?current?,
vector(1,1,1));
Isample = Diffuse(Psample,Nsample);
ScatterDSOSaveIrradiance(Isample);
}
__overrideDerivs=0;
/*
* Accumulate illumination from the nearby
* samples, using the cache to avoid searching
* the octree again.
*/
Iscatter = ScatterDSOScatter(grid_index,Pworld,
Nworld,scatterWidth,scatterTint);
return Kd*Csurf*mix(Idiffuse,Iscatter,scatterAmount);
}