MR Using BSP Diagnostics

From TOI-Pedia


Introduction

This tutorial covers using the Mental Ray BSP diagnostics to optimize the BSP settings used for rendering.


BSP is one of the methods used by Mental Ray to speed up raytracing operations. Mental Ray partitions the scene in order to roughly know where each polygon is located in the scene. BSP stands for Binary Space Partition - more information can be found on the BSP article on Wikipedia.


Optimizing the BSP settings may be necessary to be able to render your scene. At one end, non-optimized settings may cause the scene to render very slowly; at the other end, they may cause Mental Ray to hog up too much memory, possibly resulting in out-of-memory errors.


BSP in a nutshell

Binary Space Partitioning
B, D, E, G and H are leaf nodes in this example

To better understand what BSP does, some background information (optional reading):

A scene consist of many polygons (triangles). Mental Ray needs to do all kinds of calculations on these. To do this as quickly as possible, Mental Ray needs to be able to find out efficiently which polygon is located in any given part of your scene. Therefore your 3D scene is split into cells (voxels, or: '3D pixels') using the BSP algorithm. For every voxel the polygons that are present are listed.

It starts to split your scene into two voxels and determines the number of polygons in each voxel. If the number of polygons is larger than a set number (BSP size), it splits that voxel (because finding a specific polygon in a very large list is still not too quick). This process is repeated until the number of polygons in that voxel is smaller than the set BSP size, or if the maximum number of splits (BSP depth) has been reached. These voxels at the end of the splitting process are called leaves (compare: leaves on a tree, at the end of a branch). This entire operation constructs a tree in which Mental Ray can quickly lookup which polygon is in a specific part (leaf voxel) of your scene. Mental Ray now only needs to consider the few polygons that are in a specific voxel when doing calculations.


Enabling BSP Diagnostics render mode

You can use the BSP diagnostics render-mode to gain an insight in the BSP settings. Open the Render Settings and go to the Mental Ray tab:


MR RenderSettings BSP diagnostics.jpg


Scroll down to the Diagnostics section.

There are two main options for BSP diagnostics:

BSP Depth
graphically shows the depth reached for the BSP-tree for each part of the image.
BSP Size
graphically shows the size of each 'BSP-leaf'

Generally for architectural scene, you only need to worry about the BSP Depth. BSP Size is generally only needed when using Motion Blur or when you have geometry which has stretched polygons the reach across most of the image width or height.

Select the method you want to use for Diagnostics BSP, so in most cases: Depth.


Image Size

You don't need high resolution images when rendering BSP diagnostics. Therefore it's recommended to set your Image Size in the Common tab to something like 600-800 pixels for the largest direction (width or height), keeping your original image aspect ratio.


Rendering BSP Diagnostics

You can just click Render Current Frame to make a diagnostics render (provided you've selected one of the two BSP diagnostics modes). As this only considers geometry and ignores shaders and lighting, it should be pretty fast.

To get more accurate data regarding the BSP, it's recommended to enable Info Messages:

Select the Render menu set. Render -> Render Current Frame option box. Set the Verbosity Level to Info Messages. Mental Ray will now output detailed messages regarding the rendering in the Output Window.

MR Info Messages.jpg

Depth diagnostics

The image will consist of colored pixels, showing the depth reached:

blue - green
Ok. Maximum depth not reached. (Although memory usage may be higher than strictly necessary)
yellow - orange
Good/Ok. Near to maximum depth, but size constrains where (largely) met. The voxel is around the max size.
orange - red
Warning. Maximum depth is reached before the size constrain was met. The voxel is larger than the maximum that was set.


Note that red areas are not bad per se. Only if there are large continuous red areas, your depth is probably too small.


Now it's time to take a look at the diagnostics image and the details in the Output window.

BSP Depth: 30, Size: 10

This image shows large red areas, definitely not good. This will be confirmed by the output in the Output window:

RCI 0.3 info : main bsp tree statistics: RCI 0.3 info : max depth : 30 RCI 0.3 info : max leaf size : 14226 RCI 0.3 info : average depth : 29 RCI 0.3 info : average leaf size : 39 RCI 0.3 info : leafnodes : 81684 RCI 0.3 info : bsp size (Kb) : 8694

The max leaf size shows that there are some very large leafs. The average leaf size is 39, while we set the leaf size to 10 (default). This means that on average, this constraint could not be met: it's exceeded by a factor 4! The maximum depth that we set (30) is reached, as is shown by the max depth line.

If we allow a larger depth, the BSP should manage to create smaller leafs, as a larger depth allows more subdivisions.


BSP Depth: 40, Size: 10

This is much better, but still there are some red areas. If memory restrictions are high, this BSP result is acceptable.

The Output window shows:

RCI 0.3 info : main bsp tree statistics: RCI 0.3 info : max depth : 40 RCI 0.3 info : max leaf size : 406 RCI 0.3 info : average depth : 36 RCI 0.3 info : average leaf size : 8 RCI 0.3 info : leafnodes : 1303132 RCI 0.3 info : bsp size (Kb) : 61495

The max leaf size is much better and the average is now also below the value we've set (10). The memory needed for this particular BSP is now 60MByte; quite an increase from the previous, but it seems acceptable.


BSP Depth: 50, Size: 10

There is almost no red at all in the image, which is not necessarily a good thing. Some small red areas are considered 'good'. Let's take a closer look at the Output window:

RCI 0.3 info : main bsp tree statistics: RCI 0.3 info : max depth : 50 RCI 0.3 info : max leaf size : 106 RCI 0.3 info : average depth : 41 RCI 0.3 info : average leaf size : 7 RCI 0.3 info : leafnodes : 1849215 RCI 0.3 info : bsp size (Kb) : 83620

The max leaf size is now very low, just over 100. The average leaf size (7) has dropped to well below the size that we set (10). The memory needed for this particular BSP is now 80MByte; a 30% increase compared to the previous setting. For this scene it's perfectly acceptable, but for larger scenes you need to be cautious: if the BSP takes too much memory, you'll get out of memory errors. In that case, stick with lower Depth settings.


Considering all this, we would end up with a BSP Depth setting for this particular scene of around 40 - 50, so probably 46 or so.


Changing the BSP Settings

Open the Render Settings and go to the Mental Ray tab:


MR RenderSettings BSP settings.jpg


Scroll down to the Raytracing section and then the Acceleration sub-section. Here you can change the BSP size and BSP Depth values.

From the pulldown you can choose various acceleration methods.

Regular BSP
is the default. recommended for most scenes.
Large BSP
is used in some special cases (see below)
Grid
may be used when polygons are very evenly distributed across your scene. (not recommended unless you know it's needed)


In Maya 2008 Extension 2, a new acceleration method is available: BSP2, which uses a BSP variant: BIH. It is highly efficient for high-poly scenes. BSP2 can only be selected through the mentalrayGlobals node and is only available in the Extension 2 update of Maya 2008.

General Pointers

BSP Size

Keep the default setting of 10. Only when using Motion Blur or in scenes where a lot of polygons 'stretch' across the better part of a render, you may need to change this setting.

Recommendation: Do not change the default of 10 unless you really know what you're doing.

BSP Depth

Depends on the number of polygons (triangle count) in your scene. This is displayed in the Output Window when you enable Info messages for Mental Ray, see the Rendering BSP Diagnostics section. Look near the end for a line like:

GAPM 0.3 info : triangle count (including retessellation) : 12640
small scenes (<400k triangles)
around 30
medium scenes (400k - 1 million triangles)
around 40
large scenes (> 1 million triangles)
50 - 60

Most architectural scenes typically require a BSP depth between 40 and 50.

Recommendation: Change the default for large scenes. Use diagnostics to find the right values. Don't increase to over 60 unless you really know what you're doing.

BSP memory problems

Q: My BSP is very large (>100MByte), which is really necessary. But now my render crashes with memory errors...

A: Try to fix the memory problems using other memory optimizations first and make sure your scene geometry is optimized (no unnecessary polygons, which causes your BSP to be very large). If all that is done and you still need more memory for your BSP than is available, you can choose Large BSP as the acceleration method, instead of regular BSP. Large BSP allows Mental Ray to flush parts from the BSP that are not needed at that time from memory. This feature comes at a performance penalty of up to 10 to 20% in render time.

Personal tools
Actions
Navigation
Tools