RslPlugin (Reyes)
|
IntroductionWriting interior volume shaders allows the visualization of many interesting effects. A starting point for the development of a volume shader that ray-marches through a volume such as a sphere is shown in listing 1. A simple scene that can be used to test the shader is given in listing 2. |
Listing 1 "raymarcher.sl" - version 1
Listing 2 (raymarcher.rib)
|
The sampling of 3D noise can also be done in a way that finds an iso-surface defined by points that have values equal, or very nearly equal, to zero. Such points can be baked into a pointcloud, subsequently converted to a brickmap and then rendered as geometry. Baking the points defined by an implicit function is not difficult. However, for a brickmap to create the illusion of a continuous surface, figure 1, requires the baking of both points and accurate normals.
As a volume shader (ray) marches from the front to the rear surface of an
enclosed shape it can detect, relatively easily, when the current
point (refer to the variable |
|
|
A voxel that spans the iso-surface has a mixture of positive and negative "field" values at its vertices (shown as red and blue dots). Polygonization finds the iso-surface (shown as a purple polygon). The normal to the iso-surface is calculated by taking the cross- product of the vectors formed by two edges of the polygon. |
The next part of the tutorial explains how a custom RSL function is implemented
as a RslPlugin. I have prepared a C++ class,
called |
Listing 3 (raymarcher.sl)
The shader, using the custom |
Implementing the RslPluginThe RslPlugin, called "implicit", consists of the following source code files. 1 implicit.cpp 2 Voxel.h, Voxel.cpp 3 DemoVoxel.h, DemoVoxel.cpp
The first file implements the actual RslPlugin. The second group of files
define the Voxel class that implements the Bloomenthal's polygonization algorithm.
The third pair of files define a class called DemoVoxel that is derived from the
Voxel class. The DemoVoxel overrides a method called double NoiseVoxel::getImplicitValueAt(Vertex *vert) { return sin(vert->x * freq) + cos(vert->y * freq) + sin(vert->z * freq); }
The reader should note the implementation of
The |
Building the RslPluginThe following notes assume the reader is using Pixar's RenderManProServer on either Linux or MacOSX. For more information about steps 1 to 3 refer to the tutorial "RslPlugin: aveOpacity" Step 1Create a folder (project directory) in which you can save the files associated with building and testing the plugin - the location is not important. Step 2In preferences set the locations of your "rsl source" and "shader" files. Step 3In Cutter's->Edit->Preferences set the root directory of Pixar's devkit. This will generally be the same folder as the RenderManProServer installation directory. Step 4Copy and paste the text for listings 3 to 9 into files saved in your project directory. The directory should contain these files. implicit.cpp DemoVoxel.cpp DemoVoxel.h raymarcher.rib raymarcher.sl Voxel.cpp Voxel.h Step 5
With the Step 6Open the raymarcher.sl document in Cutter and compile the shader - Alt + e, Control + e. Step 7Open the raymarcher.rib file in Cutter and render both frames - Alt + e, Control + e. You should see a beauty pass render similar to figure 3. SuggestionsUnless (core) functionality is being added to the Voxel class it is best not to edit the Voxel.cpp file - simply leave it alone! However, there are a couple of improvements that could be made to Voxel. For example, the point that is baked by raymarcher.sl represents the center of the voxel. It would be better if the RslPlugin (implicit) returned the center of the iso-surface. Baking that point would probably give more accurate results. Also, the shader bakes a value for the "radius" parameter of the bake3d() function that is somewhat arbitary in size. It might be better if the Voxel class also calculated the "size" of the iso-surface (polygon) and returned that value. The shader would then have a better opportunity of setting an appropriate "radius" value. |
Listing 4 (implicit.cpp)
|
Listing 5 (Voxel.h)
|
Listing 6 (Voxel.cpp)
|
Listing 7 (DemoVoxel.h)
|
Listing 8 (DemoVoxel.cpp)
|
Listing 9 (raymarcher.rib)
|
© 2002- Malcolm Kesson. All rights reserved.