Skip to content

Commit ec62b8a

Browse files
committed
Merge pull request #82436 from Rindbee/fix-axis-being-mixed-up
Fix axis getting mixed up when split leaf
2 parents d616c3e + 0156860 commit ec62b8a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

core/math/bvh_split.inc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
2020
group_b[num_b++] = ind;
2121

2222
// remove from a
23-
group_a[0] = group_a[num_a - 1];
2423
num_a--;
24+
group_a[0] = group_a[num_a];
2525
return;
2626
}
2727

@@ -30,15 +30,15 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
3030

3131
int order[POINT::AXIS_COUNT];
3232

33-
order[0] = size.min_axis_index();
34-
order[POINT::AXIS_COUNT - 1] = size.max_axis_index();
33+
order[0] = size.max_axis_index(); // The longest axis.
34+
order[POINT::AXIS_COUNT - 1] = size.min_axis_index(); // The shortest axis.
3535

3636
static_assert(POINT::AXIS_COUNT <= 3, "BVH POINT::AXIS_COUNT has unexpected size");
3737
if constexpr (POINT::AXIS_COUNT == 3) {
3838
order[1] = 3 - (order[0] + order[2]);
3939
}
4040

41-
// simplest case, split on the longest axis
41+
// Simplest case, split on the longest axis.
4242
int split_axis = order[0];
4343
for (int a = 0; a < num_a; a++) {
4444
uint32_t ind = group_a[a];
@@ -48,8 +48,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
4848
group_b[num_b++] = ind;
4949

5050
// remove from a
51-
group_a[a] = group_a[num_a - 1];
5251
num_a--;
52+
group_a[a] = group_a[num_a];
5353

5454
// do this one again, as it has been replaced
5555
a--;
@@ -67,7 +67,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
6767
}
6868
num_b = 0;
6969

70-
// now calculate the best split
70+
// Now calculate the best split.
7171
for (int axis = 1; axis < POINT::AXIS_COUNT; axis++) {
7272
split_axis = order[axis];
7373
int count = 0;
@@ -105,8 +105,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
105105
group_b[num_b++] = ind;
106106

107107
// remove from a
108-
group_a[a] = group_a[num_a - 1];
109108
num_a--;
109+
group_a[a] = group_a[num_a];
110110

111111
// do this one again, as it has been replaced
112112
a--;
@@ -123,8 +123,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
123123
group_b[num_b++] = ind;
124124

125125
// remove from a
126-
group_a[0] = group_a[num_a - 1];
127126
num_a--;
127+
group_a[0] = group_a[num_a];
128128
}
129129
// opposite problem! :)
130130
if (!num_a) {
@@ -134,8 +134,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
134134
group_a[num_a++] = ind;
135135

136136
// remove from b
137-
group_b[0] = group_b[num_b - 1];
138137
num_b--;
138+
group_b[0] = group_b[num_b];
139139
}
140140
}
141141

0 commit comments

Comments
 (0)