Factored out interpolating over a triangle's surface into its own function.
We'll be using this in the RectangleLight sampling code soon.
This commit is contained in:
parent
5a03a46ac7
commit
b1bd419779
|
@ -128,6 +128,22 @@ pub fn intersect_ray(ray: &Ray, tri: (Point, Point, Point)) -> Option<(f32, f32,
|
|||
Some((t, b0, b1, b2))
|
||||
}
|
||||
|
||||
/// Calculates a point on a triangle's surface at the given barycentric
|
||||
/// coordinates.
|
||||
///
|
||||
/// Returns the point and the error magnitude of the point.
|
||||
pub fn surface_point(tri: (Point, Point, Point), bary: (f32, f32, f32)) -> (Point, f32) {
|
||||
let pos = ((tri.0.into_vector() * bary.0) + (tri.1.into_vector() * bary.1) +
|
||||
(tri.2.into_vector() * bary.2))
|
||||
.into_point();
|
||||
|
||||
let pos_err = (((tri.0.into_vector().abs() * bary.0) + (tri.1.into_vector().abs() * bary.1) +
|
||||
(tri.2.into_vector().abs() * bary.2)) * fp_gamma(7)).co
|
||||
.h_max();
|
||||
|
||||
(pos, pos_err)
|
||||
}
|
||||
|
||||
fn max_abs_3(a: f32, b: f32, c: f32) -> f32 {
|
||||
let a = a.abs();
|
||||
let b = b.abs();
|
||||
|
|
|
@ -5,7 +5,6 @@ use mem_arena::MemArena;
|
|||
use accel::BVH4;
|
||||
use bbox::BBox;
|
||||
use boundable::Boundable;
|
||||
use fp_utils::fp_gamma;
|
||||
use lerp::lerp_slice;
|
||||
use math::{Point, Normal, Matrix4x4, dot, cross};
|
||||
use ray::{Ray, AccelRay};
|
||||
|
@ -193,15 +192,7 @@ impl<'a> Surface for TriangleMesh<'a> {
|
|||
r.mark_done();
|
||||
} else {
|
||||
// Calculate intersection point and error magnitudes
|
||||
let pos = ((tri.0.into_vector() * b0) + (tri.1.into_vector() * b1) +
|
||||
(tri.2.into_vector() * b2))
|
||||
.into_point();
|
||||
|
||||
let pos_err = (((tri.0.into_vector().abs() * b0) +
|
||||
(tri.1.into_vector().abs() * b1) +
|
||||
(tri.2.into_vector().abs() * b2)) *
|
||||
fp_gamma(7)).co
|
||||
.h_max();
|
||||
let (pos, pos_err) = triangle::surface_point(tri, (b0, b1, b2));
|
||||
|
||||
// Calculate geometric surface normal
|
||||
let geo_normal = cross(tri.0 - tri.1, tri.0 - tri.2).into_normal();
|
||||
|
|
Loading…
Reference in New Issue
Block a user