Blender V5.0
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
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 */
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
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 */
55
56/*
57 * Performs base-4 Owen scrambling on an unsigned integer.
58 */
63
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
75{
76 return (expand_bits(x) << 1) | expand_bits(y);
77}
78
unsigned int uint
static unsigned long seed
Definition btSoftBody.h:39
ccl_device_inline uint expand_bits(uint x)
ccl_device_inline uint reversed_bit_owen_base4(uint n, const uint seed)
CCL_NAMESPACE_BEGIN ccl_device_inline uint reversed_bit_owen(uint n, const uint seed)
ccl_device_inline uint nested_uniform_scramble_base4(const uint i, const uint seed)
ccl_device_inline uint morton2d(const uint x, const uint y)
ccl_device_inline uint nested_uniform_scramble(const uint i, const uint seed)
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_inline uint32_t reverse_integer_bits(uint32_t x)
Definition math_base.h:802
i
Definition text_draw.cc:230