VolumetricHandlerAvailability LightWave 6.0 Volumetric handlers model the attenuation and scattering of light in gases, differences in density in 3D medical imaging data, or the shapes of surfaces too complex to model explicitly with geometry. They do this by participating in LightWave's raytracing mechanism. For each ray fired into the scene, the volumetric handler calculates a color and opacity for one or more samples. It hands each sample back to LightWave, which integrates all of the samples from all of the volumetrics to produce the final color seen from the source of the ray. A sample represents a segment of the ray over which the color and opacity are constant. Consider a simple cloud pierced by a ray. The handler that draws the cloud isn't interested in the parts of the ray that are outside it, so it creates no samples there. In the simplest case, it may create a single sample that begins at the point where the ray enters the cloud and extends as far as the ray remains inside. If the cloud is somewhat transparent, the color might be a linear combination of the cloud color and the backdrop color, and the opacity will be somewhat less than 1.0. Handler Activation Function XCALL_( int ) MyVolumetric( long version, GlobalFunc *global,
LWVolumetricHandler *local, void *serverData );
The local argument to a volumetric handler's activation function is an LWVolumetricHandler. typedef struct st_LWVolumetricHandler {
LWInstanceFuncs *inst;
LWItemFuncs *item;
LWRenderFuncs *rend;
double (*evaluate) (LWInstance, LWVolumeAccess *);
unsigned int (*flags) (LWInstance);
} LWVolumetricHandler;
The first three members of this structure point to the standard handler functions. In addition to these, a volumetric handler provides an evaluation function and a flags function.
Interface Activation Function XCALL_( int ) MyInterface( long version, GlobalFunc *global,
LWInterface *local, void *serverData );
This is the standard interface activation for handlers. Volumetric Access This is the structure passed to the handler's evaluation function. typedef struct st_LWVolumeAccess {
void *ray;
int flags;
LWItemID source;
double o[3], dir[3];
double rayColor[3];
double farClip, nearClip;
double oDist, frustum;
void (*addSample) (void *ray, LWVolumeSample *smp);
double (*getOpacity)(void *ray, double dist,
double opa[3]);
LWIlluminateFunc *illuminate;
LWRayTraceFunc *rayTrace;
LWRayCastFunc *rayCast;
LWRayShadeFunc *rayShade;
} LWVolumeAccess;
Volume Sample A volume sample is a single ray segment with a uniform color and opacity. The distance and stride define the position and size of the sample, and the opacity and color are given as color vectors. By the way, you can create surface samples by setting stride to 0 and dist to 0.9999 * farClip. typedef struct st_LWVolumeSample {
double dist;
double stride;
double opacity[3];
double color[3];
} LWVolumeSample;
Example The atmosphere sample is a straightforward implementation of some of the volumetric techniques discussed in chapter 14 (K. Musgrave, L. Gritz, S. Worley) of Texturing and Modeling, 2nd ed., Academic Press, 1998. It includes both a fast analytical solution that creates a single sample and a more refined solution that uses raymarching and multiple samples per ray. |