summaryrefslogtreecommitdiff
path: root/src/modules/ray
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-06-02 11:13:39 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-06-02 11:15:19 -0700
commit90d3a46622d9af4dd9a1ade5cd3491810c3cc3ab (patch)
tree22d71868c91563eda477a88967c50fe12d661863 /src/modules/ray
parentcbc6c0eaf45a7ede48465d1f6d6f7e24c14bd9ce (diff)
ray: precompute primary ray for ray_object_plane_t
This gets rid of some computation on the primary ray:plane intersection tests
Diffstat (limited to 'src/modules/ray')
-rw-r--r--src/modules/ray/ray_object_plane.h10
1 files changed, 9 insertions, 1 deletions
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;
© All Rights Reserved