On this page

Chapters

Overview

Sampling is the heart of modern render engines. Sampling refers to the simulated light rays Karma sends into the scene to determine the color of each pixel of the rendered image.

Tip

The terms sample, path, and ray are generally interchangeable when talking about path tracing.

First Karma sends samples out from the camera that then hit objects in the scene. These are the primary samples. When objects are hit, Karma uses the object properties (such as surface orientation and materials) to send out secondary samples. These additional rays hit other surfaces and lights, until the final color of the pixel is determined.

Primary
Secondary (Direct)
Secondary (Indirect)

Tip

The behavior of Primary Samples can usually refer to Path Traced Samples.

Primary samples

  • Pixel-to-camera rays that hit some object in the scene.

  • Used to resolve noise/artifacts from:

    • Geometry and Curve Details

    • Displacement

    • Depth of Field

    • Motion Blur

Secondary samples

  • Rays cast from the hit position of primary samples, toward other directions in the scene.

  • Direct Samples are position-to-light rays:

    • Light Samples

  • Indirect Samples are position-to-position rays:

    • Diffuse

    • Reflection

    • Refraction

    • Sub-Surface Scattering

    • Volume

Oversampling (sending out more rays than you need for a given quality level) and under-sampling (sending out too few rays to achieve a given quality level) are sources of slow-downs when rendering. Understanding the differences between primary and secondary samples will help you to use Karma more effectively.

Convergence Ray Counts

Understanding how primary and secondary samples are related helps estimate the maximum number of rays Karma uses when rendering. User settings, per-object overrides, and algorithms make predicting the exact number impossible. Understanding how these parameters influence one another helps debug performance.

The number of rays Karma uses is determined by the total number of primary samples and secondary samples fired for each pixel. Beyond that, we need to know the engine and convergence mode being used.

CPU - Automatic Convergence
CPU - Path Traced Convergence
XPU - Path Traced

Rays Cast per Pixel

=

[Primary Samples] + [Secondary Samples]

Secondary Samples

=

[Primary Samples] *
([Max Direct Samples] + [Max Indirect Samples])

Max Direct Samples

=

[Number of Lights Sampled] *
[Light Sample Quality] * [Max Secondary Samples]

Max Indirect Samples

=

[Max Secondary Samples] * [Diffuse Quality] +
[Max Secondary Samples] * [Reflection Quality] +
[Max Secondary Samples] * [Refraction Quality] +
[Max Secondary Samples] * [Volume Quality] +
[Max Secondary Samples] * [SSS Quality]

Rays Cast per Pixel

=

[Primary Samples] + [Secondary Samples]

Secondary Samples

=

[Primary Samples] *
([Max Direct Samples] + [Max Indirect Samples])

Max Direct Samples

=

[Number of Lights Sampled] *
[Light Sample Quality]

Max Indirect Samples

=

[1 Randomly-Chosen Indirect Sample]

Rays Cast per Pixel

=

[Primary Samples] + [Secondary Samples]

Secondary Samples

=

[Primary Samples] *
([Max Direct Samples] + [Max Indirect Samples])

Max Direct Samples

=

[Number of Lights Sampled] *
[Light Sample Quality]

Max Indirect Samples

=

[1 Randomly-Chosen Indirect Sample]

Choosing an engine

Choosing which engine and/or convergence mode is the first step. By default Karma CPU with Automatic convergence is enabled. After considering some of these points, and doing some testing of course, you might consider a different engine/mode.

Engine

Reasons

Karma CPU

  • Still rely on existing VEX shaders/features from Mantra

  • Finer control over primary and secondary sampling

  • Support for convergence modes and pixel oracles

Karma XPU

  • Want to exploit CPUs and/or GPUs for rendering

  • UsdMaterialX-based shading

  • Prefer simpler approach to resolving noise

Sampling in Karma CPU

Karma CPU offers a much wider array of sampling controls compared to Karma XPU. It supports Path Traced convergence (see below), but defaults to a sophisticated adaptive sampling approach for both primary and secondary rays.

Primary samples

The rays that Karma sends from the camera into the scene are called primary samples. Primary samples resolve anti-aliasing artifacts from small geometry detail (such as curves or displacement), depth of field, and motion blur. Sufficient pixel samples improves the overall sharpness and quality of the image.

Tip

Primary Samples are sometimes also called camera rays, AA samples, or pixel samples, especially by other renderers.

1 pixel sample, jagged edges
Multiple pixel samples, smoother result

A single primary sample is usually too coarse for anything more than debugging. Increasing the pixel samples gives much smoother representation of the shapes in the scene. While this improves quality, even in secondary noise, it can be overkill because primary samples are a multiplier on the secondary samples. For Karma CPU, the pixel oracle can help Karma avoid over-sampling the pixels.

Pixel oracle

Karma CPU supports adaptive primary samples, using pixel oracles. Pixel oracles represent the logic Karma should use when casting rays from each pixel. Currently, Karma ships with 2 pixel oracles: Variance and Uniform.

By default, Karma uses the Variance Oracle, which detects differences between neighboring pixels to avoid sending too many primary samples by stopping when each additional sample will have very little effect on the final pixel color. Karma will send a small number of primary samples, then the Variance Oracle starts comparing pixels against the Oracle’s Variance Threshold. Once the variance between the previous samples of the current pixel and adjacent pixels fall below that threshold, Karma stops firing primary samples for that pixel.

The Uniform Oracle simply sends the same number of primary samples from every pixel in the scene. You may want to switch to the Uniform Oracle when extreme depth of field (DOF) or motion blur dominates the image. In those cases, Karma ends up fully sampling every pixel anyway, so measuring variance just adds overhead.

Warning

Karma XPU does not currently support Pixel Oracles for GPU or CPU devices. It casts the same number of path traced samples from every pixel.

Secondary samples

Once a primary ray intersects an object, Karma will cast Secondary Samples from each primary ray’s hit location. For every hit position, Karma will send direct and indirect secondary samples. Direct samples are sent towards lights. Indirect samples are sent along directions determined by the geometry and shader, at the hit position. Secondary samples can be diffuse, reflection, refraction, subsurface, or volume rays.

Volumetric objects are handled a bit different from surfaces. Instead of sampling only a single hit position, Karma marches along the ray, sampling multiple points through the volume. At each positions along the ray, direct and indirect rays are sent out into the scene. Not every position within the volume is used; instead Karma intelligently chooses a subset of positions to sample.

Limits

To avoid rays potentially traveling forever, Karma provides per-type “bounce” limits. You may need to increasing these limits to ensure Karma takes enough indirect samples to get the desired look. Refraction often needs a higher limit, to improve the quality of scenes with glass and liquid materials. Volumes may also benefit from increased limits, to capture the subtle effects of volumetric lighting.

Increasing the limits can increase render times substantially. Only increase limits as needed, to achieve a desired look.

Light Tree

Karma automatically builds a light tree to make rendering scenes with many lights more efficient. This helps Karma efficiently decide which lights should be sampled the most, and are most likely to resolve faster. Karma automatically builds a light tree, and automatically adds lights to it, when it reaches certain thresholds:

Karma CPU

10 Lights

Karma XPU

2 Lights

There are some cases where lights will not be added to the light tree, such as dome and directional lights, or lights which have light filters. Light Sampling Mode can change this behavior, and tell Karma to sample all lights in a scene. Long, thin rectangle lights are not great for the light tree. Internally it represents lighting with bounding spheres, so these lights can cause the light tree to add more noise.

Once Karma determines which light to sample at a given hit position, the Light Sampling Quality parameter determines how many rays are fired towards the light.

Convergence modes

The convergence mode is the strategy used by Karma to send secondary samples into the scene. Karma supports two convergence modes: Automatic and Path Traced. While convergence mode determines secondary rays, this choice also influences how many pixels samples are necessary for the scene.

Note

Karma CPU supports both Automatic and Path Traced modes, but Karma XPU only supports Path Traced convergence, and does not support the Pixel Oracles.

Automatic

By default, Karma is setup to use Automatic convergence, as it is generally results in cleaner final renders, and offers more controls to reduce noise without over-sampling areas of the render.

Primary Sample Controls

Secondary Sample Controls

  • Primary Samples

  • Pixel Oracle

  • Min/Max Secondary Samples

  • Indirect Samples Quality (Per-lobe quality)

  • Light Sampling Quality

For every primary sample that hits an object, Karma will fire secondary samples. Karma will trace at least one ray for each type of lobe the shader produces (diffuse, reflection, refraction, sss and/or volume). Karma will send secondary rays until the Max Secondary Samples value is reached, or the variance falls below the threshold.

Karma provides an addition set of Indirect Sample Quality controls. You can use these to reduce noise in specific lobes. The values are multipliers for the Min/Max Secondary Sample values, but only apply to each specific ray type.

Path traced

In Path Traced convergence mode, the only control is Path Traced Samples. This sets the number of primary samples Karma will cast. The expected range of values is different compared to Automatic mode, so the parameter uses a different name to help reduce confusion.

1 path traced sample, jagged edges
Multiple path traced samples, smoother result

Primary Sample Controls

Secondary Sample Controls

  • Path Traced Samples

  • Pixel Oracle (Karma CPU only)

  • Light Sampling Quality

In this mode, when a primary ray hits an object, Karma will send two secondary samples by default: one direct sample toward a light, and one indirect sample into the scene. This simplicity can make Path Traced convergence very fast and interactive initially, but offers very few controls for resolving noise from specific secondary ray types in the scene. Light Sampling Quality will determine the number of times each light is sampled, but Karma decides how many lights to sample, based on the Light Sampling Mode. Karma also randomly chooses the indirect sample lobe.

Note

In interactive viewport rendering, Karma does some path tracing for the first few samples, before switching over to automatic convergence. This improves the interactive experience in Solaris.

Sampling in Karma XPU

The primary rays that Karma XPU sends from the camera into the scene are called path traced samples. Path traced samples resolve anti-aliasing artifacts from small geometry detail (such as curves or displacement), depth of field, and motion blur. With Karma XPU the only control is Path Traced Samples. This sets the number of primary samples the XPU engine will project for each pixel.

Tip

Because XPU does not currently support adaptive path traced samples, the primarysamples AOV values will be the same path traced samples value for every pixel in the image.

Primary Sample Controls

Secondary Sample Controls

  • Path Traced Samples

  • Light Sampling Quality

In this mode, when a ray hits an object, Karma will send two secondary samples by default: one direct sample toward a light, and one indirect sample into the scene. This simplicity can make Path Traced convergence very fast and interactive initially, but offers very few controls for resolving noise from specific secondary ray types in the scene. Light Sampling Quality will determine the number of times each light is sampled, but Karma decides how many lights to sample, based on the Light Sampling Mode. Karma also randomly chooses the indirect sample lobe.

Local Sample Overrides

Many of the sampling settings can also be set on objects of the scene. Per-light and per-object settings are usually multpliers on their global counterpart. If a property does not mention “scale” or “multiplies” in its description, then it overrides the equivalent global property.

Also it’s worth noting that if an engine or convergence mode does not support a given sampling style/feature, per object overrides won’t have an effect.

Note

Karma does not support per-object overrides for Primary/Path Traced Samples.

Next steps

With an understanding of how sampling works in Karma, next we’ll look at some practical tips to reduce noise in your renders.

Chapters

Karma user guide

Chapters

Reference