What is Sampling?

When working with a renderer like Arnold, it is useful to have a basic understanding of the core principles behind ray-trace rendering. Producing a realistic-looking image of a virtual scene requires simulating the propagation of light in the scene all the way from the light sources to the camera. To determine the color of each image pixel, Arnold collects information from the scene geometry, shaders, lights, etc., and traces a number of random light transport paths that connect the objects seen through the pixel to the light sources - a process called 'sampling'. The quality of the resulting image largely depends on the number of paths, or samples, generated for each pixel.


When rendering an image, Arnold must determine a color value for each pixel by examining the scene. Arnold achieves this by sending out a number of rays from the camera’s position until they hit an object in the scene. Every time a ray hits an object, it will perform some calculations that will eventually return a piece of information about the object (its color, for instance). This process can basically be described as 'sampling' the pixels in the virtual camera's image plane.

Renders computed with too few samples in each pixel can be noisy. Increasing the number of samples per pixel gives a less noisy image which better represents the actual scene. The images below show a comparison when increasing the number of Camera (AA) samples in a scene. Not only does increasing Camera (AA) samples reduce aliasing noise, but it also adds more secondary ray samples which also reduces noise in the lighting.


Camera (AA) Sampling 

So, what is camera sampling? Basically, a number of rays are shot from the camera through each required pixel of the rendered screen window into the scene. These are called 'primary rays', but sometimes they are referred to as 'eye' or 'camera rays' (Camera (AA) (anti-aliasing)) as they are cast from the rendering view. Sometimes they are called 'pixel samples'.


The Camera (AA) value controls the pixel supersampling rate or the number of rays per pixel that will be traced from the camera. The higher the number of samples, the better the anti-aliasing quality, but the longer the render times.


Note that this process is not linear, as, for each of these sampling rates, the actual number of samples taken is the square of the input value.  For example, if Camera (AA) samples is 3, it means that 3x3 = 9 samples will be used for anti-aliasing. If Diffuse samples is 2, then 2x2 = 4 samples will be used for the Diffuse GI. The same applies to the other values.


These AA samples could be described as primary rays (or pixel samples) and determine the overall quality of the image being rendered. Increasing the AA samples improves the overall quality of the image, but it can often be wasteful because it increases the sampling rate for everything. When the source of noise is identified in the scene, it is more efficient to set the sampling values to increase the number of only those specific rays. If for example, there is a scene with lots of motion blur, a larger Camera (AA) sample is required, and therefore the other sample values can be reduced. Likewise, increasing Camera (AA) can also benefit indirect lighting and therefore not as many Diffuse samples would be required. However, if you were to reduce noise on the skin of a character, it would be more efficient to have higher SSS samples and not such a high value for Camera (AA) samples.

Light Sampling 

Direct lighting rays can be described as rays which deal with lights. These rays travel from a position in the scene toward the various light sources. These rays determine if a surface is in shadow, and if not, lighting information can be calculated.

Noise from lights can sometimes be difficult to diagnose, particularly if it is a light with a large area or size. In these cases, it can sometimes be mistaken for indirect diffuse noise. This highlights the necessity for testing different noise ray types. If the issue is shadow noise, then we can simply toggle ignore shadows in the Arnold render settings, and the noise will completely resolve. The images below show how a light is traced in Arnold.

The same noise problems described earlier can occur with direct and indirect rays. Noise from direct light sources usually appear in specular highlights or in large, soft shadows from area lights. If this is the case, the number of light samples needs to be increased. The images below show the difference in the shadow noise when increasing the number of light samples from 1 to 3.


It can be useful to separate one source of noise from another, when trying to evaluate noise in a scene. Disabling 'Diffuse' rays (0) can help identify which type of noise is present. When attempting to optimize the number of indirect diffuse rays in a scene, rather than increasing the number of Diffuse rays (render time will double for each Diffuse sample), the source of the noise will need to be isolated first.


Diffuse Ray Sampling

Indirect (diffuse) lighting from emissive green cube. Rollover image to view direct lighting only (Diffuse Samples 0)


Indirect Diffuse rays are rays that interact with objects and their surface shaders. Therefore, rays travel in the scene in directions determined by the shader assigned to the object. Transmission rays travel through objects. When a ray hits a reflective object, such as a mirror, only one reflection ray is traced from that point in a direction determined by the incoming ray. In contrast, diffuse rays are sampled randomly in the hemisphere around the hit point.

Diagram showing how diffuse rays are propagated in an Arnold render


Specular Ray Sampling

When rendering glossy specular surfaces, noise can also be a problem, as with diffuse rays. Bright hotspots can cause noise in indirect specular samples. For example, wide specular reflections of small, bright lights. If the issue is noise in a specular highlight, it needs to be confirmed that the source is the direct light and not a secondary ray type (such as specular). This is easy to achieve by setting the GI_diffuse_depth, GI_specular_depth to zero (this essentially turns off all global illumination). If the noise is still there, we know it is the direct specular component of the illumination model. In most cases, it can be resolved by increasing the number of specular samples.


When sampling volumes, direct (AA) rays sample the volume multiple times as they travel through it. Indirect rays (Volume Indirect) behave similarly, sent multiple times as the ray 'steps' (volume step size) through the volumetric object. Therefore, sampling a volume usually takes longer to calculate than sampling a surface. 

Volume sampling. Direct lighting (green). Indirect lighting (blue).


At each step the ray travels, it evaluates the shader and accumulates the density of the volume. When these density values become more erratic throughout the volume, nearby rays can calculate substantially different values, introducing noise into the render. In this case, it may be necessary to render using more light volume samples or to reduce the step size in the volume. Even with low sampling values, it can be expensive to render clean images with volumes. 

There are three things to consider when rendering volumes; ray marching, direct light, and indirect light sampling, all of which have different sampling settings.

Step Size
The step_size of the ray marching process. Too low a sampling rate here will cause the volume rendering to miss small details in the volume, making them noisy, making them thinner than they should be, or making a bad estimate of the exact position of the 'surface' of a 'solid' volume like a pyroclastic cloud. A bad step size has a snowball effect that can make the rest of the sampling process noisier. This is pretty easy to test by looking at the alpha channel, or by adding some emission to the volume and turning off all lighting. If the emission/alpha channel is noisy at the desired AA setting, then the step_size is probably too large.


Step size is actually in object-space and not in world-space. This is so that the sampling quality remains the same upon scaling of the volume's transformation. However, unreasonably large step sizes should be avoided. Otherwise, the volume will appear thinned and washed out. In the example images below the volume has been scaled up to 100 units to exaggerate this effect (1/25/50 are relative to the size of this volume). 



Generally, the step size needs to be as large as possible before visibly noticeable artifacts occur. Low Step Sizes will increase render times. For example, when the step size is 0.1, and the volume is 10 units big in world space, there are approximately 100 primary samples, and therefore the volume shader is called 100 times.


Direct Lighting
When the step size is correct, noise can come from either direct or indirect lighting. Direct lighting is pretty easy to detect. The indirect light needs to be toggled off, and if the render is noisy, each light needs to be rendered one at a time until the light that is responsible for the noise is found, and turn up their volume_samples. If the direct lighting noise doesn't significantly decrease as volume_samples increases, then it's probably due to a too-low ,step_size or simply difficult to sample light interactions (highly anisotropic volumes, heavily textured mesh_lights, quadratic falloff, etc. ). In this cas, there's not much to do except to eliminate the samples via clamping or filtering.
Indirect Lighting
Indirect noise is also easy to identify. GI_volume_depth of a noisy volume needs to be disabled, and if the render is no longer noisy, then the problem is indirect sampling. If the quality needs to be improved, the number of volume_indirect_samples needs to be increased. If increasing this doesn't reduce noise, then the noise could again be from difficult to sample light interactions (multiple scattering, anisotropic volumes, lights embedded in the volume, etc.) and as mentioned before there's not much to do except to eliminate the samples via clamping or filtering.
Volume ray depth

Increasing the volume ray depth can make a dramatic difference to the appearance of a volume. However, be aware that increasing the volume ray depth will increase the number of multiple scattering bounces within the volume (defaults to 0) and therefore render times will increase significantly. 


Further information about sampling can be found here.

Further information about removing noise can be found here.




Pepe model by Daniel M. Lara (Pepeland)

  • No labels