diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-09 21:36:35 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-09 21:37:59 -0500 |
commit | 531368437bfb865247204fa78235428028170081 (patch) | |
tree | 151c642f624abe8c892532fb280fde08fa5e5d80 | |
parent | ccaf1d7af81223169fba71fe613f439df87b6fd3 (diff) | |
download | dimension-531368437bfb865247204fa78235428028170081.tar.xz |
Correct dmnsn_color_illuminate().
-rw-r--r-- | libdimension/color.c | 28 | ||||
-rw-r--r-- | libdimension/raytrace.c | 2 | ||||
-rw-r--r-- | tests/libdimension/tests.c | 2 |
3 files changed, 20 insertions, 12 deletions
diff --git a/libdimension/color.c b/libdimension/color.c index 4589824..2089326 100644 --- a/libdimension/color.c +++ b/libdimension/color.c @@ -301,15 +301,23 @@ dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color) dmnsn_CIE_Lab Lab1 = dmnsn_Lab_from_color(light, dmnsn_whitepoint); dmnsn_CIE_Lab Lab2 = dmnsn_Lab_from_color(color, dmnsn_whitepoint); - double dot = Lab1.L*Lab2.L + Lab1.a*Lab2.a + Lab1.b*Lab2.b; - double norm = sqrt(Lab2.L*Lab2.L + Lab2.a*Lab2.a + Lab2.b*Lab2.b); - - if (norm == 0.0) - return dmnsn_black; - - dmnsn_CIE_Lab Lab = { .L = dot*Lab2.L/norm/100.0, - .a = dot*Lab2.a/norm, - .b = dot*Lab2.b/norm }; + /* + * This is derived from the simple illumination equation for RGB color: + * RGB' = (R_light*R_color, G_light*G_color, B_light*B_color) + * + * CIE L*a*b* may be transformed to an RGB colorspace by considering `a' + * to be the green -> magenta opponent process (from negative to positive), + * and `b' to be the blue -> yellow opponent process: + * RGB = (L + a + b, L - a + b, L + a - b) + * + * The reverse transformation is: + * Lab = ((G + B)/2, (R - G)/2, (R - B)/2) + */ + dmnsn_CIE_Lab Lab = { + .L = (Lab1.L*Lab2.L + (Lab1.b - Lab1.a)*(Lab2.b - Lab2.a))/100.0, + .a = (Lab1.a*(Lab2.L + Lab2.b) + Lab2.a*(Lab1.L + Lab1.b))/100.0, + .b = (Lab1.b*(Lab2.L + Lab2.a) + Lab2.b*(Lab1.L + Lab1.a))/100.0 + }; dmnsn_color ret = dmnsn_color_from_Lab(Lab, dmnsn_whitepoint); ret.filter = color.filter; @@ -318,7 +326,7 @@ dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color) return ret; } -/* Find the perceptual difference between two colors, using CIE L*a*b*. */ +/* Find the perceptual difference between two colors, using CIE L*a*b* */ double dmnsn_color_difference(dmnsn_color color1, dmnsn_color color2) { diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 63385a7..74bfefc 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -295,7 +295,7 @@ dmnsn_raytrace_shadow(dmnsn_intersection *intersection, dmnsn_scene *scene, finish = texture->finish ? texture->finish : scene->default_texture->finish; } - dmnsn_color illum = dmnsn_color_mul(0.3, color); + dmnsn_color illum = dmnsn_color_mul(0.1, color); const dmnsn_light *light; unsigned int i; diff --git a/tests/libdimension/tests.c b/tests/libdimension/tests.c index 1e8cd5c..5daa5be 100644 --- a/tests/libdimension/tests.c +++ b/tests/libdimension/tests.c @@ -116,7 +116,7 @@ dmnsn_new_default_scene() dmnsn_light *light = dmnsn_new_point_light( dmnsn_vector_construct(-5.0, 20.0, -5.0), - dmnsn_color_mul(0.9, dmnsn_white) + dmnsn_white ); if (!light) { dmnsn_delete_scene(scene); |