I wrote this document to prepare my presentation at the TD love tour event the 10th jan at london and the 12th jan at Paris.
Unfortunetly I didn't have the experience of talking in another language behind a big audience. So I decided to publish this.

This document try to explain a bit Mental Ray within Xsi v5. I expose some technics to optimize Render without sacrifing quality.
You can find all the shaders here

Feel free to ask question.

 

1. Mental Images Shaders


1.1 Occlusion Shader Set


What is Occlusion ? Occlusion is the extent wich the area above a point is covered by other geometry and is generally used as a simplified methods to « simulate » Global Illumination.
In Mental ray we a set of 3 occlusions shader that can work together.

Images Courtesy to Paolo Berto, Mental Images.

This is the occlusion itself, wich handle all computation. It can be used to scale down the contribution of ambient light. For this use the shader works well when assigned to the ambient parameter of material.

This shader can also handle reflection occlusion that allow the shader to scale down the contribution from an environement reflection. In this way can simulate raytraced reflection with a simple environement reflection.

Images Courtesy to Paolo Berto, Mental Images.

output mode = 0, reflective = off
reflective occlusion (around surface normal)

Images Courtesy to Paolo Berto, Mental Images.

output mode = 0, reflective = off
reflective occlusion (around the reflection direction of eye ray)

 

So if you apply a reflection map it will show reflections EVERYWHERE on the object, even in areas where the object in reality would self-reflect. With a reflective OCCLUSION map, the reflection map gets attenuated in these areas where the objects reflection is blocked (by itself or other object).

Finally the shader can output 'bent normals'. Bent normals are expressed as a RGB encoded file where X are represented by Red, Y by Green and Blue by Z. Bent normal pass encode the direction vector to look up the ambient environement. The primary purpose of 'bent normals' is to delay the ambient lightning to later stage. Later may be either in a later rendering pass within XSI ( having rendered to a texture and performing the lookup with mib_bent_normal_env) or in an external compositing application like the Fxtree.

Images Courtesy to Def2shoot, Paris.

This utility shader return occlusion with the help of Final gathering algorithm. You need for that to activate the FG in Xsi to it working. We have all the advantage of Final Gathering such as file caching ( Fgmap ) and support of transparent object.

For the same quality the standard AO takes about 11 min to render while FG one takes about 7 min.

This is a shader to be used after lightmaping/rendermaping ( a.k.a. 'texture baking' ). We will discuss it later in outdoors exemple.

1.2 Physical Light shader set


Here we have a set of 2 shaders who can work together : mib_cie_d and physical_light. The light shader physical_light models phycially correct light sources. As for ideal point light, the light intensity falls off with the inverse square of the distance. In other word you have a nice very cool light falloff you just have to care about light intensity. By default in Xsi light have not any falloff. They light until infinity. However you can specify a fallof but you may not be phycally accurate.

mib_cie_d shader return a color according a given temperature and intensity. Temperature are expressed in Kelvin. 6500 K is considered as the white point by the Commission Internale de l'Eclairage ( CIE ). Above 6500 mib_cie_d will return a cold color while under 6500 return warm color.

 

1.3 mib_glossy_reflection/refraction


Xsi features mental ray 3.4. That mean that give us access to the new glossy materials, faster the one provided with XSI.

Images courtesy to Gent Krasniqi

 

1.4 How to get them ?


We have a bunch of new supra cool shader but how to get them ? Fortunetly the libraries are provided with XSI 5.0 only SPDL ( graphic user interface ) are missing. We have just to create these SPDL to get them in XSI.

Case studie the mib_cie_d.

Go to :


C:\softimage\XSI_5.0\Application\phenolib\include
Here you have all mental ray shader definition. Open the base.mi
Go to mib_cie_d ( line 840 )
we have :


declare shader

color "mib_cie_d" (

scalar "temperature",

scalar "intensity"

)
version 1
apply light

end declare

The shader mib_cie_d is driven by 2 scalar parameters : temperature and intensity. And it s a light shader.

What we need is to create the spdl with the same definition. We will use the shader wizzard to do this.

In Xsi :

The wizzard will generate a C template and the spdl. We don't need the C template.
Edit the Spdl file directly.
Remplace each FileName = "mib_cie_d" by FileName = "base".

Go to C:\softimage\XSI_5.0\Application\bin\nt-x86-vc71 and copy the base.dll where you spdl was generated.
Go to the plugins manager and install your spdl. Make sure that Xsi can find the library.

2. Outdoors Scenes.

When it comes to light a outdoor scene everyone think about finalgathering and HDR images. Here we will compare two approachs. The Finalgathering approach and the ambient occlusion approach.

2.1 FG vs AO ( Speed/Quality comparaison ).


I will kill the suspense. Both are valid. Let's do a quick comparaison. We have a scene with a car ( 500K polygons ). One light to simulate the sun and an Hdri as an environement.
Both scenes aren't optimised yet.

FG Contribution

Settings :
AA 0/2 threshold 0,047 Gauss 3/3
FG 128 accuracy min 1 max 10 Presampling 3
Falloff min 1 max 10.
FG time : 0:02:37 Rendering time : 0:03:58
Total time : 0:06:35

Ambient Occlusion Contribution

Settings :
AA 0/2 Treshold 0,047 Gauss 3/3
Amb_Occlusion sample : 64
Rendering 0:06:12

FG and AO look pretty similar and the render time are almost same. So what is the difference between AO and FG?


FG is concerned with bounced light and multibounce transparency, reflection, refraction and diffuse rays, whereas AO is more concerned with the absence of light, simulating the bounced light with an assumed omnipresent 'environement light' ( generally coming from diffuse environement map or a sold color ) and letting occluding geometry block light.


The output of mib_amb_occlusion is not filtered and hence is never as smooth as FG but instead any filker is never lerger than a sample ( less than a pixel ). There is no risk in losing small surface details.

2.2 Optimising AO Render


We will need amb_occlusion_shader and the mib_env_bent_normal. The idea is to bake the occlusion contribution on a map and the result to sample the environment.

We are ready to rendermap all objects. Make sure you are rendering in a float 32 bits formats.
Avoid overlapped UV !!!!!


Once you have rendered all object you need to connect in the ambient slot the mib_bent_normal with the rendermapped texture.

 

 

Rendering time after optimisation is about 0:02:04

We reduced the rendertimes by 3 while we have increased the sampling rate to 128.

Note that the slider of the global ambience of Xsi will control the contribution of environement on your objects.
Note also that you can use this technique only on rigid objects so no skinned objects.

 

2.3 FG strategies.


When objects don't move ( eg. A city or a set ) use FG maps to cache the irradience.

Fg compuation will be skipped and Fgmap is read to render irradience.

When doing IBL ( Image based Lighning as known as HDR render ). Blur and scale down the image to something like 64 pixels wide.

Use ray_type node and open FG port . Connect the average color of your material or a simplified network. It will speed up a lot the FG processing.

Bake the into maps like AO . In case of reflective object ( read with specular and/or reflection/refraction ) bake the diffuse only. Re do a new shader network where you calculate only the specular and reflection. Switch off Finalgather.

Desactivate Finalgather preview ! It 's nice when you are tweaking your scene but it slow down the render.

In mental ray 3.4, there is now a density factor to control the number of FG points in FG pre-processing. For increasing FG density, this is now recommended over lessening the FG max radius distance. Here's why:

When increasing density with the density factor, the number of FG points used surrounding the intersection point will also increase, while the surrounding area used for interpolating FG points will stay about the same.

When decreasing the FG max radius distance, the number of FG points used for interpolation will stay about the same, while shrinking the surrounding area of FG points. That is what increases FG point density, but could also increase noise.

Also, in mental ray 3.4, you can roughly halve the number of FG rays for the same quality.

Additionally, the adaptivity of the FG points in preprocessing is better.

All this means that you should see able to tune out flicker faster!

 

Once the optimisation done the render went down to :
FG Computation : 0:38.71
Rendering : 0:01:30.47
Total time : 0:02:08

2.4 FG vs AO conclusion


With Ambient Occlusion probe rays provide a 1-bounce-only illumination effect while Finalgather in mental ray can provide diffuse multibounce illumination ( since XSI 5.0 ). Furthermore, the Final gathering algorithm in the last release of Xsi is very much enchanced compared to earlier versions and resolves many issues related to potential animation flickering and detail loss, closing the gap ever further between Ambient occlusion and Final gathering, making it more an artistic and/or pipeline-architectural choice which method is employed.

As soon as I have to deal with outdoor scenes I prefer to use the ambient occlusion approach. Because I don't have to deal with potantial flickering that Finalgather can lead to. The AO looks heavy to setup specially when you have to start to bake. But optimizing Finalgather render can be heavy as well ( still simplier than AO by the way ). If you do all the baking work when you have finished the modeling of your object, it's become more praticable. You have a big advantage with AO over FG, you can move your object ( if they are rigid ) and the look up to environement is still correct.