diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-19 20:30:14 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-19 20:31:06 -0500 |
commit | d47af986a7832add1c149235f44fa8f57b56e6d8 (patch) | |
tree | 40fbd4a5e84afa188c2f23a7727d3d9d2acb6840 /libdimension/raytrace.c | |
parent | 6137aed0179476eaa626660885f01ea3f04f988a (diff) | |
download | dimension-d47af986a7832add1c149235f44fa8f57b56e6d8.tar.xz |
Implement sky spheres.
Diffstat (limited to 'libdimension/raytrace.c')
-rw-r--r-- | libdimension/raytrace.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index e6596e4..3534331 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -77,13 +77,11 @@ dmnsn_raytrace_scene_thread(void *ptr) { dmnsn_raytrace_payload *payload = ptr; + /* Pre-calculate bounding box transformations, etc. */ + dmnsn_scene_init(payload->scene); + /* Time the bounding tree construction */ payload->scene->bounding_timer = dmnsn_new_timer(); - /* Pre-calculate bounding box transformations, etc. */ - DMNSN_ARRAY_FOREACH (dmnsn_object **, object, payload->scene->objects) { - dmnsn_object_init(*object); - } - payload->prtree = dmnsn_new_prtree(payload->scene->objects); dmnsn_complete_timer(payload->scene->bounding_timer); @@ -210,21 +208,16 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, /* Iterate through each pixel */ for (size_t y = index; y < scene->canvas->height; y += threads) { for (size_t x = 0; x < scene->canvas->width; ++x) { - /* Set the pixel to the background color */ - dmnsn_color color = scene->background; - - if (scene->quality) { - /* Get the ray corresponding to the (x,y)'th pixel */ - dmnsn_line ray = dmnsn_camera_ray( - scene->camera, - ((double)x)/(scene->canvas->width - 1), - ((double)y)/(scene->canvas->height - 1) - ); + /* Get the ray corresponding to the (x,y)'th pixel */ + dmnsn_line ray = dmnsn_camera_ray( + scene->camera, + ((double)x)/(scene->canvas->width - 1), + ((double)y)/(scene->canvas->height - 1) + ); - /* Shoot a ray */ - state.reclevel = scene->reclimit; - color = dmnsn_raytrace_shoot(&state, ray); - } + /* Shoot a ray */ + state.reclevel = scene->reclimit; + dmnsn_color color = dmnsn_raytrace_shoot(&state, ray); dmnsn_set_pixel(scene->canvas, x, y, color); } @@ -272,6 +265,22 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, ? (state)->intersection->interior->ior \ : 1.0) +/** Calculate the background color. */ +static dmnsn_color +dmnsn_raytrace_background(dmnsn_raytrace_state *state, dmnsn_line ray) +{ + dmnsn_color color = state->scene->background; + if (state->scene->sky_sphere + && (state->scene->quality & DMNSN_RENDER_PIGMENT)) + { + dmnsn_color sky = dmnsn_sky_sphere_color(state->scene->sky_sphere, + dmnsn_vector_normalize(ray.n)); + color = dmnsn_color_add(dmnsn_color_filter(color, sky), sky); + } + + return color; +} + /** Calculate the base pigment at the intersection. */ static void dmnsn_raytrace_pigment(dmnsn_raytrace_state *state) @@ -465,12 +474,11 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) return dmnsn_black; --state->reclevel; - dmnsn_intersection intersection; - bool intersected - = dmnsn_prtree_intersection(state->prtree, ray, &intersection); + /* Calculate the background color */ + dmnsn_color color = dmnsn_raytrace_background(state, ray); - dmnsn_color color = state->scene->background; - if (intersected) { + dmnsn_intersection intersection; + if (dmnsn_prtree_intersection(state->prtree, ray, &intersection)) { state->intersection = &intersection; state->r = dmnsn_line_point(state->intersection->ray, state->intersection->t); |