Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Leeson <leesonw>2021-10-27 15:14:43 +0300
committerWilliam Leeson <william@blender.org>2021-10-27 15:21:15 +0300
commit82cf25dfbfad39a64b620c20bbd0d65915827a44 (patch)
tree33b2a3fe33da968cbc8a8172637177785c736fdc /intern/cycles/kernel/sample
parent7b1c5712f888ea37bbccafd9ffd7a3a6a61e665f (diff)
Cycles: Scrambling distance for the PMJ sampler
Adds scrambling distance to the PMJ sampler. This is based on the work by Mathieu Menuet in D12318 who created the original implementation for the Sobol sampler. Reviewed By: brecht Maniphest Tasks: T92181 Differential Revision: https://developer.blender.org/D12854
Diffstat (limited to 'intern/cycles/kernel/sample')
-rw-r--r--intern/cycles/kernel/sample/jitter.h54
1 files changed, 40 insertions, 14 deletions
diff --git a/intern/cycles/kernel/sample/jitter.h b/intern/cycles/kernel/sample/jitter.h
index b62ec7fda42..b76b9b8f23e 100644
--- a/intern/cycles/kernel/sample/jitter.h
+++ b/intern/cycles/kernel/sample/jitter.h
@@ -72,13 +72,27 @@ ccl_device_inline float cmj_randfloat_simple(uint i, uint p)
return cmj_hash_simple(i, p) * (1.0f / (float)0xFFFFFFFF);
}
+ccl_device_inline float cmj_randfloat_simple_dist(uint i, uint p, float d)
+{
+ return cmj_hash_simple(i, p) * (d / (float)0xFFFFFFFF);
+}
+
ccl_device float pmj_sample_1D(KernelGlobals kg, uint sample, uint rng_hash, uint dimension)
{
+ uint hash = rng_hash;
+ float jitter_x = 0.0f;
+ if (kernel_data.integrator.scrambling_distance < 1.0f) {
+ hash = kernel_data.integrator.seed;
+
+ jitter_x = cmj_randfloat_simple_dist(
+ dimension, rng_hash, kernel_data.integrator.scrambling_distance);
+ }
+
/* Perform Owen shuffle of the sample number to reorder the samples. */
#ifdef _SIMPLE_HASH_
- const uint rv = cmj_hash_simple(dimension, rng_hash);
+ const uint rv = cmj_hash_simple(dimension, hash);
#else /* Use a _REGULAR_HASH_. */
- const uint rv = cmj_hash(dimension, rng_hash);
+ const uint rv = cmj_hash(dimension, hash);
#endif
#ifdef _XOR_SHUFFLE_
# warning "Using XOR shuffle."
@@ -101,12 +115,12 @@ ccl_device float pmj_sample_1D(KernelGlobals kg, uint sample, uint rng_hash, uin
#ifndef _NO_CRANLEY_PATTERSON_ROTATION_
/* Use Cranley-Patterson rotation to displace the sample pattern. */
# ifdef _SIMPLE_HASH_
- float dx = cmj_randfloat_simple(d, rng_hash);
+ float dx = cmj_randfloat_simple(d, hash);
# else
- float dx = cmj_randfloat(d, rng_hash);
+ float dx = cmj_randfloat(d, hash);
# endif
/* Jitter sample locations and map back into [0 1]. */
- fx = fx + dx;
+ fx = fx + dx + jitter_x;
fx = fx - floorf(fx);
#else
# warning "Not using Cranley-Patterson Rotation."
@@ -122,11 +136,23 @@ ccl_device void pmj_sample_2D(KernelGlobals kg,
ccl_private float *x,
ccl_private float *y)
{
+ uint hash = rng_hash;
+ float jitter_x = 0.0f;
+ float jitter_y = 0.0f;
+ if (kernel_data.integrator.scrambling_distance < 1.0f) {
+ hash = kernel_data.integrator.seed;
+
+ jitter_x = cmj_randfloat_simple_dist(
+ dimension, rng_hash, kernel_data.integrator.scrambling_distance);
+ jitter_y = cmj_randfloat_simple_dist(
+ dimension + 1, rng_hash, kernel_data.integrator.scrambling_distance);
+ }
+
/* Perform a shuffle on the sample number to reorder the samples. */
#ifdef _SIMPLE_HASH_
- const uint rv = cmj_hash_simple(dimension, rng_hash);
+ const uint rv = cmj_hash_simple(dimension, hash);
#else /* Use a _REGULAR_HASH_. */
- const uint rv = cmj_hash(dimension, rng_hash);
+ const uint rv = cmj_hash(dimension, hash);
#endif
#ifdef _XOR_SHUFFLE_
# warning "Using XOR shuffle."
@@ -137,7 +163,7 @@ ccl_device void pmj_sample_2D(KernelGlobals kg,
/* Based on the sample number a sample pattern is selected and offset by the dimension. */
const uint sample_set = s / NUM_PMJ_SAMPLES;
- const uint d = (dimension + sample_set);
+ const uint d = dimension + sample_set;
uint dim = d % NUM_PMJ_PATTERNS;
int index = 2 * (dim * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES));
@@ -147,15 +173,15 @@ ccl_device void pmj_sample_2D(KernelGlobals kg,
#ifndef _NO_CRANLEY_PATTERSON_ROTATION_
/* Use Cranley-Patterson rotation to displace the sample pattern. */
# ifdef _SIMPLE_HASH_
- float dx = cmj_randfloat_simple(d, rng_hash);
- float dy = cmj_randfloat_simple(d + 1, rng_hash);
+ float dx = cmj_randfloat_simple(d, hash);
+ float dy = cmj_randfloat_simple(d + 1, hash);
# else
- float dx = cmj_randfloat(d, rng_hash);
- float dy = cmj_randfloat(d + 1, rng_hash);
+ float dx = cmj_randfloat(d, hash);
+ float dy = cmj_randfloat(d + 1, hash);
# endif
/* Jitter sample locations and map back to the unit square [0 1]x[0 1]. */
- float sx = fx + dx;
- float sy = fy + dy;
+ float sx = fx + dx + jitter_x;
+ float sy = fy + dy + jitter_y;
sx = sx - floorf(sx);
sy = sy - floorf(sy);
#else