commit 4a2e1c1025a288048e63cca45400b596c0955b60
parent bd73e8281ea0c62700e1ccfd3f3a1cf229e72264
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 19 Jan 2021 15:10:02 +0100
Revert closest_point hit normal internals to float
To enable strict equality with geometrical normal
Diffstat:
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/s3d_scene_view_closest_point.c b/src/s3d_scene_view_closest_point.c
@@ -177,7 +177,7 @@ closest_point_mesh
double query_pos_ws[3]; /* World space query position */
double query_pos_ls[3]; /* Local space query position */
double v0[3], v1[3], v2[3];
- double E0[3], E1[3], Ng[3];
+ float E0[3], E1[3], Ng[3];
double vec[3];
double uv[2];
float dst;
@@ -238,14 +238,17 @@ closest_point_mesh
if(dst >= args->query->radius) return 0;
- /* Compute the triangle normal in world space */
- d3_sub(E0, v2, v0);
- d3_sub(E1, v1, v0);
- d3_cross(Ng, E0, E1);
+ /* Compute the triangle normal in world space (left hand convention). Keep
+ * it in float to avoid double-cast accuracy loss wrt user computed result */
+ f3_sub(E0, mesh_get_pos(geom->data.mesh) + ids[1] * 3,
+ mesh_get_pos(geom->data.mesh) + ids[0] * 3);
+ f3_sub(E1, mesh_get_pos(geom->data.mesh) + ids[2] * 3,
+ mesh_get_pos(geom->data.mesh) + ids[0] * 3);
+ f3_cross(Ng, E1, E0);
/* Flip the geometric normal wrt the flip surface flag */
flip_surface ^= geom->flip_surface;
- if(flip_surface) d3_minus(Ng, Ng);
+ if(flip_surface) f3_minus(Ng, Ng);
/* Setup the hit */
hit.prim.shape__ = geom;
@@ -253,9 +256,9 @@ closest_point_mesh
hit.distance = dst;
hit.uv[0] = (float)uv[0];
hit.uv[1] = (float)uv[1];
- hit.normal[0] = (float)Ng[0];
- hit.normal[1] = (float)Ng[1];
- hit.normal[2] = (float)Ng[2];
+ hit.normal[0] = Ng[0];
+ hit.normal[1] = Ng[1];
+ hit.normal[2] = Ng[2];
hit.prim.prim_id = args->primID;
hit.prim.geom_id = geom->name;
hit.prim.inst_id = inst ? inst->name : S3D_INVALID_ID;