Space Sim
Toggle main menu visibility
Loading...
Searching...
No Matches
src
particles
next.comp
Go to the documentation of this file.
1
2
#version 440
8
#define WORKGROUP_SIZE 128
9
#define RADIX_SORT_BINS 128
10
#define SUBGROUP_SIZE 32
11
12
#define BODY_COUNT 15000
13
#define MAX_NODES 45000
14
layout
(local_size_x =
WORKGROUP_SIZE
) in;
15
struct
Node
{
16
vec4
com_m
;
17
// min and size
18
vec4
min
;
19
// max and next
20
vec3
max
;
21
int
next
;
22
// left child, right child, parent, depth
23
ivec4
lrpd
;
24
};
25
#define MAX_DEPTH 64
26
layout
(std430, binding=4) buffer
NodeData
{
27
uint ready_queue[
MAX_NODES
];
28
uint children_remaining[
MAX_NODES
];
29
uint depth_offsets[
MAX_DEPTH
+1];
30
uint pad0;
31
uint pad1;
32
uint pad2;
33
// center of mass and mass
34
vec4
com_m[
MAX_NODES
];
35
// left right
36
vec4
lrsn[
MAX_NODES
];
37
// min and parent
38
vec4
nmin[
MAX_NODES
];
39
// max and depth
40
vec4
nmax[
MAX_NODES
];
41
};
42
uniform
int
depth
;
43
uniform
int
max_depth
;
44
uniform
bool
first_iter
;
45
uniform uint
current_depth_offset
;
46
uniform uint
current_amt
;
47
48
void
main
()
49
{
50
uint
id
= gl_GlobalInvocationID.x;
51
if
(
id
>=
MAX_NODES
)
return
;
52
53
54
int
d = floatBitsToInt(nmax[
id
].w);
55
56
// set all child node's "next" to the parent's right node
57
// this must be done from the top-down (root first and then each depth subsequently)
58
// if current node's depth isn't the current depth
59
if
(d < depth || d == 999 || d >
depth
) {
60
return
;
61
}
62
63
int
p = floatBitsToInt(nmin[
id
].w);
64
65
// if parent
66
if
(p != -1)
67
{
68
69
// check parent lrsn (left right radius next)
70
vec4
lr = lrsn[p];
71
int
left = floatBitsToInt(lr.
x
);
72
int
right = floatBitsToInt(lr.
y
);
73
int
n = floatBitsToInt(lr.
w
);
74
// if we are our parent's left child, set our next to its right child
75
if
(left ==
id
)
76
{
77
lrsn[id].w = lr.
y
;
78
}
79
else
80
{
81
// else set it to our parent next
82
lrsn[id].w = lr.
w
;
83
}
84
}
85
else
86
{
87
// if no parent, set parent right to -1
88
lrsn[id].w = intBitsToFloat(-1);
89
}
90
91
}
layout
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
depth
uniform int depth
Definition
com22.comp:76
main
int main(int argc, char *argv[])
Definition
main.c:1726
Node::max
vec3 max
Definition
com22.comp:49
Node::com_m
vec4 com_m
Definition
com22.comp:45
Node::next
int next
Definition
com22.comp:50
Node::lrpd
ivec4 lrpd
Definition
com22.comp:52
Node::min
vec4 min
Definition
com22.comp:47
Node
Definition
types.h:109
max_depth
uniform int max_depth
Definition
next.comp:43
current_amt
uniform uint current_amt
Definition
next.comp:46
first_iter
uniform bool first_iter
Definition
next.comp:44
current_depth_offset
uniform uint current_depth_offset
Definition
next.comp:45
vec4::w
float w
Definition
types.h:47
vec4::x
float x
Definition
types.h:47
WORKGROUP_SIZE
#define WORKGROUP_SIZE
Definition
types.h:171
MAX_DEPTH
#define MAX_DEPTH
Definition
types.h:154
vec4::y
float y
Definition
types.h:47
MAX_NODES
#define MAX_NODES
Definition
types.h:40
NodeData
Definition
types.h:156
ivec4
Definition
types.h:49
vec3
Definition
main.h:5
vec4
Definition
types.h:47
Generated by
1.18.0