Los Angeles mental ray® User Group
 Home   About   Info   Summaries   Gallery   Forum   Resources   Contact   Jobs 


Resources Sections

General

Install/Setup

Options Settings

Performance Optimizations

mi Scene File

FG/AO/GI

Subsurface Scattering

Shiny Stuff

mrfm (Maya)

Shader Writing

Hair and Geometry Shaders

Rasterizer Tips

The 'rasterizer' is the name of the scanline algorithm implemented with mental ray 3.4. It is a replacement for the 'Rapid Motion' scanline algorithm from previous mental ray releases. Whether you specify -scanline rapid or -scanline rasterizer at the command line, it will use this new algorithm. The latter is now the preferred name. However, in the options block of the scene file, you must still use scanline rapid.

The rasterizer separates shading from sampling. Normally, without the rasterizer, shading is initiated by shooting an eye ray from the camera at a sample location. This primary ray hits an object and typically starts the shading calculation by calling the material shader of this object. When using the rasterizer, shading calculations occur separately, and associate with the tesselated geometry. The rasterizer samples pick up the shading results from the geometry. To understand how this works, first we'll present sampling and filtering in the rasterizer, and then we'll address shading.

Samples and pixels

From Samples Tips, we see that adaptive sampling uses samples at the corners of pixels and subpixels. However, when using the rasterizer, the samples are shifted back to the centers of pixels and subpixels. In addition, the rasterizer always uses a fixed grid pattern of samples; it will not create adaptive sampling patterns. Instead of using the samples option to control the number of samples, the rasterizer uses the samples collect option. Unlike the samples numbers, samples collect specifies the number of samples along a pixel edge.

The equation for determining how many samples are taken per pixel is n x n, where n is the number specified by samples collect in the options block, or -samples_collect at the command line.

In mental ray 3.4, the default samples collect value of 4 specifies 4 x 4, or 16, samples per pixel. In mental ray 3.3, if you don't specify samples collect, the default derives from samples, more specifically, 2maxsamples, while ignoring min samples; so a samples max of 2 (eg, samples 0 2) would equal samples collect 4, and samples 0 3 would equal samples collect 8

Diagnostics

Samples diagnostics is disabled when using the rasterizer, because it is a visualization tool to see the adaptive samples pattern. The rasterizer uses a fixed sampling pattern.

Temporal Sampling/Motion Blur

In the rasterizer, each spatial sample has its own unique time within the open shutter interval. This method is similar to fast motion blur, except that the samples are located at (sub)pixel centers rather than (sub)pixel corners. And as in fast motion blur, motion smoothness is related to the number of spatial samples per pixel.

Filtering to pixels

After each tile has been sampled, we enter the filtering stage. Note that the default filter box 1 1 won't do much if we use samples collect 1. It will just pass the sample through. Using a filter size of 3, we'll highlight the filtered samples, as we show the samples used for different pixels and then, increase the samples collect values.

The following diagrams depict the tile overlap samples for a 4x4 tile size. Note that there would be no overlap samples with filter size of 1 1, because there are no samples on the edges of the pixels.

Writing multipass sample buffers

Pass files reflect the shifted sampling patterns. For example, here is the render output listing for our 8 x 8 grape image with a task size of 4, and samples collect 1:
...
RC 0.2 info : pass file grape.pass: wrote 64 samples (0% empty, 87% black) in 4 rects
...

Each quadrant has 4 x 4 pixels, and thus 4 x 4 samples. That makes 16 samples times 4 tiles, and thus, 64 total samples. It will always say 0% empty because there are no gaps in a fixed sample pattern.

Accessing with multipass preprocess

With the rasterizer, all accessed samples will be pre-existing. There are no gaps.

Be careful not to mix rasterizer passes with non-rasterizer passes, because the sampling patterns will not match. Recall that the rasterizer has (sub)pixel center based samples, as opposed to (sub)pixel corner based samples.

Jittering

Likewise, jittering is applied with respect to the centers of pixels and subpixels instead of the corners. Each jittered sample lies somewhere in its respective jitter region, as determined by the QMC algorithm.

Shading

In the rasterizer, the shading step occurs before, rather than during, the spatial sample calculation. mental ray takes a shading sample for each tesselated primitive of a tesselated object. (For all objects, currently, a triangle serves as the primitive.) As the triangle moves, mental ray uses the same shading sample throughout the frame time. It is this re-use of shading results which speeds up the rendering process for an image requiring a similar number of spatial samples.

On the left, the dot in the center of the triangle represents the shading sample taken at frame time 0. As the triangle moves, the same shading sample stays with the triangle. On the right, we see the triangle at the end of the motion path, frame time 1.

Separate from shading, mental ray takes spatial samples with a density specified by samples collect. These spatial samples use the shading samples from whichever triangles they hit.

Any spatial sample hitting that triangle will use the same single shading sample calculated at time 0. However, note that as the triangle moves, it covers a different set of spatial samples.

Actually, because each spatial sample has its own unique time, the triangle position will be different for each sample. The sample time determines the distance the triangle has moved along its motion path. So a sample covered by the triangle at the beginning of the frame time may not hit the triangle at the end of the frame time. For example, the highlighted sample below left hits the triangle at time 0.2, whereas the sample below right misses the triangle at time 0.65.

Also consider that multiple layers of geometry may be moving. Assuming some transparency, mental ray uses all the triangles underneath the spatial sample until it hits an opaque object.

This means that the time associated with the spatial sample determines which triangles it uses to composite the final sample. We call this step "collapsing the sample". With multipass, this is what is written out to the sample-based pass file, i.e., before filtering.

Technical note: Sample Collapse Evaluation Volume and environment shaders are called at the time of collapsing a sample. In addition, a separate opacity function, mi_opacity_set, is available for combining the shading sample results. If not used, it picks up the alpha. All layers assume premultiplication.

Technical note: User Framebuffers Because multiple shading samples may combine into a spatial sample, the mi_fb_put function will also keep user framebuffer values separate before "collapse" time. And since the data type of the user framebuffer is quite flexible, no combination method can anticipate its intended use. So at "collapse" time, mental ray uses the framebuffer value stored for the topmost layer, i.e., the first triangle intersected by the eye ray.

Furthermore, because shading occurs separately, and the order depends on a sample's time and place, you can't reliably pass information between shaders on different transparent layers using, mi_fb_get. Yet, for any non-transparent ray traced out from a given shading sample, it will work. For example, this includes reflected and refracted rays.

Shading Samples

The shading samples option controls the size of the tesselated primitive, currently a triangle, with respect to view dependent tesselation. Its value roughly indicates the number of triangles per pixel. Since each triangle has one shading sample, it follows that this represents the number of shading samples per pixel for each layer of intersection. If all the objects were opaque, the total shading samples for a scene would equal approximately this number times the number of pixels. The shading samples default of 1 would roughly fit one triangle per pixel. Quality increases as the value increases above 1.

Samples Motion

mental ray also provides for taking more than 1 shading sample over the frame time per triangle. The samples motion option specifies how many times a shading sample is taken during the open shutter interval. This means that each moving triangle stores this many shading samples.

The sample is taken at times 0, 1/n, .., n-1/n, where n is what is specified by samples motion. In the example below, n = 5, and we show the location of the triangle and its shading sample at these five times

A shading sample is used for the triangle as it moves from its start time to the next shading sample time. In other words, the shading sample at time 0 is used for all spatial sample times from 0 to 1/n. Again using n = 5 below, we show a shading sample taken at 0.2 used for a spatial sample taken at 0.3. Note that we show a spatial sample hitting just inside the bottom of the triangle at 0.3

Mulitple shading samples can be used to cut down on the artifact of dragging a fixed reflection across motion. It acts as oversampling for anything that changes over time during shading.

Keep in mind that this is not the same thing as multisegment motion paths, which enable non-straight motion paths within the frame time. A curving motion path could very well use a single shading sample effectively for a given shot. However, by using multisegment motion paths together with multiple shading samples, fairly sophisticated motion blur effects are possible.

Usage and Performance

Ideally, the rasterizer handles scenes which do not require raytraced effects. However, from the information above, you should understand that each shading sample does have the ability to trace reflected and refracted rays. However, once a ray is shot, much of the time and memory savings from using the rasterizer could be eaten up with bsp tree construction, and object loading.

For this reason, we recommended detail shadow maps instead of raytraced shadows for transparent shadow effects. As a common example, most hair rendering can be satisfied with the rasterizer and detail shadow maps.

In the following table, we present some general guidelines on rasterizer usage, by presenting features that trigger rays to be traced.:

For optimum performance using the rasterizer alone, avoid:
FeatureRay TypeDescription
reflection
refraction
eye raysmaterial (surface) shaders may reflect or refract. Turn trace off or reduce trace depth to 0 0 0, but note that custom shaders may override these. Also note that environment maps will still work for reflections when raytracing is disabled.
raytraced shadowsshadow raysUse detail shadow maps to produce transparent shadows without raytracing. Or, with the bsp shadow option on, use simplified objects to produce the shadows.
final gatheringFG raysFor each FG point, multiple FG rays are cast back into the scene.
photon tracing
(GI and caustics)
photon rays
(photons)
Photons trace forward from the light source, and thus require the same structures as raytracing.
autovolumeeye raysWith autovolume on, mental ray shoots a single real (eye) ray through the middle of the image, which typically causes the construction of the bsp and the tesselation of some non-trivial object
ray-bending lens shaderseye raysBoth the regular scanline algorithm and the rasterizer depend on a straight primary eye ray. Using these will most likely cause artifacts.

Because the rasterizer takes shading samples on geometry in an undefined order, then combines them for the sample result later, shaders may behave differently. For each triangle in the scene, mental ray resets the shading sample context and then, calculates the shading sample. Some shaders which depend on this context may need to be modified. See the following table.

For shading calculations using the rasterizer, note:
Featureray typeDescription
shading sample contexteye rayThe ray hitting each triangle along the straight path of the eye ray is treated like a primary eye ray. This means that, regardless of transparency depth, the state is set up like a primary eye ray. Of note for the material shader, this means:
  • state->org is set to the eyepoint*.
  • state->user is reset
  • any state shader using miSHADERSTATE_SAMPLE_INIT/EXIT will surround the shader calculation.
*Note that if you do use raytracing, any secondary rays spawned by the surface's material shader, that are not transparency rays, will treat state->org normally.
transparencytransparency rayThe call to mi_trace_transparency will return immediately, and the transparency will be calculated later by examining the opacity color. If opacity is not set using mi_opacity_set, the alpha channel will be used. Mostly, this will give the same results, but not always. For example, a matte calculation could differ.
non-linear volume effects* rayWe must be able to add the volume shading at sample collapse time, after the surface shading. A volume effect should not depend on the order of the shading sample calculation between transparent layers. When the volume shader runs, the shading samples have already been calculated.

Summary

In mental ray 3.4, the rasterizer is the scanline method replacing Rapid Motion. These are the scene options to control it:

  • scanline rapid - enables it.
  • samples collect n - n specifies n x n samples per pixel.
  • samples motion n - n specifies n shading samples per open shutter interval.
  • shading samples x - x specifies approximate triangles per pixel.

At the command line, you may use:

  • -scanline rasterizer, or -scanline r
  • -samples_collect n
  • -samples_motion n
  • -shading_samples x

Discuss on LAmrUG forum


 © 2003-2006 Los Angeles mental ray® User Group, All Rights Reserved.
mental images and mental ray are registered trademarks of mental images GmbH, in the United States
and other countries. Other product names may be trademarks of their respective owners.


About Us| Contact Us