added Box intersect() optimization... ~2% faster
git-svn-id: svn://anubis/fart/trunk@305 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
138c90c2c3
commit
437fa8b07a
6 files changed
+53
-2
No files matched your search
@@ -20,6 +20,40 @@ Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||
|
||||
IntersectionList res;
|
||||
|
||||
/*** optimization ***/
|
||||
if (ray_inv.getOrigin()[0] > m_size[0])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::X > 0)
|
||||
return res;
|
||||
}
|
||||
else if (ray_inv.getOrigin()[0] < -m_size[0])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::X < 0)
|
||||
return res;
|
||||
}
|
||||
if (ray_inv.getOrigin()[1] > m_size[1])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::Y > 0)
|
||||
return res;
|
||||
}
|
||||
else if (ray_inv.getOrigin()[1] < -m_size[1])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::Y < 0)
|
||||
return res;
|
||||
}
|
||||
if (ray_inv.getOrigin()[2] > m_size[2])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::Z > 0)
|
||||
return res;
|
||||
}
|
||||
else if (ray_inv.getOrigin()[2] < -m_size[2])
|
||||
{
|
||||
if (ray_inv.getDirection() % Vector::Z < 0)
|
||||
return res;
|
||||
}
|
||||
/*** end optimization ***/
|
||||
|
||||
/*
|
||||
* Ray equation: R = R0 + tRd
|
||||
* x = R0x + tRdx
|
||||
|
||||
+5
-1
@@ -33,8 +33,12 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _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 */
|
||||
|
||||
/*** optimization ***/
|
||||
if (res1.size() == 0)
|
||||
return res1;
|
||||
/*** end optimization ***/
|
||||
|
||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
||||
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Shape::IntersectionList Sphere::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||
|
||||
IntersectionList res;
|
||||
|
||||
QuadraticSolver solver(1.0,
|
||||
2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0]
|
||||
+ ray_inv.getOrigin()[1] * ray_inv.getDirection()[1]
|
||||
|
||||
+5
-1
@@ -33,8 +33,12 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _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 */
|
||||
|
||||
/*** optimization ***/
|
||||
if (res1.size() == 0)
|
||||
return res1;
|
||||
/*** end optimization ***/
|
||||
|
||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
||||
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
|
||||
|
||||
|
||||
Reference in new issue
Block a user