commit ded9310ea0cfc83973fe5fc88a43a7ea7fc4ea38
parent 80d0b78d3f92d00bfb20151ecd63a6440673af78
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 9 Sep 2016 10:03:27 +0200
Fix the transformation of the instance normal in world space
Use the inverse transpose matrix rather than the original matrix.
Diffstat:
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/s3d_scene_view.c b/src/s3d_scene_view.c
@@ -167,6 +167,7 @@ hit_setup(struct s3d_scene_view* scnview, const RTCRay* ray, struct s3d_hit* hit
/* Retrieve the hit instance */
struct geometry* geom_inst;
struct geometry* geom_mesh;
+ float transform[9];
ASSERT((unsigned)ray->instID < darray_geom_size_get(&scnview->embree2geoms));
geom_inst = scene_view_geometry_from_embree_id(scnview, ray->instID);
geom_mesh = scene_view_geometry_from_embree_id
@@ -186,7 +187,8 @@ hit_setup(struct s3d_scene_view* scnview, const RTCRay* ray, struct s3d_hit* hit
ASSERT(((struct geometry*)hit->prim.inst__)->type == GEOM_INSTANCE);
/* Transform the normal in world space */
- f33_mulf3(hit->normal, geom_inst->data.instance->transform, hit->normal);
+ f33_invtrans(transform, geom_inst->data.instance->transform);
+ f33_mulf3(hit->normal, transform, hit->normal);
}
ASSERT(hit->prim.mesh__);
ASSERT(((struct geometry*)hit->prim.mesh__)->type == GEOM_MESH);