diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-08-18 20:17:37 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-08-18 20:17:37 -0600 |
commit | 9c9fb9d59c2e90fc2bc9066dac514285c9479277 (patch) | |
tree | df0d64d60cb933698054b41312167a790f5787cd /libdimension/color.c | |
parent | 6766ce89672897cabe48e48798b29dc3a461f1da (diff) | |
download | dimension-9c9fb9d59c2e90fc2bc9066dac514285c9479277.tar.xz |
Handle reflection of light and transmitted rays.
Diffstat (limited to 'libdimension/color.c')
-rw-r--r-- | libdimension/color.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libdimension/color.c b/libdimension/color.c index 02ecff9..ad9ec0a 100644 --- a/libdimension/color.c +++ b/libdimension/color.c @@ -197,6 +197,29 @@ dmnsn_color_add(dmnsn_color c1, dmnsn_color c2) return ret; } +/* Subtract two colors */ +dmnsn_color +dmnsn_color_sub(dmnsn_color c1, dmnsn_color c2) +{ + dmnsn_color ret = dmnsn_new_color(c1.R - c2.R, c1.G - c2.G, c1.B - c2.B); + + /* Switch into absolute filter and transmittance space */ + double n1 = dmnsn_color_intensity(c1), n2 = dmnsn_color_intensity(c2); + double f1 = c1.filter*c1.trans, f2 = c2.filter*c2.trans; + double t1 = c1.trans - f1, t2 = c2.trans - f2; + double f = 0.0; + if (n1 - n2 >= dmnsn_epsilon) + f = (n1*f1 - n2*f2)/(n1 - n2); + double t = t1 - t2; + + /* Switch back */ + ret.trans = f + t; + if (ret.trans >= dmnsn_epsilon) + ret.filter = f/ret.trans; + + return ret; +} + /* Multiply a color by a scalar */ dmnsn_color dmnsn_color_mul(double n, dmnsn_color color) |