ソースを参照

Merge pull request #82436 from Rindbee/fix-axis-being-mixed-up

Fix axis getting mixed up when split leaf
Rémi Verschelde 2 年 前
コミット
ec62b8a3ee
1 ファイル変更9 行追加9 行削除
  1. 9 9
      core/math/bvh_split.inc

+ 9 - 9
core/math/bvh_split.inc

@@ -20,8 +20,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 		group_b[num_b++] = ind;
 		group_b[num_b++] = ind;
 
 
 		// remove from a
 		// remove from a
-		group_a[0] = group_a[num_a - 1];
 		num_a--;
 		num_a--;
+		group_a[0] = group_a[num_a];
 		return;
 		return;
 	}
 	}
 
 
@@ -30,15 +30,15 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 
 
 	int order[POINT::AXIS_COUNT];
 	int order[POINT::AXIS_COUNT];
 
 
-	order[0] = size.min_axis_index();
-	order[POINT::AXIS_COUNT - 1] = size.max_axis_index();
+	order[0] = size.max_axis_index(); // The longest axis.
+	order[POINT::AXIS_COUNT - 1] = size.min_axis_index(); // The shortest axis.
 
 
 	static_assert(POINT::AXIS_COUNT <= 3, "BVH POINT::AXIS_COUNT has unexpected size");
 	static_assert(POINT::AXIS_COUNT <= 3, "BVH POINT::AXIS_COUNT has unexpected size");
 	if constexpr (POINT::AXIS_COUNT == 3) {
 	if constexpr (POINT::AXIS_COUNT == 3) {
 		order[1] = 3 - (order[0] + order[2]);
 		order[1] = 3 - (order[0] + order[2]);
 	}
 	}
 
 
-	// simplest case, split on the longest axis
+	// Simplest case, split on the longest axis.
 	int split_axis = order[0];
 	int split_axis = order[0];
 	for (int a = 0; a < num_a; a++) {
 	for (int a = 0; a < num_a; a++) {
 		uint32_t ind = group_a[a];
 		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
 			group_b[num_b++] = ind;
 			group_b[num_b++] = ind;
 
 
 			// remove from a
 			// remove from a
-			group_a[a] = group_a[num_a - 1];
 			num_a--;
 			num_a--;
+			group_a[a] = group_a[num_a];
 
 
 			// do this one again, as it has been replaced
 			// do this one again, as it has been replaced
 			a--;
 			a--;
@@ -67,7 +67,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 		}
 		}
 		num_b = 0;
 		num_b = 0;
 
 
-		// now calculate the best split
+		// Now calculate the best split.
 		for (int axis = 1; axis < POINT::AXIS_COUNT; axis++) {
 		for (int axis = 1; axis < POINT::AXIS_COUNT; axis++) {
 			split_axis = order[axis];
 			split_axis = order[axis];
 			int count = 0;
 			int count = 0;
@@ -105,8 +105,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 					group_b[num_b++] = ind;
 					group_b[num_b++] = ind;
 
 
 					// remove from a
 					// remove from a
-					group_a[a] = group_a[num_a - 1];
 					num_a--;
 					num_a--;
+					group_a[a] = group_a[num_a];
 
 
 					// do this one again, as it has been replaced
 					// do this one again, as it has been replaced
 					a--;
 					a--;
@@ -123,8 +123,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 		group_b[num_b++] = ind;
 		group_b[num_b++] = ind;
 
 
 		// remove from a
 		// remove from a
-		group_a[0] = group_a[num_a - 1];
 		num_a--;
 		num_a--;
+		group_a[0] = group_a[num_a];
 	}
 	}
 	// opposite problem! :)
 	// opposite problem! :)
 	if (!num_a) {
 	if (!num_a) {
@@ -134,8 +134,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
 		group_a[num_a++] = ind;
 		group_a[num_a++] = ind;
 
 
 		// remove from b
 		// remove from b
-		group_b[0] = group_b[num_b - 1];
 		num_b--;
 		num_b--;
+		group_b[0] = group_b[num_b];
 	}
 	}
 }
 }