added Box intersect() optimization... ~2% faster
git-svn-id: svn://anubis/fart/trunk@305 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
138c90c2c3
commit
437fa8b07a
@ -20,6 +20,40 @@ Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
|
||||||
IntersectionList res;
|
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
|
* Ray equation: R = R0 + tRd
|
||||||
* x = R0x + tRdx
|
* x = R0x + tRdx
|
||||||
|
@ -33,8 +33,12 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
|
|||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
|
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
|
||||||
if (res1.size() == 0) /* optimization */
|
|
||||||
|
/*** optimization ***/
|
||||||
|
if (res1.size() == 0)
|
||||||
return res1;
|
return res1;
|
||||||
|
/*** end optimization ***/
|
||||||
|
|
||||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
||||||
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
|
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);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
|
|
||||||
IntersectionList res;
|
IntersectionList res;
|
||||||
|
|
||||||
QuadraticSolver solver(1.0,
|
QuadraticSolver solver(1.0,
|
||||||
2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0]
|
2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0]
|
||||||
+ ray_inv.getOrigin()[1] * ray_inv.getDirection()[1]
|
+ ray_inv.getOrigin()[1] * ray_inv.getDirection()[1]
|
||||||
|
@ -33,8 +33,12 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
|
|||||||
{
|
{
|
||||||
Ray ray_inv = m_inverse.transform_ray(ray);
|
Ray ray_inv = m_inverse.transform_ray(ray);
|
||||||
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
|
IntersectionList res1 = m_shape1->intersect(m_shape1, ray_inv);
|
||||||
if (res1.size() == 0) /* optimization */
|
|
||||||
|
/*** optimization ***/
|
||||||
|
if (res1.size() == 0)
|
||||||
return res1;
|
return res1;
|
||||||
|
/*** end optimization ***/
|
||||||
|
|
||||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
IntersectionList res2 = m_shape2->intersect(m_shape2, ray_inv);
|
||||||
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
|
BoolIntersectionList merged(res1, res2, ray_inv.getOrigin());
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
|
||||||
|
const Vector Vector::X(1, 0, 0);
|
||||||
|
const Vector Vector::Y(0, 1, 0);
|
||||||
|
const Vector Vector::Z(0, 0, 1);
|
||||||
|
|
||||||
Vector::Vector()
|
Vector::Vector()
|
||||||
{
|
{
|
||||||
m_array[0] = 0.0;
|
m_array[0] = 0.0;
|
||||||
|
@ -32,6 +32,10 @@ class Vector
|
|||||||
Vector & operator+=(const Vector & v2);
|
Vector & operator+=(const Vector & v2);
|
||||||
Vector & operator-=(const Vector & v2);
|
Vector & operator-=(const Vector & v2);
|
||||||
|
|
||||||
|
static const Vector X;
|
||||||
|
static const Vector Y;
|
||||||
|
static const Vector Z;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_array[3];
|
double m_array[3];
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user