Multipass rendering is a new feature in mental ray 3.1.2 that allows rendering multiple scenes with the same frame number, resolution, oversampling parameters, and list of type of frame buffers, but different contents. This is useful if a scene is extremely complex, or consists of many distinct elements, so that rendering it all at once is impractical either because of the size, or because certain elements are expected to change and it would be too expensive to re-render the entire scene for each small change. Multipass rendering allows splitting such a scene into sub-scenes (called passes or layers), rendering each sub-scene, and putting the results together in a separate step called merging.
Scenes are typically broken into sub-scenes by clustering geometry, for example one for each complex character or creature, or props such as vehicles, or backgrounds. Elements not present in a sub-scene are either omitted completely or replaced by very simple stand-ins that do not appear in the rendered pass image, for example simple invisible and nontraceable objects that cast shadows. This allows objects of one pass to cast shadows on objects in another pass. (In this particular case it is useful to enable the shadow BSP tree with the option statement bsp shadow on to manage the shadow stand-ins more efficiently.)
Each pass render leaves a pass file in a directory specified by the user, using a pass statement list in the camera definition. Pass statements come in five forms:
All pass prep statements are executed in order before rendering. During rendering, all pass and pass merge statements are executed in order, once for each finished rectangle. After rendering, all delete statements are executed. For more information on the syntax, see page mpassopt.
Merging is the operation of combining all samples for a pixel, sample by sample, to arrive at the final sample to be filtered into the pixel. Merging may simply choose the sample with the lowest depth, or also perform alpha blending or other operations based on the available frame buffers. Merging can either happen at the end of the last pass, or as a separate operation. mental ray will merge without rendering if there is no pass statement (of the first type above). If merging without rendering, it is still necessary to provide some information about the scene that agrees with the settings in the pass sub-scenes:
Note that when using the rasterizer, the shading samples setting is used in place of the samples setting.
The pass statement specifies the current pass number, the number of passes, and an optional directory to store the pass files (which can become large if there are many samples and many defined frame buffers, much larger than image files). Here is an example scene for merging only:
link "passmerge.so" declare shader "mymerge" () version 1 end declare options "opt" samples -2 1 end options camera "cam" frame 1 pass merge read [ "pass.0", "pass.1", "pass.2" ] "mymerge" () output "rgb" "out.rgb" resolution 150 128 end camera instance "cam_inst" "cam" end instance instgroup "rootgrp" "cam_inst" end instgroup render "rootgrp" "cam_inst" "opt"
Note that the camera specifies no pass write statement, so no rendering takes place and no geometry needs to be specified here. (If it were, it would be ignored.) The renderpass merge shader "mymerge" is responsible for putting the render passes together, sample by sample. Its implementation is described on page passmerge. The example there merges the scenes by Z depth, and since the merging is based on individual samples, any intersections will be properly anti-aliased (which they would not if the merging were based on images). If no merge shader is specified, mental ray will default to a simple depth sorting function with alpha blending.
Note, however, that each pass is a separate scene with no knowledge about other scenes. This means that at points where objects in one pass intersect with objects in another pass in the final image, mental ray sees no reason to oversample the intersection because it does not exist at that time. Although mental ray will reconstruct low-sampling areas before merging, it may occasionally be necessary to use sampling parameters where the minimum number of samples is close to, or in extreme cases (where the objects are simple and nearly flat-shaded but highly detailed inter-pass intersections take place) even equal to the maximum number of samples. It is also recommended to turn jittering off because different passes may jitter sample position in different ways.
For the merge example above to work, it is necessary to first render the three pass files. This is done by adding pass statements to the camera:
camera "cam" ... pass write "pass.0" ... end camera
And similar for passes 1 and 2. These files are otherwise normal scene files. As mentioned before, the resolution and sampling parameters, and list of frame buffers (as defined by output and frame buffer statements) must agree. Pass files from hosts with different byte orders cannot be merged. No pass merge statements are required, unless merging should be done after rendering too. Note that if merging and rendering is done in one step, the pass being rendered is referenced in the pass merge statement with an empty string ( ""). This can be done in any pass - if rendering pass 2 of 3, for example, the pass merge statement would be
pass merge read [ "pass.0", "", "pass.2" ] output "rgb" "rgb.out"
Note that pass files are not intended for long-term archival. Although different versions of mental ray will generally accept the same pass merge files, major revisions may alter the file format. An informational warning will be printed if the version numbers do not agree, but this warning can be ignored. mental ray will detect incompatibilities and reject pass files that have the wrong version, resolution etc., or the wrong byte order.
If renderpass mode is enabled, mental ray will automatically enable the depth (Z) frame buffer. This may change in future versions.
Copyright © 1986-2008 by mental images GmbH