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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2014-01-03 05:48:48 +0400
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2014-01-03 21:57:38 +0400
commitbb0a0315e28216e64190b3c6e5657438a28ad56d (patch)
tree02da099e09c58b6b3f8de559d9abe819fb3b9af3 /intern/cycles/kernel/kernel_random.h
parent57407d39b0230a1f1a137beaedb7a4771d8b8272 (diff)
Code refactor: move random number and MIS variables into PathState.
This makes it easier to pass this state around, and wraps some common RNG dimension computations in utility functions.
Diffstat (limited to 'intern/cycles/kernel/kernel_random.h')
-rw-r--r--intern/cycles/kernel/kernel_random.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h
index c435c27b7b4..e3b1c1d7822 100644
--- a/intern/cycles/kernel/kernel_random.h
+++ b/intern/cycles/kernel/kernel_random.h
@@ -227,6 +227,8 @@ ccl_device void path_rng_end(KernelGlobals *kg, ccl_global uint *rng_state, RNG
#endif
+/* Linear Congruential Generator */
+
ccl_device uint lcg_step_uint(uint *rng)
{
/* implicit mod 2^32 */
@@ -248,5 +250,47 @@ ccl_device uint lcg_init(uint seed)
return rng;
}
+/* Path Tracing Utility Functions
+ *
+ * For each random number in each step of the path we must have a unique
+ * dimension to avoid using the same sequence twice.
+ *
+ * For branches in the path we must be careful not to reuse the same number
+ * in a sequence and offset accordingly. */
+
+ccl_device_inline float path_state_rng_1D(KernelGlobals *kg, RNG *rng, PathState *state, int dimension)
+{
+ return path_rng_1D(kg, rng, state->sample, state->num_samples, state->rng_offset + dimension);
+}
+
+ccl_device_inline void path_state_rng_2D(KernelGlobals *kg, RNG *rng, PathState *state, int dimension, float *fx, float *fy)
+{
+ path_rng_2D(kg, rng, state->sample, state->num_samples, state->rng_offset + dimension, fx, fy);
+}
+
+ccl_device_inline float path_branched_rng_1D(KernelGlobals *kg, RNG *rng, PathState *state, int branch, int num_branches, int dimension)
+{
+ return path_rng_1D(kg, rng, state->sample*num_branches + branch, state->num_samples*num_branches, state->rng_offset + dimension);
+}
+
+ccl_device_inline void path_branched_rng_2D(KernelGlobals *kg, RNG *rng, PathState *state, int branch, int num_branches, int dimension, float *fx, float *fy)
+{
+ path_rng_2D(kg, rng, state->sample*num_branches + branch, state->num_samples*num_branches, state->rng_offset + dimension, fx, fy);
+}
+
+ccl_device_inline void path_state_branch(PathState *state, int branch, int num_branches)
+{
+ /* path is splitting into a branch, adjust so that each branch
+ * still gets a unique sample from the same sequence */
+ state->rng_offset += PRNG_BOUNCE_NUM;
+ state->sample = state->sample*num_branches + branch;
+ state->num_samples = state->num_samples*num_branches;
+}
+
+ccl_device inline uint lcg_state_init(RNG *rng, PathState *state, uint scramble)
+{
+ return lcg_init(*rng + state->rng_offset + state->sample*scramble);
+}
+
CCL_NAMESPACE_END