From 138c90c2c31c8e47ce4a9489578023cf9e6d9214 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 28 Sep 2010 14:22:25 +0000 Subject: [PATCH] optimized intersect() test for Subtract and Intersect boolean objects to not attempt intersecting with object B when object A had no intersections.... had about a 26% speed improvement for DW test scene git-svn-id: svn://anubis/fart/trunk@304 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- shapes/Intersect.cc | 2 ++ shapes/Subtract.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/shapes/Intersect.cc b/shapes/Intersect.cc index a4c421e..2546c1c 100644 --- a/shapes/Intersect.cc +++ b/shapes/Intersect.cc @@ -33,6 +33,8 @@ Shape::IntersectionList Intersect::intersect(refptr _this, const Ray & ra { Ray ray_inv = m_inverse.transform_ray(ray); IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv); + if (res1.size() == 0) /* optimization */ + return res1; IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv); BoolIntersectionList merged(res1, res2, ray_inv.getOrigin()); diff --git a/shapes/Subtract.cc b/shapes/Subtract.cc index a2f2d94..dd7a646 100644 --- a/shapes/Subtract.cc +++ b/shapes/Subtract.cc @@ -33,6 +33,8 @@ Shape::IntersectionList Subtract::intersect(refptr _this, const Ray & ray { Ray ray_inv = m_inverse.transform_ray(ray); IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv); + if (res1.size() == 0) /* optimization */ + return res1; IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv); BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());