some advice on muller trumbore code for ray-triangle intersection.
- From: broli <Broli00@xxxxxxxxx>
- Date: Thu, 24 Jul 2008 10:24:47 -0700 (PDT)
hello, this is the ray triangle intersection code based on the muller
- trumbore paper i read-
bool intersect_triangle(vector *o, vector *d, vector *v0, vector *v1,
vector *v2, double *t, double *u, double *v)
{
vector edge1, edge2, pvec, qvec, tvec;
double det, inv_det;
vector_sub(v1, v0, &edge1);
vector_sub(v2, v0, &edge2);
vector_cross(d, &edge2, &pvec);
det = vector_dot(&edge1, &pvec);
if (det < DBL_EPSILON)
{
return (false);
}
vector_sub(o, v0, &tvec);
*u = vector_dot(&tvec, &pvec);
if (*u < 0.0 || *u > det)
{
return (false);
}
vector_cross(&tvec, &edge1, &qvec);
*v = vector_dot(d, &qvec);
if (*v < 0.0 || *u + *v > det)
{
return (false);
}
*t = vector_dot(&edge2, &qvec);
inv_det = 1.0 / det;
*t *= inv_det;
if (*t < -DBL_EPSILON)
{
return (false);
}
*u *= inv_det;
*v *= inv_det;
return (true);
}
One thing I noticed is that if the ray origin lie on the object
itself, then the triangle on which the origin lies is reported as the
intersected triangle and the distance to triangle is 0.
I think this is undesirable in case of multiple reflections i.e. when
ray gets reflected of many surfaces on the object. In that case, *t < -
DBL_EPSILON statement is the culprit and I'm not sure why they had
this condition in the code. Any particular reasons ? If I change it to
*t <= 0.0, the code is alright.
.
- Follow-Ups:
- Prev by Date: Re: ray-triangle edge intersection
- Next by Date: Re: some advice on muller trumbore code for ray-triangle intersection.
- Previous by thread: Rectangle problem
- Next by thread: Re: some advice on muller trumbore code for ray-triangle intersection.
- Index(es):
Relevant Pages
|