Writing point clouds
Note: in V 2, a new parameter was added, called Skip Checking for sj_pc_tag . See the bottom of the page for details.
The cloud is written by a camera shader called sj_write. For
each pixel, a ray is sent toward the scene, and for each intersection found, a
point is added to the cloud. You can choose to have more than one ray per pixel
(oversample) and the maximum depth the ray will travel.
Tracing the cloud
from the camera is, in a way, coherent with the original renderman
design (at least one point per pixel), but suffers of some problem:
1. The points are not equally distributed over the surface of the
objects.
2. The density of points is proportional to the incidence of a
surface location as seen from the camera.
3. Objects out of the viewing frustum are not used.
4. If the cloud is not dense
enough, it will jitter at render time.
But also has a series of advantages:
1. It's very
easy to set up. Just one camera shader. You don't need to adjust any
geometry approximation, nor to apply any texture.
2. The resolution of
the cloud is easily controllable, as it depends only on the rendering
resolution, the oversample and the tracing depth.
3. Everything in the scene
can be point clouded, including hair, instanced geometry and
render-time generated geometry (geo shaders).
The
first thing to do is "marking" the objects in the scene that will
contribute to the cloud. To do it, you must apply sj_pc_tag as
surface shader.
The previous surface shader must be connected to
Passthrough. The shader whose color you want to assign to the
points generated out of the object must be connected to Color. You can connect whatever shader to
Color
, not necessarily the beauty one.
Classically, you want to connect a lambertian shader, not depending on the
viewing direction, for instance an ambient occlusion.
In this example, we
connect lambert materials for all the objects.
The other parameter is called
Tag, and is an integer that will also be written together with
the points. It can be used at read time, to filter the read points.
In this
example, body was tagged as 0, the horns as 1, the eyes as 2 and the grid as
3.
We can now apply the camera shader. The
parameters are:
Mute: if on, the shader does nothing.
Jitter, Oversample: if
Jitter is off, a ray is sent for each pixel, centered at the
pixel center. If on, the rays goes through a random location over the pixel
area. If Jitter is off, Oversample rays are traced for each
pixel, at different locations. So, you can increase the cloud resolution without
changing the rendering resolution.
Max
Depth: the maximum number of intersections a
ray travels along its direction. For instance, if 1, only the surface areas
directly visible from the camera contribute to the cloud generation.
Use, Tag: if
Use is on, the Tag string is used to filter
the objects that generate points. If off, all the objects having sj_tag as
surface shader are used. The way it works is the same you use when printing a
document from most of the text editors, ie numbers separated by commas or
dashes. For instance, if Tag is
1-3,5,10-12
it means that only
the objects (sj_)tagged as 1,2,3,5,10,11,12 will contribute to the clouds, the
others being skipped.
Action, Pdc File, Map File: action can
be one of the following:
Write mrmap: the cloud is written
to Map File (.mrmap extension), the new mental ray 3d map
format.
Write pdc: the cloud is written to Pdc
File (.pdc extension), a maya particle format.
Write
both: both are written.
Convert: convert an
existing Pdc File to Map File (this way the
shader is just acting as a converter, doing nothing
else).
Frame: The files names must have the right extension
and a frame number (for instance, c:\temp\test.1.pdc). For each rendering frame,
Frame replaces the frame number in the string. In
Softimage, Frame is initialized with the Fc expression, but you
can overwrite it. In Maya, you have to animate it yourself.
Radius: the radius of the
points, used for previewing pdc files (not used at render
time).

Notes:
When in
Convert mode, you can convert any existing pdc file to mrmap.
The input pdc must have at least the rgbPP and the
normalPP attributes.
The final resolution of the point cloud
is, at max, rendering_x_res*rendering*y_res*Oversample*Max
Depth
We are
now ready to generate the cloud. Just render the current frame.
If the
verbose is enabled, you should see some progress info as shown
here.

Since we wrote the pdc also,
we can now preview it. In Softimage, you can use SjPdcImport, giving the
exported pdc as file name and 1 as Step


In V 2, I added a
new parameter to the shader, called Skip Checking for
sj_pc_tag, so the ppg now looks as shown below.
If off, it
all works as in V 1.
If on, also the objects without
sj_pc_tag are traced, and the color for the points is simply
the surface shader of the objects.
This option was introduced to fix
some particular cases where sj_pc_tag was not correctly recognized as the
surface shader, particularly in the case of ice strands. For such objects, a
fixed tag (0) is assigned when writing the files.
Since using this flag can
slow down the point generation, you should avoid it wherever
possible.
