some advice on muller trumbore code for ray-triangle intersection.



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.
.



Relevant Pages

  • Re: Triangle mesh question?
    ... Still renders only spheres. ... intersect each triangle. ... This is a well studied problem in ray tracing. ... subdivision" and "bounding volume hierarchy". ...
    (comp.graphics.algorithms)
  • Re: some advice on muller trumbore code for ray-triangle intersection.
    ... One thing I noticed is that if the ray origin lie on the object ... intersected triangle and the distance to triangle is 0. ... I think this is undesirable in case of multiple reflections i.e. when ...
    (comp.graphics.algorithms)
  • ray tracing electromagnetic waves
    ... I'm actually trying to ray trace electromagnetic waves and the object ... intersection faster..The main objective is to calculate the total ... triangle to find the intersection point. ... multiple reflection? ...
    (comp.graphics.algorithms)
  • Re: Point location via ray shooting
    ... > triangle points to the same direction as the triangle else its ... Taking this you just have to shoot at least one ray from each ... Best regards, ... Prev by Date: ...
    (comp.graphics.algorithms)