diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2011-12-02 20:57:37 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2011-12-02 20:57:37 +0400 |
commit | 4fd273648767a736f79acd3edc3d7f332129b46f (patch) | |
tree | 4f37b89622cd0e422c7b1579197b838ab852ce32 /intern/cycles/kernel/osl/nodes/node_color.h | |
parent | f96aad6688a695c692e9f784314d8eb4e169e6da (diff) |
HSV Color Node for Cycles
.........................
note, the OSL code has a problem.
In the original node the input and output nodes have the same name (Color).
So this will be fixed here once Brecht come up with a nice autorenaming (or we do a doversion patch) for that.
Diffstat (limited to 'intern/cycles/kernel/osl/nodes/node_color.h')
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_color.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/nodes/node_color.h b/intern/cycles/kernel/osl/nodes/node_color.h index b92973d1dfe..37d092eae78 100644 --- a/intern/cycles/kernel/osl/nodes/node_color.h +++ b/intern/cycles/kernel/osl/nodes/node_color.h @@ -48,3 +48,78 @@ color color_scene_linear_to_srgb(color c) color_scene_linear_to_srgb(c[2])); } +/* Color Operations */ + +color rgb_to_hsv(color rgb) +{ + float cmax, cmin, h, s, v, cdelta; + color c; + + cmax = max(rgb[0], max(rgb[1], rgb[2])); + cmin = min(rgb[0], min(rgb[1], rgb[2])); + cdelta = cmax - cmin; + + v = cmax; + + if(cmax != 0.0) { + s = cdelta/cmax; + } + else { + s = 0.0; + h = 0.0; + } + + if(s == 0.0) { + h = 0.0; + } + else { + c = (color(cmax, cmax, cmax) - rgb)/cdelta; + + if(rgb[0] == cmax) h = c[2] - c[1]; + else if(rgb[1] == cmax) h = 2.0 + c[0] - c[2]; + else h = 4.0 + c[1] - c[0]; + + h /= 6.0; + + if(h < 0.0) + h += 1.0; + } + + return color(h, s, v); +} + +color hsv_to_rgb(color hsv) +{ + float i, f, p, q, t, h, s, v; + color rgb; + + h = hsv[0]; + s = hsv[1]; + v = hsv[2]; + + if(s==0.0) { + rgb = color(v, v, v); + } + else { + if(h==1.0) + h = 0.0; + + h *= 6.0; + i = floor(h); + f = h - i; + rgb = color(f, f, f); + p = v*(1.0-s); + q = v*(1.0-(s*f)); + t = v*(1.0-(s*(1.0-f))); + + if(i == 0.0) rgb = color(v, t, p); + else if(i == 1.0) rgb = color(q, v, p); + else if(i == 2.0) rgb = color(p, v, t); + else if(i == 3.0) rgb = color(p, q, v); + else if(i == 4.0) rgb = color(t, p, v); + else rgb = color(v, p, q); + } + + return rgb; +} + |