summaryrefslogtreecommitdiff
path: root/src/modules/ray
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-06-01 15:32:17 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-06-01 15:32:17 -0700
commitecdb3ebb4897a2a750d403a3389a12cb982cd113 (patch)
tree2631795853d924d7a399104d93f00ef789567eee /src/modules/ray
parentf77ab1e77aa3c89c4e923395b6fd75f3cb0bc522 (diff)
ray: perform ambient light color scale in prepare
Trivially removes a ray_3f_mult_scalar() from the hot path.
Diffstat (limited to 'src/modules/ray')
-rw-r--r--src/modules/ray/ray_scene.c5
-rw-r--r--src/modules/ray/ray_scene.h16
2 files changed, 13 insertions, 8 deletions
diff --git a/src/modules/ray/ray_scene.c b/src/modules/ray/ray_scene.c
index acd65d3..955bab6 100644
--- a/src/modules/ray/ray_scene.c
+++ b/src/modules/ray/ray_scene.c
@@ -57,8 +57,7 @@ static inline ray_color_t shade_ray(ray_scene_t *scene, ray_ray_t *ray, ray_obje
unsigned i;
surface = ray_object_surface(object, &intersection);
- color = ray_3f_mult_scalar(&scene->ambient_color, scene->ambient_brightness);
- color = ray_3f_mult(&surface.color, &color);
+ color = ray_3f_mult(&surface.color, &scene->_prepared.ambient_light);
/* visit lights for shadows and illumination */
for (i = 0; i < scene->n_lights; i++) {
@@ -186,6 +185,8 @@ void ray_scene_prepare(ray_scene_t *scene)
{
unsigned i;
+ scene->_prepared.ambient_light = ray_3f_mult_scalar(&scene->ambient_color, scene->ambient_brightness);
+
for (i = 0; i < scene->n_objects; i++)
ray_object_prepare(&scene->objects[i]);
}
diff --git a/src/modules/ray/ray_scene.h b/src/modules/ray/ray_scene.h
index d8a1e7a..820b16b 100644
--- a/src/modules/ray/ray_scene.h
+++ b/src/modules/ray/ray_scene.h
@@ -10,14 +10,18 @@
typedef union ray_object_t ray_object_t;
typedef struct ray_scene_t {
- ray_object_t *objects;
- unsigned n_objects;
+ ray_object_t *objects;
+ unsigned n_objects;
- ray_object_t *lights;
- unsigned n_lights;
+ ray_object_t *lights;
+ unsigned n_lights;
- ray_color_t ambient_color;
- float ambient_brightness;
+ ray_color_t ambient_color;
+ float ambient_brightness;
+
+ struct {
+ ray_color_t ambient_light;
+ } _prepared;
} ray_scene_t;
void ray_scene_prepare(ray_scene_t *scene);
© All Rights Reserved