summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-02 04:53:15 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-02 04:53:15 +0000
commitc1accd2356394e8c905cc7de2eb6b8c453157708 (patch)
treed1ba4b76a7b3f56bbd1c6316afd86f674c6b1639
parentc6f889eb183f83fa125082abdb6edba60c4e0907 (diff)
downloaddimension-c1accd2356394e8c905cc7de2eb6b8c453157708.tar.xz
Color objects different colors when raytracing.
-rw-r--r--libdimension/raytrace.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 2f7251f..21dfcb9 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -196,7 +196,7 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
dmnsn_line ray, ray_trans;
dmnsn_array *intersections;
dmnsn_color color;
- dmnsn_sRGB sRGB;
+ dmnsn_CIE_Lab Lab;
width = scene->canvas->x;
height = scene->canvas->y;
@@ -225,17 +225,23 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
/* Find the closest intersection */
for (j = 0; j < dmnsn_array_size(intersections); ++j) {
dmnsn_array_get(intersections, j, &t_temp);
- if ((t_temp < t && t_temp >= 0.0) || t < 0.0) t = t_temp;
+ if ((t_temp < t && t_temp >= 0.0) || t < 0.0) {
+ t = t_temp;
+
+ /* Color each object differently */
+ Lab.a = sin((double)(i + 2));
+ Lab.b = cos((double)(i + 2));
+ }
}
dmnsn_delete_array(intersections);
}
/* Shade according to distance from camera */
if (t >= 0.0) {
- sRGB.R = 1.0 - (t - 2.25)/2.25;
- sRGB.G = sRGB.R;
- sRGB.B = sRGB.R;
- color = dmnsn_color_from_sRGB(sRGB);
+ Lab.L = 100.0*(1.0 - (t - 2.25)/2.25);
+ Lab.a *= Lab.L;
+ Lab.b *= Lab.L;
+ color = dmnsn_color_from_Lab(Lab, dmnsn_whitepoint);
}
dmnsn_set_pixel(scene->canvas, x, y, color);