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