Page tree

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Contents

In order to render images with as low noise and as fast convergence as possible, it is important to use samples that do not clump and do not leave large parts of the sampling domain empty.  We say such samples are well stratified.  There are several different ways of generating such well-stratified samples; RenderMan uses lookups in pre-generated tables of progressive multi-jittered (PMJ) sample sequences which are suitable for progressive rendering and stratified in 1D, 2D, and 3D.  The 1D samples are between 0 and 1, the 2D samples are on the unit square, and the 3D samples are in the unit cube.  (Practical tips on how to map to other domains are mentioned below.)

In order to look up in one of the pre-generated sample tables one needs to specify which table to use and which sample number.  RenderMan provides a convenient abstraction class and API for this, called RixRNG.

The API is defined in include/RixRNG.h (and the implementation of PMJ table lookups are in include/RixRNGProgressive.h).

The SampleCtx struct

A sample context (SampleCtx) consists of two unsigned integers: patternid and sampleid.  Patternid is a 32-bit pattern that gets hashed to one of the built-in PMJ  tables, and sampleid determines which of the samples in the table to use.

The RixRNG class

The "RNG" part of RixRNG stands for "Random Number Generator" even though the samples are not random all.  The RixRNG class is basically just a wrapper around an array of per-shading-point sample contexts (SampleCtxArray) and an integer (numPts) specifying how many sample contexts there are in the array.  There is typically one SampleCtx for each point in a ray batch.  The RixRNG wrapper class makes it convenient to generate sample points (or new sample domains) for an entire ray batch with just a single function call.

Generating samples

There are six different functions to generate samples: DrawSample1D(), 

Generate functions increment the sample context sampleid; Draw functions do not.

Multipoint functions: generate samples for all points in a RixRNG: GenerateSamples1D(), GenerateSamples2D(), GenerateSamples3D(), DrawSamples1D(), DrawSamples2D(), and DrawSamples3D().

// Generate a sample and increment sample id

Bxdf calls ...

Integrators call ...

Generating new sample domains

Here "domain" means ... actually just a different bit-pattern patternid.  The name "domain" was chosen because typically a different patternid is used for bxdf sampling, light source sampling, etc., with the bxdf and light sources being different "sample domains".

NewDomain

The 'newdomain' patterns can be any bit pattern, but it is important that the bit pattern to generate different new domains are different.  For example, if an Integrator is generating new domains for bxdf and light source sampling, those should use different 'newdomain' bit patterns.  Otherwise there will be visible correlation between bxdf and light source sampling, leading to visible artifacts and poor convergence – or no convergence at all!

Tips for using samples in practice

Mapping from unit square to other domains ...  Example: uniform sampling a disk.  RtPoint2 sample = DrawSample2D(...);  radius = sqrt(sample.x); phi = 2 * M_PI * sample.y; point.x = radius * cos(phi); point.y = radius * sin(sample.x);

When to use splitting and when not.

Shirley remap.  Example: Select a light source and then a position on that light source.  Figure of samples before and after remapping?

Splitting:  intuition: 1 cam ray x 4 diff rays should give same diffuse directions as 4 cam rays x 1 diff ray.  Figure?

Non-stratified samples similar to e.g. drand48(): ... Repeatable, and no multi-threaded contention (drand48() has notoriously bad locking, hampering multi-treaded performance).

Advanced topic: PMJ table lookup implementation

Above we wrote that patternid is used to choose the PMJ table, and sampleid is used to choose the sample in that table.  If we had 2^32 pre-generated PMJ tables it really would be as simple as that.  However, in practice we have only a few hundred different PMJ tables, so we have to be a bit inventive to make it look like we have many, many different tables even though we don't.  The trick – implemented in include/RixRNGProgressive.h – ... scrambling and shuffling.

Another practical detail is that even though PMJ tables theoretically could be generated with infinitely many samples, in practice we limit each table to 4096 samples.  When a sampleid higher than 4096 is requested, we look up from the beginning of another table.  So the samples beyond 4096 are still stratified, just not quite as well stratified with respect to the first 4096 samples as if we had had larger tables.

Advanced topic: Overriding the RixRNG implementation

It is possible to override the default PMJ samples if other sample sequences are desired.  This is scary stuff.  The Generator class ... When a custom Generator has been specified, it automatically gets called when e.g. a Bxdf of Integrator calls one of the GenerateSample or DrawSample functions.

More information

For more (very nerdy!) details about the properties of PMJ samples please refer to the following paper:

  "Progressive multi-jittered sample sequences",

  Per Christensen, Andrew Kensler, and Charlie Kilpatrick,

  Computer Graphics Forum (Proceedings of the Eurographics Symposium on Rendering), 37(4):21-33, 2018.

Paper and presentation slides are available here:  graphics.pixar.com/library/ProgressiveMultijitteredSampling