commit 9d8d2ff7ee24f94b92e507cacdaa719d19ea5888
parent 282807c38404b499d4c4d0ad1c1a974542d1ee31
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 24 Jun 2016 16:52:11 +0200
Push further the "trace ray" tests
Diffstat:
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/s2d.h b/src/s2d.h
@@ -120,7 +120,7 @@ static const struct s2d_vertex_data S2D_VERTEX_DATA_NULL = S2D_VERTEX_DATA_NULL_
struct s2d_hit {
struct s2d_primitive prim; /* Intersected primitive */
float normal[2]; /* Unormalized geometry normal */
- float u; /* Barycentric coordinates of the hit onto `prim' */
+ float u; /* Barycentric coordinates onto `prim'. pos = (1 - u)*v0 + u*v1 */
float distance; /* Hit distance from the ray origin */
};
diff --git a/src/s2d_scene.c b/src/s2d_scene.c
@@ -69,7 +69,9 @@ hit_setup(struct s2d_scene* scn, const RTCRay* ray, struct s2d_hit* hit)
hit->normal[0] = ray->Ng[0];
hit->normal[1] = ray->Ng[1];
hit->distance = ray->tfar;
- hit->u = ray->u; /* TODO Check that the hit "u" matches to the edge "u" */
+ /* The Embree "v" parametric coordinate of the extruded quad corresponds to
+ * the edge parametric coordinate */
+ hit->u = ray->v;
if(geom->flip_contour)
f2_minus(hit->normal, hit->normal);
diff --git a/src/test_s2d_trace_ray.c b/src/test_s2d_trace_ray.c
@@ -147,6 +147,37 @@ main(int argc, char** argv)
f2(range, 0.f, FLT_MAX);
CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_BAD_OP);
+ CHECK(s2d_scene_begin_session(scn, S2D_TRACE), RES_OK);
+ f2_sub(dir, f2(dir, 0.75f, -1.f), org);
+ f2_normalize(dir, dir);
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ CHECK(eq_epsf(hit.u, 0.125f, 1.e-6f), 1);
+ CHECK(eq_epsf(hit.distance, 1.25, 1.E-6f), 1);
+
+ f2_sub(dir, f2(dir, -1.f, 0.25f), org);
+ f2_normalize(dir, dir);
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ CHECK(eq_epsf(hit.u, 0.625, 1.e-6f), 1);
+ CHECK(eq_epsf(hit.distance, (float)sqrt(1.0625f), 1e-6f), 1);
+
+ f2(org, -1.25f, 0.f);
+ f2(dir, -1, 0.f);
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 1);
+
+ f2(dir, 1, 0.f);
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ CHECK(hit.prim.prim_id, 1);
+ f2_normalize(N, hit.normal);
+ CHECK(f2_eq_eps(N, f2(dir, 1.f, 0.f), 1.e-6f), 1);
+ CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
+ CHECK(eq_epsf(hit.distance, 0.25f, 1.e-6f), 1);
+
+ CHECK(s2d_scene_end_session(scn), RES_OK);
+
CHECK(s2d_device_ref_put(dev), RES_OK);
CHECK(s2d_shape_ref_put(shape), RES_OK);
CHECK(s2d_scene_ref_put(scn), RES_OK);