[Bf-blender-cvs] [721a484ccb3] blender2.8: BLI_kdopbvh: reduce branching in calc_nearest_point_squared.

Alexander Gavrilov noreply at git.blender.org
Mon Nov 5 15:18:35 CET 2018


Commit: 721a484ccb3c66f49665988d624e5992e457cdde
Author: Alexander Gavrilov
Date:   Sun Nov 4 12:26:49 2018 +0300
Branches: blender2.8
https://developer.blender.org/rB721a484ccb3c66f49665988d624e5992e457cdde

BLI_kdopbvh: reduce branching in calc_nearest_point_squared.

This lets the compiler use min/max instructions for 4.5% FPS
improvement in Shrinkwrap to Nearest Surface Point.

===================================================================

M	source/blender/blenlib/intern/BLI_kdopbvh.c

===================================================================

diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 45198af0515..ebe73ed1044 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1266,12 +1266,12 @@ static float calc_nearest_point_squared(const float proj[3], BVHNode *node, floa
 
 	/* nearest on AABB hull */
 	for (i = 0; i != 3; i++, bv += 2) {
-		if (bv[0] > proj[i])
-			nearest[i] = bv[0];
-		else if (bv[1] < proj[i])
-			nearest[i] = bv[1];
-		else
-			nearest[i] = proj[i];
+		float val = proj[i];
+		if (bv[0] > val)
+			val = bv[0];
+		if (bv[1] < val)
+			val = bv[1];
+		nearest[i] = val;
 	}
 
 	return len_squared_v3v3(proj, nearest);



More information about the Bf-blender-cvs mailing list