Blender
V5.0
intern
cycles
kernel
sample
cycles/kernel/sample/util.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/math.h
"
8
#include "
util/types.h
"
9
10
CCL_NAMESPACE_BEGIN
11
12
/*
13
* Performs base-2 Owen scrambling on a reversed-bit unsigned integer.
14
*
15
* This is equivalent to the Laine-Karras permutation, but much higher
16
* quality. See https://psychopath.io/post/2021_01_30_building_a_better_lk_hash
17
*/
18
ccl_device_inline
uint
reversed_bit_owen
(
uint
n,
const
uint
seed
)
19
{
20
n ^= n * 0x3d20adea;
21
n +=
seed
;
22
n *= (
seed
>> 16) | 1;
23
n ^= n * 0x05526c56;
24
n ^= n * 0x53a22864;
25
26
return
n;
27
}
28
29
/*
30
* Performs base-4 Owen scrambling on a reversed-bit unsigned integer.
31
*
32
* See https://psychopath.io/post/2022_08_14_a_fast_hash_for_base_4_owen_scrambling
33
*/
34
35
ccl_device_inline
uint
reversed_bit_owen_base4
(
uint
n,
const
uint
seed
)
36
{
37
n ^= n * 0x3d20adea;
38
n ^= (n >> 1) & (n << 1) & 0x55555555;
39
n +=
seed
;
40
n *= (
seed
>> 16) | 1;
41
n ^= (n >> 1) & (n << 1) & 0x55555555;
42
n ^= n * 0x05526c56;
43
n ^= n * 0x53a22864;
44
45
return
n;
46
}
47
48
/*
49
* Performs base-2 Owen scrambling on an unsigned integer.
50
*/
51
ccl_device_inline
uint
nested_uniform_scramble
(
const
uint
i
,
const
uint
seed
)
52
{
53
return
reverse_integer_bits
(
reversed_bit_owen
(
reverse_integer_bits
(
i
),
seed
));
54
}
55
56
/*
57
* Performs base-4 Owen scrambling on an unsigned integer.
58
*/
59
ccl_device_inline
uint
nested_uniform_scramble_base4
(
const
uint
i
,
const
uint
seed
)
60
{
61
return
reverse_integer_bits
(
reversed_bit_owen_base4
(
reverse_integer_bits
(
i
),
seed
));
62
}
63
64
ccl_device_inline
uint
expand_bits
(
uint
x
)
65
{
66
x
&= 0x0000ffff;
67
x
= (
x
^ (
x
<< 8)) & 0x00ff00ff;
68
x
= (
x
^ (
x
<< 4)) & 0x0f0f0f0f;
69
x
= (
x
^ (
x
<< 2)) & 0x33333333;
70
x
= (
x
^ (
x
<< 1)) & 0x55555555;
71
return
x
;
72
}
73
74
ccl_device_inline
uint
morton2d
(
const
uint
x
,
const
uint
y
)
75
{
76
return
(
expand_bits
(
x
) << 1) |
expand_bits
(
y
);
77
}
78
79
CCL_NAMESPACE_END
x
x
Definition
BLI_expr_pylike_eval_test.cc:345
uint
unsigned int uint
Definition
BLI_sys_types.h:64
seed
static unsigned long seed
Definition
btSoftBody.h:39
y
y
Definition
compositor_morphological_blur_infos.hh:22
expand_bits
ccl_device_inline uint expand_bits(uint x)
Definition
cycles/kernel/sample/util.h:64
reversed_bit_owen_base4
ccl_device_inline uint reversed_bit_owen_base4(uint n, const uint seed)
Definition
cycles/kernel/sample/util.h:35
reversed_bit_owen
CCL_NAMESPACE_BEGIN ccl_device_inline uint reversed_bit_owen(uint n, const uint seed)
Definition
cycles/kernel/sample/util.h:18
nested_uniform_scramble_base4
ccl_device_inline uint nested_uniform_scramble_base4(const uint i, const uint seed)
Definition
cycles/kernel/sample/util.h:59
morton2d
ccl_device_inline uint morton2d(const uint x, const uint y)
Definition
cycles/kernel/sample/util.h:74
nested_uniform_scramble
ccl_device_inline uint nested_uniform_scramble(const uint i, const uint seed)
Definition
cycles/kernel/sample/util.h:51
ccl_device_inline
#define ccl_device_inline
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
reverse_integer_bits
ccl_device_inline uint32_t reverse_integer_bits(uint32_t x)
Definition
math_base.h:802
CCL_NAMESPACE_BEGIN
Definition
python.cpp:37
i
i
Definition
text_draw.cc:230
math.h
types.h
Generated on
for Blender by
doxygen
1.16.1