summaryrefslogtreecommitdiffstats
path: root/libdimension/raytrace.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-16 01:49:40 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-16 01:49:40 +0000
commit90564274757e489429daf8bcdb92009563fd2efd (patch)
tree854503bb591bcd73b4244cd622a6692a815a16b8 /libdimension/raytrace.c
parent6b4dc860466ce4794b346533162291046a6ee96c (diff)
downloaddimension-90564274757e489429daf8bcdb92009563fd2efd.tar.xz
Render pigments.
Diffstat (limited to 'libdimension/raytrace.c')
-rw-r--r--libdimension/raytrace.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 10f400d..c9217ca 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -185,7 +185,7 @@ dmnsn_raytrace_scene_multithread_thread(void *ptr)
/* Helper for dmnsn_raytrace_scene_impl - shoot a ray */
static dmnsn_color dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color,
- unsigned int x, unsigned int y);
+ dmnsn_line ray);
/*
* Actually raytrace a scene
@@ -196,6 +196,7 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
{
unsigned int x, y;
unsigned int width, height;
+ dmnsn_line ray;
dmnsn_color color;
width = scene->canvas->x;
@@ -211,7 +212,10 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
color = scene->background;
if (scene->quality >= DMNSN_RENDER_OBJECTS) {
- color = dmnsn_raytrace_shoot(scene, color, x, y);
+ /* Get the ray corresponding to the (x,y)'th pixel */
+ ray = (*scene->camera->ray_fn)(scene->camera, scene->canvas, x, y);
+ /* Shoot a ray */
+ color = dmnsn_raytrace_shoot(scene, color, ray);
}
dmnsn_set_pixel(scene->canvas, x, y, color);
@@ -225,17 +229,13 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
/* Shoot a ray, and calculate the color, using `color' as the background */
static dmnsn_color
-dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color,
- unsigned int x, unsigned int y)
+dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color, dmnsn_line ray)
{
- dmnsn_line ray, ray_trans;
+ dmnsn_line ray_trans;
dmnsn_object *object;
- dmnsn_intersection *intersection;
+ dmnsn_intersection *intersection = NULL, *intersection_temp;
unsigned int i;
- /* Get the ray corresponding to the (x,y)'th pixel */
- ray = (*scene->camera->ray_fn)(scene->camera, scene->canvas, x, y);
-
for (i = 0; i < dmnsn_array_size(scene->objects); ++i) {
dmnsn_array_get(scene->objects, i, &object);
@@ -243,13 +243,33 @@ dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color,
ray_trans = dmnsn_matrix_line_mul(object->trans, ray);
/* Test for intersections with objects */
- intersection = (*object->intersection_fn)(object, ray_trans);
+ intersection_temp = (*object->intersection_fn)(object, ray_trans);
+
+ if (intersection_temp &&
+ (!intersection || intersection_temp->t < intersection->t)) {
+ dmnsn_delete_intersection(intersection);
+ intersection = intersection_temp;
+ }
+ }
- if (intersection) {
- color = dmnsn_color_from_XYZ(dmnsn_whitepoint);
+ if (intersection) {
+ if (scene->quality >= DMNSN_RENDER_PIGMENT) {
+ if (intersection->texture) {
+ if (intersection->texture->pigment) {
+ color = (*intersection->texture->pigment->pigment_fn)(
+ intersection->texture->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);
}