summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-09-16 09:35:20 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-09-17 17:58:07 -0700
commitfc1a7bc862121c81a4b1e6075c9c0d3381e2f1bb (patch)
tree4696e54fda172b4310f608dc8fa860def31b0a52
parent337440d4a0f141c036e057ecc4fe4f4b808ff9c0 (diff)
ray: stop recurring below a relevance threshold
There's no point computing more reflections if they're not going to contribute substantially to the resulting sample. Previously the max depth threshold solely controlled how many times a given ray could reflect, this commit introduces a minimum relevance as well. Value may require tuning, may actually make sense to move into the scene description as a parameter. Brings a minor frame rate improvement.
-rw-r--r--src/modules/ray/ray_scene.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/modules/ray/ray_scene.c b/src/modules/ray/ray_scene.c
index f78ed3e..21a3bfa 100644
--- a/src/modules/ray/ray_scene.c
+++ b/src/modules/ray/ray_scene.c
@@ -10,7 +10,7 @@
#include "ray_scene.h"
#define MAX_RECURSION_DEPTH 4
-
+#define MIN_RELEVANCE 0.05f
/* Determine if the ray is obstructed by an object within the supplied distance, for shadows */
@@ -163,8 +163,6 @@ static inline ray_color_t trace_ray(ray_scene_t *scene, ray_ray_t *primary_ray)
reflected_ray.direction = new_direction;
ray = &reflected_ray;
-
- relevance *= reflectivity;
}
nearest_object = find_nearest_intersection(scene, reflector, ray, depth, &nearest_distance);
@@ -182,7 +180,7 @@ static inline ray_color_t trace_ray(ray_scene_t *scene, ray_ray_t *primary_ray)
}
reflector = nearest_object;
- } while (reflector && (++depth < MAX_RECURSION_DEPTH));
+ } while (reflector && (++depth < MAX_RECURSION_DEPTH) && (relevance *= reflectivity) >= MIN_RELEVANCE);
return color;
}
© All Rights Reserved