RenderManAPI  24.0
RixRNGProgressive.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 2020 Pixar. All rights reserved.
5 #
6 # The information in this file (the "Software") is provided for the exclusive
7 # use of the software licensees of Pixar ("Licensees"). Licensees have the
8 # right to incorporate the Software into other products for use by other
9 # authorized software licensees of Pixar, without fee. Except as expressly
10 # permitted herein, the Software may not be disclosed to third parties, copied
11 # or duplicated in any form, in whole or in part, without the prior written
12 # permission of Pixar.
13 #
14 # The copyright notices in the Software and this entire statement, including the
15 # above license grant, this restriction and the following disclaimer, must be
16 # included in all copies of the Software, in whole or in part, and all permitted
17 # derivative works of the Software, unless such copies or derivative works are
18 # solely in the form of machine-executable object code generated by a source
19 # language processor.
20 #
21 # PIXAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL PIXAR BE
23 # LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
25 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. IN NO CASE WILL
27 # PIXAR'S TOTAL LIABILITY FOR ALL DAMAGES ARISING OUT OF OR IN CONNECTION WITH
28 # THE USE OR PERFORMANCE OF THIS SOFTWARE EXCEED $50.
29 #
30 # Pixar
31 # 1200 Park Ave
32 # Emeryville CA 94608
33 #
34 # ------------------------------------------------------------------------------
35 */
36 
37 #ifndef RixRNGProgressive_h
38 #define RixRNGProgressive_h
39 
40 // IWYU pragma: no_include <assert.h> // for assert
41 // IWYU pragma: no_include "RiTypesHelper.h" // for RtFloat3, RtFloat2
42 // IWYU pragma: no_include "prmanapi.h" // for PRMAN_INLINE
43 
44 // This file is intended solely for inclusion by RixInterfaces.h and should
45 // not be included directly. Here we define inline implementations of private
46 // RixRNG methods. Conceptually the contents of this file are "opaque" but
47 // we provide them to deliver the highest performance. Each release may
48 // differ from the last, so in order to obtain the new benefits, clients
49 // will need to recompile.
50 //
51 // These routines collectively implement progressive multi-jittered (PMJ) sample
52 // sequences based on lookups in precomputed tables. The progressive multi-jittered
53 // sample sequences are described in detail in:
54 // "Progressive multi-jittered sample sequences" by
55 // Per Christensen, Andrew Kensler, and Charlie Kilpatrick,
56 // Proc. Eurographics Symposium on Rendering, 2018.
57 // (http://graphics.pixar.com/library/ProgressiveMultiJitteredSampling/).
58 //
59 // See also the related work on correlated multi-jittered sample sets described
60 // in Pixar Technical Memo #13-01, "Correlated Multi-Jittered Sampling"
61 // (http://graphics.pixar.com/library/MultiJitteredSampling/).
62 //
63 // Alternatively, you may use the fields in Ctx as inputs to your own
64 // sampling sequence instead if you prefer.
65 //
66 
67 //
68 // Progressive multi-jittered samples (PMJ).
69 // Lookups in a pre-generated table of progressive samples.
70 // We xor-scramble the bits and locally shuffle the order -- this preserves the PMJ
71 // properties but increases the number of apparently different sample sequences.
72 // The xor-scrambles and shuffles have been carefully generated to give
73 // visually pleasing blue noise noise patterns and also improve denoising.
74 //
75 
76 #define N_PMJ_SEQS (256*256) // number of different shuffles+scrambles of pmj sequences
77 #define N_PMJ_SAMPS 4096 // number of samples in the pmj sequence
78 
79 class ProgressiveSampler : public Generator
80 {
81 public:
82  void* pmjTables;
83 
84  ProgressiveSampler(void* tables) : pmjTables(tables) {}
85 
86 private:
87 
88  // Compute a repeatable random float in [0,1) based on value and scramble
89  PRMAN_INLINE static float
90  HashToRandom(const unsigned value, const unsigned scramble)
91  {
92  // clang-format off
93  unsigned result = value;
94  result ^= scramble;
95  result ^= result >> 17;
96  result ^= result >> 10; result *= 0xb36534e5;
97  result ^= result >> 12;
98  result ^= result >> 21; result *= 0x93fc4795;
99  result ^= 0xdf6e307f;
100  result ^= result >> 17; result *= 1 | scramble >> 18;
101  return static_cast<float>(result) / 4298115584.0f;
102  // clang-format on
103  }
104 
105  // Compute a repeatable random unsigned int based on value and scramble.
106  // Same as HashToRandom() but returns unsigned int instead of float.
107  // Has avalanche property: if a single input bit changes, an average
108  // of half the output bits change.
109  PRMAN_INLINE static unsigned int
110  HashToRandomUInt(unsigned int const value, unsigned int const scramble)
111  {
112  // clang-format off
113  unsigned int result = value;
114  result ^= scramble;
115  result ^= result >> 17;
116  result ^= result >> 10; result *= 0xb36534e5;
117  result ^= result >> 12;
118  result ^= result >> 21; result *= 0x93fc4795;
119  result ^= 0xdf6e307f;
120  result ^= result >> 17; result *= 1 | scramble >> 18;
121  return result;
122  // clang-format on
123  }
124 
125  // Shuffle the sample order to avoid correlation between samples when sequences are
126  // combined for high-dimensional sampling ("padding").
127  // Local shuffling does not affect the convergence properties of each sequence.
128  // This shuffling involves a fine balance: If the samples are not shuffled enough, then
129  // the correlation will persist; if the samples are shuffled too much then there is too
130  // much noise at samplecounts between powers of two (as in regression tests with e.g.
131  // 49 or 900 spp).
132  // Here the shuffle tables have been generated so that shuffling is within groups of
133  // at most 32, while only allowing swaps within each of the two A/B subclasses.
134  // Class order is: AABBAABBBBAABBAA ...
135  // (Alternatively, this shuffling could be done using Brent's hashed Owen-shuffling (as
136  // long as we keep track of the sample class the sample had before the shuffling); this
137  // might better preserve the lowest possible noise for in-between sample counts?)
138  PRMAN_INLINE unsigned int
139  shuffle(const unsigned int pattern,
140  const unsigned int sample) const
141  {
142  void** const tables = (void**)pmjTables;
143  unsigned short* shuffleTable = (unsigned short*)tables[2]; // extra shuffle table
144  unsigned int t1, t2, s;
145  const unsigned int nSamps = N_PMJ_SAMPS; // 4096
146 
147  // Optimization: first 4 samples are never shuffled, so don't bother looking up in shuffleTable
148  if (sample < 4) return sample;
149 
150  t1 = pattern & 0xff;
151  t2 = (pattern >> 8) & 0xff;
152  assert(sample < nSamps);
153  s = sample;
154 
155  // Do two shuffles by looking up in shuffle table twice -- this gives us a total of
156  // 256^2 = 64K different shuffles.
157  // (Ideas for future improvement:
158  // - The shuffle table could be smaller by storing signed char deltas between -31 and 31
159  // instead of unsigned shorts. This would require some signed-unsigned conversions here.
160  // - The table reads could be more coherent by storing all sample 0s first, then sample 1s,
161  // etc.)
162  s = shuffleTable[t1 * nSamps + s];
163  s = shuffleTable[t2 * nSamps + s];
164 
165  assert(s/32 == sample/32); // shuffles are local within groups of 32 samples
166  assert(s < nSamps);
167  return s;
168  }
169 
170  // Scramble bits of sample f with bits of 'scramble' and convert back to
171  // float. Both the input f and the result are floats between 0.0 and 1.0.
172  PRMAN_INLINE static float
173  fpScramble(float f, unsigned int scramble)
174  {
175  union
176  {
177  float f;
178  unsigned int i;
179  } f2i;
180  f2i.f = f + 1.0f; // map f to [1,2) so we know the exponent is 0
181  f2i.i ^= (scramble >> 9); // scramble the 23 fp mantissa bits
182  return f2i.f - 1.0f; // map result to [0,1)
183  }
184 
185  // Compute a progressive 1D PMJ (actually PJ) sample.
186  // Uses shifting of sequences and shuffling and scrambling of samples to generate more
187  // sequences out of the original pj sequence in the table, while at the same time
188  // preserving the tiled blue noise properties of the samples.
189  PRMAN_INLINE float progressive1DSample(
190  const unsigned int pattern,
191  const unsigned int sample) const
192  {
193  void** const tables = (void**)pmjTables;
194  float* sampleTable = (float*)tables[0]; // pmj02+pj table
195  unsigned int* shuffleScrambleTable = (unsigned int*)tables[1]; // shuffle+scramble table
196  float result;
197  unsigned int t, shift, s, ss;
198  unsigned int shuffleBitsZ, scrambleBitsZ;
199  const unsigned int nSeqs = N_PMJ_SEQS; // 256*256 = 65,536
200  const unsigned int nSamps = N_PMJ_SAMPS; // 4096
201 
202  if (sample > nSeqs * nSamps)
203  {
204  // Resort to (repeatable) random when running out of table entries
205  // after 256*256*4096 = 67,108,864 samples with same pattern id.
206  result = HashToRandom(sample, pattern * 0x51633e2d);
207  return result;
208  }
209 
210  // Select sequence (table) based on the pixel position encoded in the top 16 bits and
211  // a "random" shift that depends on the domain (and indirectly on the frame number, to
212  // avoid shower-door effect)
213  t = pattern >> 16; // for 256x256 tiles (8+8 bits for pixel pos leaves 16 bits)
214  assert(t < nSeqs);
215  shift = pattern & 0xffff; // shift sequence (table) to avoid shower-door effect
216  t += shift; // (% nSeqs is done below)
217 
218  // When we have "used up" all 4096 samples in a pixel's sequence we start over
219  // in another sequence 10 rows down, 19 columns over. (2579 is a prime.)
220  t += 2579 * (sample / nSamps);
221  t = t % nSeqs;
222  s = sample % nSamps;
223 
224  // Locally pre-shuffle the sample order by carefully swapping samples
225  // within groups of up to 32. Only samples of same class are swapped.
226  s = shuffle(pattern, s);
227 
228  // Lookup z shuffle and scramble bits from large table for tile
229  shuffleBitsZ = shuffleScrambleTable[5*t+3];
230  scrambleBitsZ = shuffleScrambleTable[5*t+4];
231 
232  // Shuffle the sample number
233  assert(shuffleBitsZ < 64); // we only shuffle z by at most 64 (to preserve 3D stratification)
234  ss = s ^ shuffleBitsZ; // xor the sample index
235  assert(ss < nSamps);
236 
237  // Lookup sample in pj table
238  result = sampleTable[3*ss+2]; // z dim: pj sequence with 1D tiled blue noise
239  assert(0.0f <= result && result < 1.0f);
240 
241  // Scramble sample value
242  result = fpScramble(result, scrambleBitsZ); // xor the sample value
243 
244  // Random (but consistent) flips
245  //if (pattern & 0x8000) result = 1.0f - result;
246 
247  // Ensure scrambled (and flipped?) value is strictly less than 1.0
248  result = std::min(result, 0.999990f);
249  assert(0.0f <= result && result < 1.0f);
250 
251  return result;
252  }
253 
254  // Compute a tiled 2D PMJ sample.
255  // Uses shifting of sequences and shuffling and scrambling of samples to generate more
256  // sequences out of the original pmj02 sequence in the table, while at the same time
257  // preserving the tiled blue noise properties of the samples.
258  // (This function is not suitable for photon emission, where the 64K sequences -- even
259  // with 8 "random" flips -- are not enough unique samples.)
260  PRMAN_INLINE RtFloat2 progressive2DSample(
261  const unsigned int pattern,
262  const unsigned int sample) const
263  {
264  void** const tables = (void**)pmjTables;
265  float* sampleTable = (float*)tables[0]; // pmj02+pj table
266  unsigned int* shuffleScrambleTable = (unsigned int*)tables[1]; // shuffle+scramble table
267  RtFloat2 result;
268  unsigned int t, shift, s, ss;
269  unsigned int shuffleBits, scrambleBitsX, scrambleBitsY;
270  const unsigned int nSeqs = N_PMJ_SEQS; // 256*256 = 65,536
271  const unsigned int nSamps = N_PMJ_SAMPS; // 4096
272 
273  if (sample > nSeqs * nSamps)
274  {
275  // Resort to (repeatable) random when running out of table entries
276  // after 256*256*4096 = 67,108,864 samples with same pattern id.
277  result.x = HashToRandom(sample, pattern * 0x51633e2d);
278  result.y = HashToRandom(sample, pattern * 0x68bc21eb);
279  return result;
280  }
281 
282  // Select sequence (table) based on the pixel position encoded in the top 16 bits and
283  // a "random" shift that depends on the domain (and indirectly on the frame number, to
284  // avoid shower-door effect)
285  t = pattern >> 16; // for 256x256 tiles (8+8 bits for pixel pos leaves 16 bits)
286  assert(t < nSeqs);
287  shift = pattern & 0xffff; // shift sequence to avoid shower-door effect
288  t += shift; // (% nSeqs is done below)
289 
290  // When we have "used up" all 4096 samples in a pixel's sequence we start over
291  // in another sequence 10 rows down, 19 columns over. (2579 is a prime.)
292  t += 2579 * (sample / nSamps);
293  t = t % nSeqs;
294  s = sample % nSamps;
295 
296  // Locally pre-shuffle the sample order by carefully swapping samples
297  // within groups of up to 32. Only samples of same class are swapped.
298  // Local shuffling does not affect the convergence properties of each
299  // sequence, but decorrelates 2D sequences so they can be safely combined
300  // to a higher-dimensional sample (aka. "padding"). Even two patterns
301  // that happen to map to the same sequence will be decorrelated when shuffled
302  // differently.
303  s = shuffle(pattern, s);
304 
305  // Lookup shuffle and scramble bits from large table for tile
306  shuffleBits = shuffleScrambleTable[5*t];
307  scrambleBitsX = shuffleScrambleTable[5*t+1];
308  scrambleBitsY = shuffleScrambleTable[5*t+2];
309 
310  // Shuffle the sample number
311  assert(shuffleBits < 256);
312  ss = s ^ shuffleBits; // xor the sample index
313  assert(ss < nSamps);
314 
315  // Lookup sample in pmj02 table
316  result.x = sampleTable[3*ss];
317  result.y = sampleTable[3*ss+1];
318  assert(0.0f <= result.x && result.x < 1.0f);
319  assert(0.0f <= result.y && result.y < 1.0f);
320 
321  // Scramble sample x and y values
322  result.x = fpScramble(result.x, scrambleBitsX); // xor the sample's x value
323  result.y = fpScramble(result.y, scrambleBitsY); // xor the sample's y value
324 
325  // Random (but consistent) flips -- these preserve tiled blue noise (but useless??)
326  // Using 0xX000 as scrables makes quality worse; using 0xX0000 does nothing to quality
327  //if (pattern & 0x80000) result.x = 1.0f - result.x;
328  //if (pattern & 0x40000) result.y = 1.0f - result.y;
329  //if (pattern & 0x20000) std::swap(result.x, result.y);
330 
331  // Ensure scrambled (and flipped?) values are strictly less than 1.0
332  result.x = std::min(result.x, 0.999990f);
333  result.y = std::min(result.y, 0.999990f);
334  assert(0.0f <= result.x && result.x < 1.0f);
335  assert(0.0f <= result.y && result.y < 1.0f);
336 
337  return result;
338  }
339 
340  // Compute a scrambled progressive 2D PMJ sample.
341  // Nearly identical to the function above, but this version does not only use the 16 top
342  // bits of pattern to select the table, and it has a last step that does
343  // bit-scrambling to generate *many* different sequences from the pmj02 table.
344  // This is equivalent to the old progressive2DSample() function from RenderMan 23 and older.
345  // This function is used for photon emission, where the original 256*256 sequences -- even
346  // with 8 "random" flips = 512K sequences -- do not provide enough unique samples.
347  PRMAN_INLINE RtFloat2 progressive2DScrambledSample(
348  const unsigned int pattern,
349  const unsigned int sample) const
350  {
351  void** const tables = (void**)pmjTables;
352  float* sampleTable = (float*)tables[0]; // pmj02+pj table
353  unsigned int* shuffleScrambleTable = (unsigned int*)tables[1]; // shuffle+scramble table
354  RtFloat2 result;
355  unsigned int t, s, ss;
356  unsigned int shuffleBits, pattern1, pattern2;
357  const unsigned int nSeqs = N_PMJ_SEQS; // 256*256 = 65,536
358  const unsigned int nSamps = N_PMJ_SAMPS; // 4096
359 
360  if (sample > nSeqs * nSamps)
361  {
362  // Resort to (repeatable) random when running out of table entries
363  // after 256*256*4096 = 67,108,864 samples with same pattern id.
364  result.x = HashToRandom(sample, pattern * 0x51633e2d);
365  result.y = HashToRandom(sample, pattern * 0x68bc21eb);
366  return result;
367  }
368 
369  // Select sequence (table)
370  t = pattern % nSeqs; // same as in RenderMan 23 and older
371  assert(t < nSeqs);
372 
373  // When we have "used up" all 4096 samples in a pixel's sequence we start over
374  // in another sequence 10 rows down, 19 columns over. (2579 is a prime.)
375  t += 2579 * (sample / nSamps);
376  t = t % nSeqs;
377  s = sample % nSamps;
378 
379  // Locally pre-shuffle the sample order by carefully swapping samples
380  // within groups of up to 32. Only samples of same class are swapped.
381  // Local shuffling does not affect the convergence properties of each
382  // sequence, but decorrelates 2D sequences so they can be safely combined
383  // to a higher-dimensional sample (aka. "padding"). Even two patterns
384  // that happen to map to the same sequence will be decorrelated when shuffled
385  // differently.
386  s = shuffle(pattern, s);
387 
388  // Lookup shuffle bits from large table for tile (ignore scramble bits in table)
389  shuffleBits = shuffleScrambleTable[5*t];
390 
391  // Shuffle the sample number
392  ss = s ^ shuffleBits; // xor the sample index
393  assert(ss < nSamps);
394 
395  // Lookup sample in pmj02 table
396  result.x = sampleTable[3*ss];
397  result.y = sampleTable[3*ss+1];
398  assert(0.0f <= result.x && result.x < 1.0f);
399  assert(0.0f <= result.y && result.y < 1.0f);
400 
401  // Xor-scramble bits of sample with bits of pattern, convert back to float
402  pattern1 = HashToRandomUInt(pattern, 0x51633e2d);
403  pattern2 = HashToRandomUInt(pattern, 0x68bc21eb);
404  result.x = fpScramble(result.x, pattern1); // xor the sample's x value
405  result.y = fpScramble(result.y, pattern2); // xor the sample's y value
406 
407  // Ensure (bit-scrambled) values are strictly less than 1.0
408  result.x = std::min(result.x, 0.999990f);
409  result.y = std::min(result.y, 0.999990f);
410  assert(0.0f <= result.x && result.x < 1.0f);
411  assert(0.0f <= result.y && result.y < 1.0f);
412 
413  return result;
414  }
415 
416  // Compute a progressive 3D PMJ sample.
417  // Uses shifting of sequences and shuffling and scrambling of samples to generate more
418  // sequences out of the original pmj02+pj 3D sequence in the table, while at the same time
419  // preserving the tiled blue noise properties of the samples.
420  PRMAN_INLINE RtFloat3 progressive3DSample(
421  const unsigned int pattern,
422  const unsigned int sample) const
423  {
424  void** const tables = (void**)pmjTables;
425  float* sampleTable = (float*)tables[0]; // pmj02+pj table
426  unsigned int* shuffleScrambleTable = (unsigned int*)tables[1]; // shuffle+scramble table
427  RtFloat3 result;
428  unsigned int t, shift, s, ss, sz;
429  unsigned int shuffleBits, scrambleBitsX, scrambleBitsY, shuffleBitsZ, scrambleBitsZ;
430  const unsigned int nSeqs = N_PMJ_SEQS; // 256*256 = 65,536
431  const unsigned int nSamps = N_PMJ_SAMPS; // 4096
432 
433  if (sample > nSeqs * nSamps)
434  {
435  // Resort to (repeatable) random when running out of table entries
436  // after 256*256*4096 = 67,108,864 samples with same pattern id.
437  result.x = HashToRandom(sample, pattern * 0x51633e2d);
438  result.y = HashToRandom(sample, pattern * 0x68bc21eb);
439  result.z = HashToRandom(sample, pattern * 0x02e5be93);
440  return result;
441  }
442 
443  // Select sequence (table) based on the pixel position encoded in the top 16 bits and
444  // a "random" shift that depends on the domain (and indirectly on the frame number, to
445  // avoid shower-door effect)
446  t = pattern >> 16; // for 256x256 tiles (8+8 bits for pixel pos)
447  assert(t < nSeqs);
448  shift = pattern & 0xffff; // shift sequence (table) to avoid shower-door effect
449  t += shift; // (% nSeqs is done below)
450 
451  // When we have "used up" all 4096 samples in a pixel's sequence we start over
452  // in another sequence 10 rows down, 19 columns over. (2579 is a prime.)
453  t += 2579 * (sample / nSamps);
454  t = t % nSeqs;
455  s = sample % nSamps;
456 
457  // Locally pre-shuffle the sample order by carefully swapping samples
458  // within groups of up to 32. Only samples of same class are swapped.
459  s = shuffle(pattern, s);
460 
461  // Lookup shuffle and scramble bits from large table for tile
462  shuffleBits = shuffleScrambleTable[5*t];
463  scrambleBitsX = shuffleScrambleTable[5*t+1];
464  scrambleBitsY = shuffleScrambleTable[5*t+2];
465  shuffleBitsZ = shuffleScrambleTable[5*t+3];
466  scrambleBitsZ = shuffleScrambleTable[5*t+4];
467 
468  // Shuffle the sample number (z has different shuffle than x and y)
469  ss = s ^ shuffleBits; // xor the xy sample index
470  assert(ss < nSamps);
471  sz = s ^ shuffleBitsZ; // xor the z sample index
472  assert(sz < nSamps);
473 
474  // Lookup sample in pmj02+pj 3D table
475  result.x = sampleTable[3*ss]; // progressive multijittered (0,2) samples + z strafied in 3D
476  result.y = sampleTable[3*ss+1];
477  result.z = sampleTable[3*sz+2];
478  assert(0.0f <= result.x && result.x < 1.0f);
479  assert(0.0f <= result.y && result.y < 1.0f);
480  assert(0.0f <= result.z && result.z < 1.0f);
481 
482  // Scramble sample x, y, and z values
483  result.x = fpScramble(result.x, scrambleBitsX); // xor the sample's x value
484  result.y = fpScramble(result.y, scrambleBitsY); // xor the sample's y value
485  result.z = fpScramble(result.z, scrambleBitsZ); // xor the sample's z value
486 
487  // Random (but consistent) flips. (Could also swap xy xz yz.)
488  //if (pattern & 0x80000) result.x = 1.0f - result.x;
489  //if (pattern & 0x40000) result.y = 1.0f - result.y;
490  //if (pattern & 0x20000) result.z = 1.0f - result.z;
491 
492  // Ensure scramble (and flipped?) values are strictly less than 1.0
493  result.x = std::min(result.x, 0.999990f);
494  result.y = std::min(result.y, 0.999990f);
495  result.z = std::min(result.z, 0.999990f);
496  assert(0.0f <= result.x && result.x < 1.0f);
497  assert(0.0f <= result.y && result.y < 1.0f);
498  assert(0.0f <= result.z && result.z < 1.0f);
499 
500  return result;
501  }
502 
503 public:
504 
505  // Functions to draw a single PMJ sample from a sequence.
506  // The 'i' parameter (shading context index) is part of the Generator class
507  // interface, but ignored for PMJ samples.
508 
509  virtual float Sample1D(const SampleCtx& rctx, unsigned i) const
510  {
511  PIXAR_ARGUSED(i);
512  return progressive1DSample(rctx.patternid, rctx.sampleid);
513  }
514 
515  virtual RtFloat2 Sample2D(const SampleCtx& rctx, unsigned i) const
516  {
517  PIXAR_ARGUSED(i);
518  return progressive2DSample(rctx.patternid, rctx.sampleid);
519  }
520 
521  virtual RtFloat2 ScrambledSample2D(const SampleCtx& rctx, unsigned i) const
522  {
523  PIXAR_ARGUSED(i);
524  return progressive2DScrambledSample(rctx.patternid, rctx.sampleid);
525  }
526 
527  virtual RtFloat3 Sample3D(const SampleCtx& rctx, unsigned i) const
528  {
529  PIXAR_ARGUSED(i);
530  return progressive3DSample(rctx.patternid, rctx.sampleid);
531  }
532 
533  // Generator functions to draw multiple samples, each from a different sequence.
534  // (These functions are candidates for future simd implementation.)
535 
536  virtual void MultiSample1D(
537  unsigned int n,
538  const SampleCtx* rctx,
539  float* xis) const
540  {
541  for (unsigned int i = 0; i < n; ++i)
542  {
543  xis[i] = progressive1DSample(rctx[i].patternid, rctx[i].sampleid);
544  }
545  }
546 
547  virtual void MultiSample2D(
548  unsigned int n,
549  const SampleCtx* rctx,
550  RtFloat2* xis) const
551  {
552  for (unsigned int i = 0; i < n; ++i)
553  {
554  xis[i] = progressive2DSample(rctx[i].patternid, rctx[i].sampleid);
555  }
556  }
557 
559  unsigned int n,
560  const SampleCtx* rctx,
561  RtFloat2* xis) const
562  {
563  for (unsigned int i = 0; i < n; ++i)
564  {
565  xis[i] = progressive2DScrambledSample(rctx[i].patternid, rctx[i].sampleid);
566  }
567  }
568 
569  virtual void MultiSample3D(
570  unsigned int n,
571  const SampleCtx* rctx,
572  RtFloat3* xis) const
573  {
574  for (unsigned int i = 0; i < n; ++i)
575  {
576  xis[i] = progressive3DSample(rctx[i].patternid, rctx[i].sampleid);
577  }
578  }
579 };
580 
581 #endif
#define N_PMJ_SEQS
Definition: RixRNGProgressive.h:76
float x
Definition: RiTypesHelper.h:86
void * pmjTables
Definition: RixRNGProgressive.h:82
virtual void MultiSample2D(unsigned int n, const SampleCtx *rctx, RtFloat2 *xis) const
Definition: RixRNGProgressive.h:547
virtual RtFloat2 ScrambledSample2D(const SampleCtx &rctx, unsigned i) const
Definition: RixRNGProgressive.h:521
Definition: RiTypesHelper.h:82
virtual RtFloat3 Sample3D(const SampleCtx &rctx, unsigned i) const
Definition: RixRNGProgressive.h:527
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:69
Definition: RixRNGProgressive.h:79
virtual void MultiScrambledSample2D(unsigned int n, const SampleCtx *rctx, RtFloat2 *xis) const
Definition: RixRNGProgressive.h:558
virtual float Sample1D(const SampleCtx &rctx, unsigned i) const
Definition: RixRNGProgressive.h:509
virtual void MultiSample1D(unsigned int n, const SampleCtx *rctx, float *xis) const
Definition: RixRNGProgressive.h:536
ProgressiveSampler(void *tables)
Definition: RixRNGProgressive.h:84
#define PRMAN_INLINE
Definition: prmanapi.h:99
float y
Definition: RiTypesHelper.h:86
virtual RtFloat2 Sample2D(const SampleCtx &rctx, unsigned i) const
Definition: RixRNGProgressive.h:515
#define N_PMJ_SAMPS
Definition: RixRNGProgressive.h:77
virtual void MultiSample3D(unsigned int n, const SampleCtx *rctx, RtFloat3 *xis) const
Definition: RixRNGProgressive.h:569
#define PIXAR_ARGUSED(x)
Definition: prmanapi.h:170