From 90d3a46622d9af4dd9a1ade5cd3491810c3cc3ab Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 2 Jun 2017 11:13:39 -0700 Subject: ray: precompute primary ray for ray_object_plane_t This gets rid of some computation on the primary ray:plane intersection tests --- src/modules/ray/ray_object_plane.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/ray/ray_object_plane.h b/src/modules/ray/ray_object_plane.h index 0be28f4..5fcc619 100644 --- a/src/modules/ray/ray_object_plane.h +++ b/src/modules/ray/ray_object_plane.h @@ -13,11 +13,15 @@ typedef struct ray_object_plane_t { ray_surface_t surface; ray_3f_t normal; float distance; + struct { + float primary_dot_plus; + } _prepared; } ray_object_plane_t; static void ray_object_plane_prepare(ray_object_plane_t *plane, ray_camera_t *camera) { + plane->_prepared.primary_dot_plus = (ray_3f_dot(&plane->normal, &camera->position) + plane->distance); } @@ -26,8 +30,12 @@ static inline int ray_object_plane_intersects_ray(ray_object_plane_t *plane, uns float d = ray_3f_dot(&plane->normal, &ray->direction); if (d >= 0.00001f) { - float distance = (ray_3f_dot(&plane->normal, &ray->origin) + plane->distance) / d; + float distance = plane->_prepared.primary_dot_plus; + if (depth != 1) + distance = (ray_3f_dot(&plane->normal, &ray->origin) + plane->distance); + + distance /= d; if (distance > 0) { *res_distance = distance; -- cgit v1.2.3