From fc1a7bc862121c81a4b1e6075c9c0d3381e2f1bb Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 16 Sep 2017 09:35:20 -0700 Subject: 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. --- src/modules/ray/ray_scene.c | 6 ++---- 1 file 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; } -- cgit v1.2.3