Blender V4.3
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/types.h"
8
10
11/*
12 * Performs base-2 Owen scrambling on a reversed-bit unsigned integer.
13 *
14 * This is equivalent to the Laine-Karras permutation, but much higher
15 * quality. See https://psychopath.io/post/2021_01_30_building_a_better_lk_hash
16 */
18{
19 n ^= n * 0x3d20adea;
20 n += seed;
21 n *= (seed >> 16) | 1;
22 n ^= n * 0x05526c56;
23 n ^= n * 0x53a22864;
24
25 return n;
26}
27
28/*
29 * Performs base-4 Owen scrambling on a reversed-bit unsigned integer.
30 *
31 * See https://psychopath.io/post/2022_08_14_a_fast_hash_for_base_4_owen_scrambling
32 */
33
35{
36 n ^= n * 0x3d20adea;
37 n ^= (n >> 1) & (n << 1) & 0x55555555;
38 n += seed;
39 n *= (seed >> 16) | 1;
40 n ^= (n >> 1) & (n << 1) & 0x55555555;
41 n ^= n * 0x05526c56;
42 n ^= n * 0x53a22864;
43
44 return n;
45}
46
47/*
48 * Performs base-2 Owen scrambling on an unsigned integer.
49 */
54
55/*
56 * Performs base-4 Owen scrambling on an unsigned integer.
57 */
62
64{
65 x &= 0x0000ffff;
66 x = (x ^ (x << 8)) & 0x00ff00ff;
67 x = (x ^ (x << 4)) & 0x0f0f0f0f;
68 x = (x ^ (x << 2)) & 0x33333333;
69 x = (x ^ (x << 1)) & 0x55555555;
70 return x;
71}
72
74{
75 return (expand_bits(x) << 1) | expand_bits(y);
76}
77
unsigned int uint
static unsigned long seed
Definition btSoftBody.h:39
ccl_device_inline uint expand_bits(uint x)
CCL_NAMESPACE_BEGIN ccl_device_inline uint reversed_bit_owen(uint n, uint seed)
ccl_device_inline uint reversed_bit_owen_base4(uint n, uint seed)
ccl_device_inline uint nested_uniform_scramble(uint i, uint seed)
ccl_device_inline uint nested_uniform_scramble_base4(uint i, uint seed)
ccl_device_inline uint morton2d(uint x, uint y)
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_inline uint32_t reverse_integer_bits(uint32_t x)
Definition util/math.h:1016