Blender V5.3
select_lib.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
7#include "select_defines.hh"
9
10namespace draw {
11
15
16struct Select {
18
19 [[uniform(SELECT_DATA)]] const SelectInfoData &select_info_buf;
20 [[storage(SELECT_ID_IN, read)]] const uint (&in_select_buf)[];
21 [[storage(SELECT_ID_OUT, read_write)]] uint (&out_select_buf)[];
22
24 {
25 if (id == -1u) {
26 /* Invalid index */
27 return;
28 }
29
30 if (select_info_buf.mode == SELECT_ALL) {
31 if (select_info_buf.radius > 0) {
32 /* When the radius is set, we assume that the center is cursor is the center of a circle.
33 */
34 int2 coord = int2(frag_coord.xy) - select_info_buf.cursor;
35 uint dist_sq = uint(coord.x * coord.x + coord.y * coord.y);
36 uint rad_sq = select_info_buf.radius * select_info_buf.radius;
37 if (dist_sq > rad_sq) {
38 return;
39 }
40 }
41
42 /* Set the bit of the select id in the bitmap. */
43 atomicOr(out_select_buf[id / 32u], 1u << (id % 32u));
44 }
45 else if (select_info_buf.mode == SELECT_PICK_ALL) {
46 /* Stores the nearest depth for this select id. */
48 }
49 else if (select_info_buf.mode == SELECT_PICK_NEAREST) {
50 /* Stores the nearest depth with the distance to the cursor. */
51
52 /* Distance function to the cursor. Currently a simple pixel ring distance. */
53 int2 coord = abs(int2(frag_coord.xy) - select_info_buf.cursor);
54 uint dist = uint(max(coord.x, coord.y));
55
56 uint depth = uint(frag_coord.z * float(0x00FFFFFFu));
57
58 /* Reject hits outside of valid range. */
59 if (dist < 0xFFu) {
60 /* Packed values to ensure the atomicMin is performed on the whole result. */
61 atomicMin(out_select_buf[id], (depth << 8u) | dist);
62 }
63 }
64 }
65};
66
67struct SelectOut {
68 [[flat]] uint select_id;
69};
70
71} // namespace draw
btScalar max
#define uniform(slot)
#define storage(slot, qualifiers)
#define flat
#define frag_coord
#define compilation_constant
#define resource_table
int atomicMin(int &, int) RET
#define abs
VecBase< uint, D > floatBitsToUint(VecOp< float, D >) RET
int atomicOr(int &, int) RET
#define SELECT_DATA
#define SELECT_ID_IN
#define SELECT_ID_OUT
SelectConstant consts
const SelectInfoData & select_info_buf
uint(& out_select_buf)[]
const uint(& in_select_buf)[]
void select_id_output(uint id, float4 frag_coord)