Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_random.h
| Context not available. | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #pragma once | #pragma once | ||||
| #include "kernel/kernel_jitter.h" | #include "kernel/kernel_jitter.h" | ||||
| Context not available. | |||||
| uint i = index + SOBOL_SKIP; | uint i = index + SOBOL_SKIP; | ||||
| for (int j = 0, x; (x = find_first_set(i)); i >>= x) { | for (int j = 0, x; (x = find_first_set(i)); i >>= x) { | ||||
| j += x; | j += x; | ||||
| result ^= __float_as_uint(kernel_tex_fetch(__sample_pattern_lut, 32 * dimension + j - 1)); | result ^= kernel_tex_fetch(__sample_pattern_lut, 32 * dimension + j - 1); | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| Context not available. | |||||
| ccl_device_forceinline void path_rng_2D( | ccl_device_forceinline void path_rng_2D( | ||||
| const KernelGlobals *kg, uint rng_hash, int sample, int dimension, float *fx, float *fy) | const KernelGlobals *kg, uint rng_hash, int sample, int dimension, float *fx, float *fy) | ||||
| { | { | ||||
| #ifdef __DEBUG_CORRELATION__ | |||||
| *fx = (float)drand48(); | |||||
| *fy = (float)drand48(); | |||||
| return; | |||||
| #endif | |||||
| #ifdef __SOBOL__ | |||||
| if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_PMJ) | |||||
| #endif | |||||
| { | |||||
| pmj_sample_2D(kg, sample, rng_hash, dimension, fx, fy); | |||||
| return; | |||||
| } | |||||
| #ifdef __SOBOL__ | |||||
| /* Sobol. */ | |||||
| *fx = path_rng_1D(kg, rng_hash, sample, dimension); | *fx = path_rng_1D(kg, rng_hash, sample, dimension); | ||||
| *fy = path_rng_1D(kg, rng_hash, sample, dimension + 1); | *fy = path_rng_1D(kg, rng_hash, sample, dimension + 1); | ||||
| #endif | |||||
| } | |||||
| /** | |||||
| * 1D hash recomended from "Hash Functions for GPU Rendering" JCGT Vol. 9, No. 3, 2020 | |||||
| * See https://www.shadertoy.com/view/4tXyWN and https://www.shadertoy.com/view/XlGcRh | |||||
| * http://www.jcgt.org/published/0009/03/02/paper.pdf | |||||
| */ | |||||
| ccl_device_inline uint hash_iqint1(uint n) | |||||
| { | |||||
| n = (n << 13U) ^ n; | |||||
| n = n * (n * n * 15731U + 789221U) + 1376312589U; | |||||
| return n; | |||||
| } | |||||
| /** | |||||
| * 2D hash recomended from "Hash Functions for GPU Rendering" JCGT Vol. 9, No. 3, 2020 | |||||
| * See https://www.shadertoy.com/view/4tXyWN and https://www.shadertoy.com/view/XlGcRh | |||||
| * http://www.jcgt.org/published/0009/03/02/paper.pdf | |||||
| */ | |||||
| ccl_device_inline uint hash_iqnt2d(const uint x, const uint y) | |||||
| { | |||||
| const uint qx = 1103515245U * ((x >> 1U) ^ (y)); | |||||
| const uint qy = 1103515245U * ((y >> 1U) ^ (x)); | |||||
| const uint n = 1103515245U * ((qx) ^ (qy >> 3U)); | |||||
| return n; | |||||
| } | } | ||||
| ccl_device_inline uint path_rng_hash_init(const KernelGlobals *ccl_restrict kg, | ccl_device_inline uint path_rng_hash_init(const KernelGlobals *ccl_restrict kg, | ||||
| Context not available. | |||||
| const int x, | const int x, | ||||
| const int y) | const int y) | ||||
| { | { | ||||
| const uint rng_hash = hash_iqnt2d(x, y) ^ kernel_data.integrator.seed; | const uint rng_hash = hash_uint2(x, y) ^ kernel_data.integrator.seed; | ||||
| #ifdef __DEBUG_CORRELATION__ | #ifdef __DEBUG_CORRELATION__ | ||||
| srand48(rng_hash + sample); | srand48(rng_hash + sample); | ||||
| Context not available. | |||||