summaryrefslogtreecommitdiffstats
path: root/libdimension/raytrace.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-04-20 22:39:41 -0400
committerTavian Barnes <tavianator@gmail.com>2011-04-20 22:43:17 -0400
commit9cc3fef27ba1c23b2b935b6f81cf15dc9159fe3a (patch)
treef31cf4d59c104fff165177b4881175bf77b03aba /libdimension/raytrace.c
parent5c9680634b2999afdf43eaef5f367e98d3888f96 (diff)
downloaddimension-9cc3fef27ba1c23b2b935b6f81cf15dc9159fe3a.tar.xz
Cache previous intersections in dmnsn_prtree_intersection().
Due to geometric locality of rays, this provides a very large speedup for most scenes.
Diffstat (limited to 'libdimension/raytrace.c')
-rw-r--r--libdimension/raytrace.c9
1 files changed, 5 insertions, 4 deletions
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);