summaryrefslogtreecommitdiff
path: root/src/modules/ray
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-05-12 15:58:32 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-05-12 18:34:56 -0700
commitb8338217569a871cee6e91e3fd07766191667663 (patch)
treeb05a354d15953d16d37bd69934c35f2c24950c6f /src/modules/ray
parent73ef51a819138e50b3d0b162d61a9f272fe07d01 (diff)
ray: mult normalize in ray_object_sphere_normal
Simple optimization taking advantage of the prepare, mults generally are cheaper than divs.
Diffstat (limited to 'src/modules/ray')
-rw-r--r--src/modules/ray/ray_object_sphere.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/modules/ray/ray_object_sphere.h b/src/modules/ray/ray_object_sphere.h
index cb8e665..aadda18 100644
--- a/src/modules/ray/ray_object_sphere.h
+++ b/src/modules/ray/ray_object_sphere.h
@@ -17,6 +17,7 @@ typedef struct ray_object_sphere_t {
float radius;
struct {
float r2;
+ float r_inv;
} _prepared;
} ray_object_sphere_t;
@@ -24,6 +25,9 @@ typedef struct ray_object_sphere_t {
static void ray_object_sphere_prepare(ray_object_sphere_t *sphere)
{
sphere->_prepared.r2 = sphere->radius * sphere->radius;
+
+ /* to divide by radius via multiplication in ray_object_sphere_normal() */
+ sphere->_prepared.r_inv = 1.0f / sphere->radius;
}
@@ -57,7 +61,7 @@ static inline ray_3f_t ray_object_sphere_normal(ray_object_sphere_t *sphere, ray
ray_3f_t normal;
normal = ray_3f_sub(point, &sphere->center);
- normal = ray_3f_div_scalar(&normal, sphere->radius); /* normalize without the sqrt() */
+ normal = ray_3f_mult_scalar(&normal, sphere->_prepared.r_inv); /* normalize without the sqrt() */
return normal;
}
© All Rights Reserved