From 7e7ec10dea751540eda7898cf83f8471185aa063 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 16 Jul 2009 18:25:02 +0000 Subject: Add support for default textures. --- libdimension/raytrace.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'libdimension/raytrace.c') diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index c9217ca..470af4f 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -234,6 +234,8 @@ dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color, dmnsn_line ray) dmnsn_line ray_trans; dmnsn_object *object; dmnsn_intersection *intersection = NULL, *intersection_temp; + const dmnsn_texture *texture; + const dmnsn_pigment *pigment; unsigned int i; for (i = 0; i < dmnsn_array_size(scene->objects); ++i) { @@ -245,6 +247,7 @@ dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color, dmnsn_line ray) /* Test for intersections with objects */ intersection_temp = (*object->intersection_fn)(object, ray_trans); + /* Find the closest intersection to the camera */ if (intersection_temp && (!intersection || intersection_temp->t < intersection->t)) { dmnsn_delete_intersection(intersection); @@ -253,23 +256,29 @@ dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color, dmnsn_line ray) } if (intersection) { + /* Default to black if we have no texture/pigment */ + color = dmnsn_black; + if (scene->quality >= DMNSN_RENDER_PIGMENT) { - if (intersection->texture) { - if (intersection->texture->pigment) { - color = (*intersection->texture->pigment->pigment_fn)( - intersection->texture->pigment, + /* Use the default texture if given a NULL texture */ + texture = intersection->texture ? intersection->texture + : scene->default_texture; + + if (texture) { + /* Use the default pigment if given a NULL pigment */ + pigment = texture->pigment ? texture->pigment + : scene->default_texture->pigment; + + if (pigment) { + color = (*pigment->pigment_fn)( + pigment, dmnsn_line_point(intersection->ray, intersection->t) ); - } else { - color = dmnsn_black; } - } else { - color = dmnsn_black; } - } else { - color = dmnsn_white; } + /* Delete the intersection */ dmnsn_delete_intersection(intersection); } -- cgit v1.2.3