[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42345] trunk/blender: HSV Color Node for Cycles
Dalai Felinto
dfelinto at gmail.com
Fri Dec 2 17:57:37 CET 2011
Revision: 42345
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42345
Author: dfelinto
Date: 2011-12-02 16:57:37 +0000 (Fri, 02 Dec 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/intern/cycles/app/cycles_xml.cpp
trunk/blender/intern/cycles/blender/blender_shader.cpp
trunk/blender/intern/cycles/kernel/CMakeLists.txt
trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
trunk/blender/intern/cycles/kernel/osl/nodes/node_color.h
trunk/blender/intern/cycles/kernel/osl/nodes/node_mix.osl
trunk/blender/intern/cycles/kernel/svm/svm.h
trunk/blender/intern/cycles/kernel/svm/svm_mix.h
trunk/blender/intern/cycles/kernel/svm/svm_types.h
trunk/blender/intern/cycles/render/nodes.cpp
trunk/blender/intern/cycles/render/nodes.h
trunk/blender/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c
Added Paths:
-----------
trunk/blender/intern/cycles/kernel/osl/nodes/node_hsv.osl
trunk/blender/intern/cycles/kernel/svm/svm_hsv.h
Modified: trunk/blender/intern/cycles/app/cycles_xml.cpp
===================================================================
--- trunk/blender/intern/cycles/app/cycles_xml.cpp 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/app/cycles_xml.cpp 2011-12-02 16:57:37 UTC (rev 42345)
@@ -446,6 +446,9 @@
else if(string_iequals(node.name(), "separate_rgb")) {
snode = new SeparateRGBNode();
}
+ else if(string_iequals(node.name(), "hsv")) {
+ snode = new HSVNode();
+ }
else if(string_iequals(node.name(), "attribute")) {
AttributeNode *attr = new AttributeNode();
xml_read_ustring(&attr->attribute, node, "attribute");
Modified: trunk/blender/intern/cycles/blender/blender_shader.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_shader.cpp 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/blender/blender_shader.cpp 2011-12-02 16:57:37 UTC (rev 42345)
@@ -131,7 +131,6 @@
case BL::ShaderNode::type_CURVE_RGB: break;
case BL::ShaderNode::type_CURVE_VEC: break;
case BL::ShaderNode::type_GEOMETRY: break;
- case BL::ShaderNode::type_HUE_SAT: break;
case BL::ShaderNode::type_INVERT: break;
case BL::ShaderNode::type_MATERIAL: break;
case BL::ShaderNode::type_MATERIAL_EXT: break;
@@ -171,6 +170,10 @@
node = new CombineRGBNode();
break;
}
+ case BL::ShaderNode::type_HUE_SAT: {
+ node = new HSVNode();
+ break;
+ }
case BL::ShaderNode::type_RGBTOBW: {
node = new ConvertNode(SHADER_SOCKET_COLOR, SHADER_SOCKET_FLOAT);
break;
Modified: trunk/blender/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/CMakeLists.txt 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/kernel/CMakeLists.txt 2011-12-02 16:57:37 UTC (rev 42345)
@@ -60,6 +60,7 @@
svm/svm_fresnel.h
svm/svm_geometry.h
svm/svm_gradient.h
+ svm/svm_hsv.h
svm/svm_image.h
svm/svm_light_path.h
svm/svm_magic.h
Modified: trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt 2011-12-02 16:57:37 UTC (rev 42345)
@@ -21,6 +21,7 @@
node_geometry.osl
node_glass_bsdf.osl
node_glossy_bsdf.osl
+ node_hsv.osl
node_image_texture.osl
node_light_path.osl
node_magic_texture.osl
Modified: trunk/blender/intern/cycles/kernel/osl/nodes/node_color.h
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_color.h 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_color.h 2011-12-02 16:57:37 UTC (rev 42345)
@@ -48,3 +48,78 @@
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;
+}
+
Added: trunk/blender/intern/cycles/kernel/osl/nodes/node_hsv.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_hsv.osl (rev 0)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_hsv.osl 2011-12-02 16:57:37 UTC (rev 42345)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "stdosl.h"
+#include "node_color.h"
+
+shader node_hsv(
+ float Hue = 0.5,
+ float Saturation = 1.0,
+ float Value = 1.0,
+ float Fac = 0.5,
+ color ColorIn = color(0.0, 0.0, 0.0),
+ output color ColorOut = color(0.0, 0.0, 0.0))
+{
+ float t = clamp(Fac, 0.0, 1.0);
+ color Color = rgb_to_hsv(ColorIn);
+
+ Color[0] += Hue - 0.5;
+ Color[0] = fmod(Color[0], 1.0);
+ Color[1] *= Saturation;
+ Color[2] *= Value;
+
+ Color = hsv_to_rgb(Color);
+
+ ColorOut = mix(Color, ColorIn, t);
+}
+
Modified: trunk/blender/intern/cycles/kernel/osl/nodes/node_mix.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_mix.osl 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_mix.osl 2011-12-02 16:57:37 UTC (rev 42345)
@@ -17,80 +17,8 @@
*/
#include "stdosl.h"
+#include "node_color.h"
-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;
-}
-
color node_mix_blend(float t, color col1, color col2)
{
return mix(col1, col2, t);
Modified: trunk/blender/intern/cycles/kernel/svm/svm.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm.h 2011-12-02 16:57:22 UTC (rev 42344)
+++ trunk/blender/intern/cycles/kernel/svm/svm.h 2011-12-02 16:57:37 UTC (rev 42345)
@@ -127,6 +127,7 @@
#include "svm_displace.h"
#include "svm_fresnel.h"
#include "svm_geometry.h"
+#include "svm_hsv.h"
#include "svm_image.h"
#include "svm_light_path.h"
#include "svm_magic.h"
@@ -261,6 +262,9 @@
case NODE_COMBINE_RGB:
svm_node_combine_rgb(sd, stack, node.y, node.z, node.w);
break;
+ case NODE_HSV:
+ svm_node_hsv(kg, sd, stack, node.y, node.z, node.w, &offset);
+ break;
case NODE_ATTR:
svm_node_attr(kg, sd, stack, node);
break;
Added: trunk/blender/intern/cycles/kernel/svm/svm_hsv.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_hsv.h (rev 0)
+++ trunk/blender/intern/cycles/kernel/svm/svm_hsv.h 2011-12-02 16:57:37 UTC (rev 42345)
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __SVM_HSV_H__
+#define __SVM_HSV_H__
+
+CCL_NAMESPACE_BEGIN
+
+__device float3 rgb_to_hsv(float3 rgb)
+{
+ float cmax, cmin, h, s, v, cdelta;
+ float3 c;
+
+ cmax = fmaxf(rgb.x, fmaxf(rgb.y, rgb.z));
+ cmin = min(rgb.x, min(rgb.y, rgb.z));
+ cdelta = cmax - cmin;
+
+ v = cmax;
+
+ if(cmax != 0.0f) {
+ s = cdelta/cmax;
+ }
+ else {
+ s = 0.0f;
+ h = 0.0f;
+ }
+
+ if(s == 0.0f) {
+ h = 0.0f;
+ }
+ else {
+ float3 cmax3 = make_float3(cmax, cmax, cmax);
+ c = (cmax3 - rgb)/cdelta;
+
+ if(rgb.x == cmax) h = c.z - c.y;
+ else if(rgb.y == cmax) h = 2.0f + c.x - c.z;
+ else h = 4.0f + c.y - c.x;
+
+ h /= 6.0f;
+
+ if(h < 0.0f)
+ h += 1.0f;
+ }
+
+ return make_float3(h, s, v);
+}
+
+__device float3 hsv_to_rgb(float3 hsv)
+{
+ float i, f, p, q, t, h, s, v;
+ float3 rgb;
+
+ h = hsv.x;
+ s = hsv.y;
+ v = hsv.z;
+
+ if(s==0.0f) {
+ rgb = make_float3(v, v, v);
+ }
+ else {
+ if(h==1.0f)
+ h = 0.0f;
+
+ h *= 6.0f;
+ i = floor(h);
+ f = h - i;
+ rgb = make_float3(f, f, f);
+ p = v*(1.0f-s);
+ q = v*(1.0f-(s*f));
+ t = v*(1.0f-(s*(1.0f-f)));
+
+ if(i == 0.0f) rgb = make_float3(v, t, p);
+ else if(i == 1.0f) rgb = make_float3(q, v, p);
+ else if(i == 2.0f) rgb = make_float3(p, v, t);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list