Blender  V3.3
lcg.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Linear Congruential Generator */
9 
10 /* This is templated to handle multiple address spaces on Metal. */
11 template<class T> ccl_device uint lcg_step_uint(T rng)
12 {
13  /* implicit mod 2^32 */
14  *rng = (1103515245 * (*rng) + 12345);
15  return *rng;
16 }
17 
18 /* This is templated to handle multiple address spaces on Metal. */
19 template<class T> ccl_device float lcg_step_float(T rng)
20 {
21  /* implicit mod 2^32 */
22  *rng = (1103515245 * (*rng) + 12345);
23  return (float)*rng * (1.0f / (float)0xFFFFFFFF);
24 }
25 
27 {
28  uint rng = seed;
29  lcg_step_uint(&rng);
30  return rng;
31 }
32 
34  const uint rng_offset,
35  const uint sample,
36  const uint scramble)
37 {
38  return lcg_init(rng_hash + rng_offset + sample * scramble);
39 }
40 
typedef float(TangentPoint)[2]
unsigned int uint
Definition: BLI_sys_types.h:67
static unsigned long seed
Definition: btSoftBody.h:39
#define ccl_device
Definition: cuda/compat.h:32
#define ccl_device_inline
Definition: cuda/compat.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_BEGIN ccl_device uint lcg_step_uint(T rng)
Definition: lcg.h:11
ccl_device uint lcg_init(uint seed)
Definition: lcg.h:26
ccl_device_inline uint lcg_state_init(const uint rng_hash, const uint rng_offset, const uint sample, const uint scramble)
Definition: lcg.h:33
ccl_device float lcg_step_float(T rng)
Definition: lcg.h:19
#define T