rtiow: remove unused ray/triangle intersection implementations.
This commit is contained in:
parent
b9ebc186fa
commit
468cba97b3
@ -71,7 +71,7 @@ where
|
||||
}
|
||||
|
||||
/// Based on https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection.html
|
||||
fn ray_triangle_intersect_moller_trumbore1(r: Ray, tri: &Triangle) -> Option<RayTriangleResult> {
|
||||
fn ray_triangle_intersect_moller_trumbore(r: Ray, tri: &Triangle) -> Option<RayTriangleResult> {
|
||||
// #ifdef MOLLER_TRUMBORE
|
||||
// Vec3f v0v1 = v1 - v0;
|
||||
// Vec3f v0v2 = v2 - v0;
|
||||
@ -133,88 +133,6 @@ fn ray_triangle_intersect_moller_trumbore1(r: Ray, tri: &Triangle) -> Option<Ray
|
||||
None
|
||||
}
|
||||
|
||||
// From https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||
fn ray_triangle_intersect_moller_trumbore2(r: Ray, tri: &Triangle) -> Option<RayTriangleResult> {
|
||||
let v0 = tri.verts[0];
|
||||
let v1 = tri.verts[1];
|
||||
let v2 = tri.verts[2];
|
||||
|
||||
let edge1 = v1 - v0;
|
||||
let edge2 = v2 - v0;
|
||||
let h = cross(r.direction, edge2);
|
||||
let a = dot(edge1, h);
|
||||
if a < EPSILON {
|
||||
return None;
|
||||
}
|
||||
|
||||
let f = 1. / a;
|
||||
let s = r.origin - v0;
|
||||
let u = f * dot(s, h);
|
||||
if u < 0. || u > 1. {
|
||||
return None;
|
||||
}
|
||||
let q = cross(s, edge1);
|
||||
let v = f * dot(r.direction, q);
|
||||
if v < 0. || u + v > 1. {
|
||||
return None;
|
||||
}
|
||||
// At this stage we can compute t to find out where the intersection point is on the line.
|
||||
let t = f * dot(edge2, q);
|
||||
// ray intersection
|
||||
if t > EPSILON {
|
||||
return Some(RayTriangleResult {
|
||||
t,
|
||||
p: r.origin + r.direction * t,
|
||||
});
|
||||
}
|
||||
// This means that there is a line intersection but not a ray intersection.
|
||||
None
|
||||
}
|
||||
/// Based on https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ray-triangle-intersection-geometric-solution.html
|
||||
fn ray_triangle_intersect_geometric(r: Ray, tri: &Triangle) -> Option<RayTriangleResult> {
|
||||
let n = tri.normal;
|
||||
|
||||
// close enough to parallel, won't hit
|
||||
let n_dot_dir = dot(n, r.direction);
|
||||
if n_dot_dir < EPSILON {
|
||||
return None;
|
||||
}
|
||||
|
||||
let v0 = tri.verts[0];
|
||||
let v1 = tri.verts[1];
|
||||
let v2 = tri.verts[2];
|
||||
let d = -dot(n, v0);
|
||||
let t = -(dot(n, r.origin) + d) / n_dot_dir;
|
||||
// check if the triangle is behind the ray
|
||||
if t < 0. {
|
||||
return None;
|
||||
}
|
||||
|
||||
let p = r.origin + t * r.direction;
|
||||
|
||||
let edge0 = v1 - v0;
|
||||
let edge1 = v2 - v1;
|
||||
let edge2 = v0 - v2;
|
||||
let vp0 = p - v0;
|
||||
let c = cross(edge0, vp0);
|
||||
if dot(n, c) < 0. {
|
||||
return None;
|
||||
}
|
||||
|
||||
let vp1 = p - v1;
|
||||
let c = cross(edge1, vp1);
|
||||
if dot(n, c) < 0. {
|
||||
return None;
|
||||
}
|
||||
|
||||
let vp2 = p - v2;
|
||||
let c = cross(edge2, vp2);
|
||||
if dot(n, c) < 0. {
|
||||
return None;
|
||||
}
|
||||
Some(RayTriangleResult { t, p })
|
||||
}
|
||||
|
||||
impl<M> Hit for Triangles<M>
|
||||
where
|
||||
M: Material,
|
||||
@ -222,8 +140,7 @@ where
|
||||
fn hit(&self, r: Ray, _t_min: f32, _t_max: f32) -> Option<HitRecord> {
|
||||
// TODO(wathiede): add an acceleration structure to more cheaply skip some triangles.
|
||||
for tri in &self.triangles {
|
||||
if let Some(RayTriangleResult { t, p }) =
|
||||
ray_triangle_intersect_moller_trumbore1(r, tri)
|
||||
if let Some(RayTriangleResult { t, p }) = ray_triangle_intersect_moller_trumbore(r, tri)
|
||||
{
|
||||
//if let Some(RayTriangleResult { t, p }) = ray_triangle_intersect_geometric(r, tri) {
|
||||
// We don't support UV (yet?).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user