Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_jitter.h
| Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| ccl_device_inline float cmj_randfloat_simple(uint i, uint p) | ccl_device_inline float cmj_randfloat_simple(uint i, uint p) | ||||
| { | { | ||||
| return cmj_hash_simple(i, p) * (1.0f / (float)0xFFFFFFFF); | return cmj_hash_simple(i, p) * (1.0f / (float)0xFFFFFFFF); | ||||
| } | } | ||||
| ccl_device float pmj_sample_1D(const KernelGlobals *kg, uint sample, uint rng_hash, uint dimension) | ccl_device float pmj_sample_1D(const KernelGlobals *kg, uint sample, uint rng_hash, uint dimension) | ||||
| { | { | ||||
| /* The PMJ sample sets contain a sample with (x,y) with NUM_PMJ_SAMPLES so for 1D | |||||
| * the x part is used as the sample (TODO(@leesonw): Add using both x and y parts | |||||
| * independently). */ | |||||
| /* Perform Owen shuffle of the sample number to reorder the samples. */ | /* Perform Owen shuffle of the sample number to reorder the samples. */ | ||||
| #ifdef _SIMPLE_HASH_ | #ifdef _SIMPLE_HASH_ | ||||
| const uint rv = cmj_hash_simple(dimension, rng_hash); | const uint rv = cmj_hash_simple(dimension, rng_hash); | ||||
| #else /* Use a _REGULAR_HASH_. */ | #else /* Use a _REGULAR_HASH_. */ | ||||
| const uint rv = cmj_hash(dimension, rng_hash); | const uint rv = cmj_hash(dimension, rng_hash); | ||||
| #endif | #endif | ||||
| #ifdef _XOR_SHUFFLE_ | #ifdef _XOR_SHUFFLE_ | ||||
| # warning "Using XOR shuffle." | # warning "Using XOR shuffle." | ||||
| const uint s = sample ^ rv; | const uint s = sample ^ rv; | ||||
| #else /* Use _OWEN_SHUFFLE_ for reordering. */ | #else /* Use _OWEN_SHUFFLE_ for reordering. */ | ||||
| const uint s = nested_uniform_scramble(sample, rv); | const uint s = nested_uniform_scramble(sample, rv); | ||||
| #endif | #endif | ||||
| /* Based on the sample number a sample pattern is selected and offset by the dimension. */ | /* 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 sample_set = s / NUM_PMJ_SAMPLES; | ||||
| const uint d = (dimension + sample_set); | const uint d = (dimension + sample_set); | ||||
| const uint dim = d % NUM_PMJ_PATTERNS; | const uint dim = d % NUM_PMJ_PATTERNS; | ||||
| int index = 2 * (dim * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)); | |||||
| /* The PMJ sample sets contain a sample with (x,y) with NUM_PMJ_SAMPLES so for 1D | |||||
| * the x part is used for even dims and the y for odd. */ | |||||
| int index = 2 * ((dim >> 1) * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)) + (dim & 1); | |||||
| float fx = kernel_tex_fetch(__sample_pattern_lut, index); | float fx = kernel_tex_fetch(__sample_pattern_lut, index); | ||||
| #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ | #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ | ||||
| /* Use Cranley-Patterson rotation to displace the sample pattern. */ | /* Use Cranley-Patterson rotation to displace the sample pattern. */ | ||||
| # ifdef _SIMPLE_HASH_ | # ifdef _SIMPLE_HASH_ | ||||
| float dx = cmj_randfloat_simple(d, rng_hash); | float dx = cmj_randfloat_simple(d, rng_hash); | ||||
| # else | # else | ||||
| /* Only jitter within the grid interval. */ | |||||
| float dx = cmj_randfloat(d, rng_hash); | float dx = cmj_randfloat(d, rng_hash); | ||||
| # endif | # endif | ||||
| fx = fx + dx * (1.0f / NUM_PMJ_SAMPLES); | /* Jitter sample locations and map back to the unit square. */ | ||||
| fx = fx + dx; | |||||
| fx = fx - floorf(fx); | fx = fx - floorf(fx); | ||||
| #else | #else | ||||
| # warning "Not using Cranley-Patterson Rotation." | # warning "Not using Cranley-Patterson Rotation." | ||||
| #endif | #endif | ||||
| return fx; | return fx; | ||||
| } | } | ||||
| ccl_device void pmj_sample_2D( | ccl_device void pmj_sample_2D( | ||||
| Show All 10 Lines | # warning "Using XOR shuffle." | ||||
| const uint s = sample ^ rv; | const uint s = sample ^ rv; | ||||
| #else /* Use _OWEN_SHUFFLE_ for reordering. */ | #else /* Use _OWEN_SHUFFLE_ for reordering. */ | ||||
| const uint s = nested_uniform_scramble(sample, rv); | const uint s = nested_uniform_scramble(sample, rv); | ||||
| #endif | #endif | ||||
| /* Based on the sample number a sample pattern is selected and offset by the dimension. */ | /* 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 sample_set = s / NUM_PMJ_SAMPLES; | ||||
| const uint d = (dimension + sample_set); | const uint d = (dimension + sample_set); | ||||
| const uint dim = d % NUM_PMJ_PATTERNS; | uint dim = d % NUM_PMJ_PATTERNS; | ||||
| int index = 2 * (dim * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)); | int index = 2 * ((dim >> 1) * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)); | ||||
| float fx = kernel_tex_fetch(__sample_pattern_lut, index); | float fx = kernel_tex_fetch(__sample_pattern_lut, index); | ||||
| float fy = kernel_tex_fetch(__sample_pattern_lut, index + 1); | float fy = kernel_tex_fetch(__sample_pattern_lut, index + 1); | ||||
| #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ | #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ | ||||
| /* Use Cranley-Patterson rotation to displace the sample pattern. */ | /* Use Cranley-Patterson rotation to displace the sample pattern. */ | ||||
| # ifdef _SIMPLE_HASH_ | # ifdef _SIMPLE_HASH_ | ||||
| float dx = cmj_randfloat_simple(d, rng_hash); | float dx = cmj_randfloat_simple(d, rng_hash); | ||||
| float dy = cmj_randfloat_simple(d + 1, rng_hash); | float dy = cmj_randfloat_simple(d + 1, rng_hash); | ||||
| # else | # else | ||||
| float dx = cmj_randfloat(d, rng_hash); | float dx = cmj_randfloat(d, rng_hash); | ||||
| float dy = cmj_randfloat(d + 1, rng_hash); | float dy = cmj_randfloat(d + 1, rng_hash); | ||||
| # endif | # endif | ||||
| /* Only jitter within the grid cells. */ | /* Jitter sample locations and map back to the unit square. Also | ||||
| fx = fx + dx * (1.0f / NUM_PMJ_DIVISIONS); | swaps x and y on odd dimensions. */ | ||||
| fy = fy + dy * (1.0f / NUM_PMJ_DIVISIONS); | dim = dim & 0x1; | ||||
| fx = fx - floorf(fx); | float sx = ((dim == 0) ? fx : fy) + dx; | ||||
| fy = fy - floorf(fy); | float sy = ((dim == 0) ? fy : fx) + dy; | ||||
brecht: It's unclear to me what this swapping accomplishes. Does it result in some visible difference… | |||||
leesonwAuthorUnsubmitted Done Inline ActionsI have removed this for now as it is not necessary to fix this. leesonw: I have removed this for now as it is not necessary to fix this. | |||||
| sx = sx - floorf(sx); | |||||
| sy = sy - floorf(sy); | |||||
| #else | #else | ||||
| # warning "Not using Cranley Patterson Rotation." | # warning "Not using Cranley Patterson Rotation." | ||||
| #endif | #endif | ||||
| (*x) = fx; | (*x) = sx; | ||||
| (*y) = fy; | (*y) = sy; | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
It's unclear to me what this swapping accomplishes. Does it result in some visible difference in renders?
PathTraceDimension has all the 2D sample patterns on even dimensions, as far as I can tell this would have no effect then.