From 9cc3fef27ba1c23b2b935b6f81cf15dc9159fe3a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 20 Apr 2011 22:39:41 -0400 Subject: Cache previous intersections in dmnsn_prtree_intersection(). Due to geometric locality of rays, this provides a very large speedup for most scenes. --- libdimension/raytrace.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libdimension/raytrace.c') diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 7a797bf..a35b1e6 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -253,10 +253,10 @@ dmnsn_raytrace_light_ray(const dmnsn_raytrace_state *state, dmnsn_color color = light->light_fn(light, state->r); unsigned int reclevel = state->reclevel; - while (reclevel) { + while (reclevel > 0) { dmnsn_intersection shadow_caster; - bool shadow_casted - = dmnsn_prtree_intersection(state->prtree, shadow_ray, &shadow_caster); + bool shadow_casted = dmnsn_prtree_intersection(state->prtree, shadow_ray, + &shadow_caster, false); if (!shadow_casted || shadow_caster.t > 1.0) { break; @@ -416,7 +416,8 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) dmnsn_color color = dmnsn_raytrace_background(state, ray); dmnsn_intersection intersection; - if (dmnsn_prtree_intersection(state->prtree, ray, &intersection)) { + bool reset = state->reclevel == state->scene->reclimit - 1; + if (dmnsn_prtree_intersection(state->prtree, ray, &intersection, reset)) { state->intersection = &intersection; state->r = dmnsn_line_point(state->intersection->ray, state->intersection->t); -- cgit v1.2.3