Blender V5.3
gpu_shader_material_bit_math.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9[[node]]
10void bit_math_and(int a, int b, int &result)
11{
12 result = a & b;
13}
14
15[[node]]
16void bit_math_or(int a, int b, int &result)
17{
18 result = a | b;
19}
20
21[[node]]
22void bit_math_xor(int a, int b, int &result)
23{
24 result = a ^ b;
25}
26
27[[node]]
28void bit_math_not(int a, int &result)
29{
30 result = ~a;
31}
32
33[[node]]
34void bit_math_shift(int a, int shift_amount, int &result)
35{
36 const uint value = uint(a);
37 const int shift = shift_amount;
38
39 if (shift < -31 || shift > 31) {
40 result = 0;
41 }
42 else {
43 if (shift >= 0) {
44 result = int(value << uint(shift));
45 }
46 else {
47 result = int(value >> uint(-shift));
48 }
49 }
50}
51
52[[node]]
53void bit_math_rotate(int a, int shift_amount, int &result)
54{
55 const uint value = uint(a);
56 int shift = shift_amount % 32;
57
58 if (shift < 0) {
59 shift += 32;
60 }
61 if (shift == 0) {
62 result = int(value);
63 }
64 else {
65 result = int((value << uint(shift)) | (value >> uint(32 - shift)));
66 }
67}
void bit_math_or(int a, int b, int &result)
void bit_math_xor(int a, int b, int &result)
void bit_math_and(int a, int b, int &result)
void bit_math_shift(int a, int shift_amount, int &result)
void bit_math_not(int a, int &result)
void bit_math_rotate(int a, int shift_amount, int &result)