Explains the background details of how Mantra uses raytracing to shade objects in the scene.

## BSDFs

A bidirectional scattering distribution function (BSDF) controls how light reflects off a surface.

BSDFs are probability models. Given a certain angle of incidence, a BSDF will calculate a the probability that the light ray will bounce off the surface in a certain direction.

BSDFs are bidirectional. That means it can calculate how a ray of light from a light source bounces off a surface, and it can also, given a ray from a camera to a surface, work in reverse to calculate an angle from the surface to the light source.

Since Houdini 13, Mantra’s shading model is based on BSDFs: all render engines use BSDFs and the standard final product of a Mantra shader network is a BSDF (although the Output VOP still accepts `Cf` and `Of`).

## How Mantra ray traces surfaces

1. Mantra fires a certain number of primary rays (a.k.a. direct rays) per pixel (controlled by the Pixel samples parameter).

The default Pixel samples is 3×3, or 9 primary rays per pixel.

2. When a primary ray hits a surface, Mantra fires secondary rays (a.k.a indirect rays).

The number of secondary rays is also controlled by the Pixel samples. When Ray variance antialiasing is on, the number of samples multiplied by a number Mantra calculates based on where it needs more rays. The minimum multiplier is the Min ray samples parameter (default `1`, meaning use the number in Pixel samples), and the maximum is Max ray samples (default `9`, or nine times the number in Pixel samples).

Mantra runs each surface shader BSDF in reverse, trying to backtrack from the camera angle back to a light source. A BSDF will have multiple possible result angles based on the camera angle. Mantra simply chooses an angle at random according to the BSDF’s probability model. The more rays, the more the noise introduced by this randomness evens out.

For surface shaders with multiple BSDF components (which is the usual case). For example, a surface shader might have one or more reflective components, a diffuse component, and a sub-surface scattering component. In this case, Mantra calculates the best distribution of rays to satisfy all BSDFs in the shader.

3. For each secondary ray, Mantra uses a 3D tree search algorithm to find surfaces or lights along rays computed by the BSDF. (This is why area lights are more efficient in physically based rendering: they're easier to find.)

When a ray hits a surface:

• The sample is considered to be in shadow (the shader can use the Is Shadow node to test for this).

• If the bounce limit for this type of ray hasn’t been reached yet, Mantra will again send secondary rays and repeat the process. Rays sent by reflect, diffuse, and refract have different bounce limits (on the Properties ▸ Shading tab of the Mantra node). The default Diffuse limit is `0`, meaning the rays will stop when they hit the first surface (so you will not see objects reflected in other objects unless you increase this limit).

When a ray hits a light:

• The sample is considered unshadowed (the shader can use the Is Shadow node to test for this).

• Mantra takes all the collected values and computes the pixel color based on the light color and the colors of all the hit surfaces.

Note that if you start with the default 3×3 = 9 samples per pixel, and each bounce sends out 9 or more additional rays, if you increase the allowed bounces (for example, to allow diffuse bounces), the number of rays can explode and rendering can get slow. If you need more bounces, you might try decreasing the base pixel samples and then increasing the max ray samples so Mantra uses fewer rays in simple cases but more where they're needed. Or, if you don’t care about render time, you could just set pixel samples to 12×12 and turn off ray variance antialiasing to get extreme quality uniformly everywhere and a very long render time. See render quality and speed for how to use the rendering parameters to balance speed and quality.

## Ray tracing volumes

Mantra treats volumes similarly to surfaces. It dices a volume into micropolygons. When a ray hits one of the micropolygons, it will stop or send additonal rays (based on the Shading ▸ Volume Limit parameter).

Mantra treats BSDFs as first-class objects. Certain VOP nodes such as the Reflect VOP can generate them and you can use the Add, Multiply, and Subtract VOPs to combine BSDFs.

All VOPs that generate a BSDF have a Label parameter. This lets you associate a name with the shading component the BSDF represents, such as diffuse, reflection, refraction, or sub-surface scattering. You can use these labels in two ways:

## Tips

• If you are using caustics or emission (including sub-surface scattering) in your shaders, on the Mantra node, On the Properties ▸ Shading tab, set Allowable paths to "All".

# Rendering

## Mantra user guide

• Explains how sampling works in Mantra.

• Automatically "scoop out" geometry with one shader from inside overlapping geometry with another shader, allowing different shading properties inside.

## Basics

• Lets you drag a box in the viewer to render an automatically updating preview of that part of the view.

• How to use variables and expressions in file path fields to generate numbered and unique filenames.

• Renders the contents of the viewer as images, allowing you to play them back at full speed.

## Lighting

• The light bank is a data tree view that lets you set various parameters on all lights in a scene through a single interface.

• You can instance lights onto points at render time just like instancing geometry.

## Next steps

• Tips on how to integrate Houdini and Mantra into a production pipeline efficiently.

• Explains the background details of how Mantra uses raytracing to shade objects in the scene.

• A quick overview of how to reduce the size of IFD files when rendering with Mantra. How to use procedurals, Alembic archives, and packed primitives to make IFDs smaller, and how IFDs work with HQueue.

• When you generate an IFD file for rendering, you can choose whether to "inline" the geometry in the IFD file, or store the geometry in external files.

## Guru-level

• How the Physically Based Rendering engine in mantra uses VEX to compute lighting.

• This help page is for informational purposes only. The Amazon Cloud render service is unavailable indefinitely for Houdini . due to reasons outside of SideFX’s control. You can render scenes on an on-demand render farm running on top of the Amazon EC2 compute service.