diff options
author | Stefan Werner <stefan.werner@tangent-animation.com> | 2020-03-02 17:12:44 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-02 18:35:52 +0300 |
commit | 409074aae56138f49ce078ce919a6d02e44e521e (patch) | |
tree | 3c2e57fc9ff715c297c21bd3c888cc4ffc1b2848 /intern/cycles/kernel/kernel_jitter.h | |
parent | 7b8db971d42f6d6b7b1c74959758266ce8c859e0 (diff) |
Cycles: add Progressive Multi-Jitter sampling pattern
This sampling pattern is particularly suited to adaptive sampling, and will
be used for that upcoming feature.
Based on "Progressive Multi-Jittered Sample Sequences" by Per Christensen,
Andrew Kensler and Charlie Kilpatrick.
Ref D4686
Diffstat (limited to 'intern/cycles/kernel/kernel_jitter.h')
-rw-r--r-- | intern/cycles/kernel/kernel_jitter.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/intern/cycles/kernel/kernel_jitter.h b/intern/cycles/kernel/kernel_jitter.h index e59d8946950..b733bb9fee2 100644 --- a/intern/cycles/kernel/kernel_jitter.h +++ b/intern/cycles/kernel/kernel_jitter.h @@ -195,4 +195,35 @@ ccl_device void cmj_sample_2D(int s, int N, int p, float *fx, float *fy) } #endif +ccl_device float pmj_sample_1D(KernelGlobals *kg, int sample, int rng_hash, int dimension) +{ + /* Fallback to random */ + if (sample > NUM_PMJ_SAMPLES) { + int p = rng_hash + dimension; + return cmj_randfloat(sample, p); + } + uint tmp_rng = cmj_hash_simple(dimension, rng_hash); + int index = ((dimension % NUM_PMJ_PATTERNS) * NUM_PMJ_SAMPLES + sample) * 2; + return __uint_as_float(kernel_tex_fetch(__sample_pattern_lut, index) ^ (tmp_rng & 0x007fffff)) - + 1.0f; +} + +ccl_device void pmj_sample_2D( + KernelGlobals *kg, int sample, int rng_hash, int dimension, float *fx, float *fy) +{ + if (sample > NUM_PMJ_SAMPLES) { + int p = rng_hash + dimension; + *fx = cmj_randfloat(sample, p); + *fy = cmj_randfloat(sample, p + 1); + } + uint tmp_rng = cmj_hash_simple(dimension, rng_hash); + int index = ((dimension % NUM_PMJ_PATTERNS) * NUM_PMJ_SAMPLES + sample) * 2; + *fx = __uint_as_float(kernel_tex_fetch(__sample_pattern_lut, index) ^ (tmp_rng & 0x007fffff)) - + 1.0f; + tmp_rng = cmj_hash_simple(dimension + 1, rng_hash); + *fy = __uint_as_float(kernel_tex_fetch(__sample_pattern_lut, index + 1) ^ + (tmp_rng & 0x007fffff)) - + 1.0f; +} + CCL_NAMESPACE_END |