Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-12-11 18:39:37 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-12-11 18:39:37 +0400
commit43c04eefe32773b708d85ea0db95564e71f4870e (patch)
treeadcbc13cd57ce4f48f7fc26e123e3ca11c71cb2c /intern
parent7c81952179f0ff08cfdd8f571eb1c0f06e224070 (diff)
Cycles: RGB and Vector Curves nodes now supported, with the limitation that the
range must be left to the default (0..1 and -1..1).
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/blender_shader.cpp14
-rw-r--r--intern/cycles/blender/blender_util.h30
-rw-r--r--intern/cycles/kernel/shaders/CMakeLists.txt2
-rw-r--r--intern/cycles/kernel/shaders/node_rgb_curves.osl53
-rw-r--r--intern/cycles/kernel/shaders/node_vector_curves.osl53
-rw-r--r--intern/cycles/kernel/svm/svm.h3
-rw-r--r--intern/cycles/kernel/svm/svm_ramp.h25
-rw-r--r--intern/cycles/kernel/svm/svm_types.h1
-rw-r--r--intern/cycles/render/nodes.cpp47
-rw-r--r--intern/cycles/render/nodes.h6
10 files changed, 228 insertions, 6 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index c9380d8d58b..848a9a199f9 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -173,7 +173,6 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
switch(b_node.type()) {
/* not supported */
- case BL::ShaderNode::type_CURVE_VEC: break;
case BL::ShaderNode::type_GEOMETRY: break;
case BL::ShaderNode::type_MATERIAL: break;
case BL::ShaderNode::type_MATERIAL_EXT: break;
@@ -193,9 +192,18 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
node = proxy;
break;
}
+ case BL::ShaderNode::type_CURVE_VEC: {
+ BL::ShaderNodeVectorCurve b_curve_node(b_node);
+ VectorCurvesNode *curves = new VectorCurvesNode();
+ curvemapping_color_to_array(b_curve_node.mapping(), curves->curves, RAMP_TABLE_SIZE, false);
+ node = curves;
+ break;
+ }
case BL::ShaderNode::type_CURVE_RGB: {
- RGBCurvesNode *ramp = new RGBCurvesNode();
- node = ramp;
+ BL::ShaderNodeRGBCurve b_curve_node(b_node);
+ RGBCurvesNode *curves = new RGBCurvesNode();
+ curvemapping_color_to_array(b_curve_node.mapping(), curves->curves, RAMP_TABLE_SIZE, true);
+ node = curves;
break;
}
case BL::ShaderNode::type_VALTORGB: {
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 0a9f2dd06aa..fbcbe15ec5a 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -52,6 +52,36 @@ static inline void colorramp_to_array(BL::ColorRamp ramp, float4 *data, int size
}
}
+static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *data, int size, bool rgb_curve)
+{
+ cumap.update();
+
+ BL::CurveMap mapR = cumap.curves[0];
+ BL::CurveMap mapG = cumap.curves[1];
+ BL::CurveMap mapB = cumap.curves[2];
+
+ if(rgb_curve) {
+ BL::CurveMap mapI = cumap.curves[3];
+
+ for(int i = 0; i < size; i++) {
+ float t = i/(float)(size-1);
+
+ data[i][0] = mapR.evaluate(mapI.evaluate(t));
+ data[i][1] = mapG.evaluate(mapI.evaluate(t));
+ data[i][2] = mapB.evaluate(mapI.evaluate(t));
+ }
+ }
+ else {
+ for(int i = 0; i < size; i++) {
+ float t = i/(float)(size-1);
+
+ data[i][0] = mapR.evaluate(t);
+ data[i][1] = mapG.evaluate(t);
+ data[i][2] = mapB.evaluate(t);
+ }
+ }
+}
+
static inline bool BKE_object_is_modified(BL::Object self, BL::Scene scene, bool preview)
{
return self.is_modified(scene, (preview)? (1<<0): (1<<1))? true: false;
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt
index f7fec62fd6d..70fc8610c98 100644
--- a/intern/cycles/kernel/shaders/CMakeLists.txt
+++ b/intern/cycles/kernel/shaders/CMakeLists.txt
@@ -49,6 +49,7 @@ set(SRC_OSL
node_output_volume.osl
node_particle_info.osl
node_refraction_bsdf.osl
+ node_rgb_curves.osl
node_rgb_ramp.osl
node_separate_rgb.osl
node_set_normal.osl
@@ -58,6 +59,7 @@ set(SRC_OSL
node_translucent_bsdf.osl
node_transparent_bsdf.osl
node_value.osl
+ node_vector_curves.osl
node_vector_math.osl
node_velvet_bsdf.osl
node_voronoi_texture.osl
diff --git a/intern/cycles/kernel/shaders/node_rgb_curves.osl b/intern/cycles/kernel/shaders/node_rgb_curves.osl
new file mode 100644
index 00000000000..baa1d5c3de4
--- /dev/null
+++ b/intern/cycles/kernel/shaders/node_rgb_curves.osl
@@ -0,0 +1,53 @@
+/*
+ * 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 "oslutil.h"
+
+float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component)
+{
+ float f = clamp(at, 0.0, 1.0) * (RAMP_TABLE_SIZE - 1);
+
+ /* clamp int as well in case of NaN */
+ int i = (int)f;
+ if (i < 0) i = 0;
+ if (i >= RAMP_TABLE_SIZE) i = RAMP_TABLE_SIZE - 1;
+ float t = f - (float)i;
+
+ float result = ramp[i][component];
+
+ if (t > 0.0)
+ result = (1.0 - t) * result + t * ramp[i + 1][component];
+
+ return result;
+}
+
+shader node_rgb_curves(
+ color ramp[RAMP_TABLE_SIZE] = {0.0},
+
+ color ColorIn = color(0.0, 0.0, 0.0),
+ float Fac = 0.0,
+ output color ColorOut = color(0.0, 0.0, 0.0))
+{
+ ColorOut[0] = ramp_lookup(ramp, ColorIn[0], 0);
+ ColorOut[1] = ramp_lookup(ramp, ColorIn[1], 1);
+ ColorOut[2] = ramp_lookup(ramp, ColorIn[2], 2);
+
+ ColorOut = mix(ColorIn, ColorOut, Fac);
+}
+
diff --git a/intern/cycles/kernel/shaders/node_vector_curves.osl b/intern/cycles/kernel/shaders/node_vector_curves.osl
new file mode 100644
index 00000000000..94082287f4d
--- /dev/null
+++ b/intern/cycles/kernel/shaders/node_vector_curves.osl
@@ -0,0 +1,53 @@
+/*
+ * 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 "oslutil.h"
+
+float ramp_lookup(color ramp[RAMP_TABLE_SIZE], float at, int component)
+{
+ float f = clamp((at + 1.0)*0.5, 0.0, 1.0) * (RAMP_TABLE_SIZE - 1);
+
+ /* clamp int as well in case of NaN */
+ int i = (int)f;
+ if (i < 0) i = 0;
+ if (i >= RAMP_TABLE_SIZE) i = RAMP_TABLE_SIZE - 1;
+ float t = f - (float)i;
+
+ float result = ramp[i][component];
+
+ if (t > 0.0)
+ result = (1.0 - t) * result + t * ramp[i + 1][component];
+
+ return result*2.0 - 1.0;
+}
+
+shader node_vector_curves(
+ color ramp[RAMP_TABLE_SIZE] = {0.0},
+
+ vector VectorIn = vector(0.0, 0.0, 0.0),
+ float Fac = 0.0,
+ output vector VectorOut = vector(0.0, 0.0, 0.0))
+{
+ VectorOut[0] = ramp_lookup(ramp, VectorIn[0], 0);
+ VectorOut[1] = ramp_lookup(ramp, VectorIn[1], 1);
+ VectorOut[2] = ramp_lookup(ramp, VectorIn[2], 2);
+
+ VectorOut = mix(VectorIn, VectorOut, Fac);
+}
+
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 9c79886fdca..ec7978066c2 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -398,6 +398,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
case NODE_RGB_CURVES:
svm_node_rgb_curves(kg, sd, stack, node, &offset);
break;
+ case NODE_VECTOR_CURVES:
+ svm_node_vector_curves(kg, sd, stack, node, &offset);
+ break;
case NODE_LIGHT_FALLOFF:
svm_node_light_falloff(sd, stack, node);
break;
diff --git a/intern/cycles/kernel/svm/svm_ramp.h b/intern/cycles/kernel/svm/svm_ramp.h
index c64413cbe84..054137fe7a3 100644
--- a/intern/cycles/kernel/svm/svm_ramp.h
+++ b/intern/cycles/kernel/svm/svm_ramp.h
@@ -63,9 +63,9 @@ __device void svm_node_rgb_curves(KernelGlobals *kg, ShaderData *sd, float *stac
float fac = stack_load_float(stack, fac_offset);
float3 color = stack_load_float3(stack, color_offset);
- float r = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.x).w).x;
- float g = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.y).w).y;
- float b = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.z).w).z;
+ float r = rgb_ramp_lookup(kg, *offset, color.x).x;
+ float g = rgb_ramp_lookup(kg, *offset, color.y).y;
+ float b = rgb_ramp_lookup(kg, *offset, color.z).z;
color = (1.0f - fac)*color + fac*make_float3(r, g, b);
stack_store_float3(stack, out_offset, color);
@@ -73,6 +73,25 @@ __device void svm_node_rgb_curves(KernelGlobals *kg, ShaderData *sd, float *stac
*offset += RAMP_TABLE_SIZE;
}
+__device void svm_node_vector_curves(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
+{
+ uint fac_offset = node.y;
+ uint color_offset = node.z;
+ uint out_offset = node.w;
+
+ float fac = stack_load_float(stack, fac_offset);
+ float3 color = stack_load_float3(stack, color_offset);
+
+ float r = rgb_ramp_lookup(kg, *offset, (color.x + 1.0f)*0.5f).x;
+ float g = rgb_ramp_lookup(kg, *offset, (color.y + 1.0f)*0.5f).y;
+ float b = rgb_ramp_lookup(kg, *offset, (color.z + 1.0f)*0.5f).z;
+
+ color = (1.0f - fac)*color + fac*make_float3(r*2.0f - 1.0f, g*2.0f - 1.0f, b*2.0f - 1.0f);
+ stack_store_float3(stack, out_offset, color);
+
+ *offset += RAMP_TABLE_SIZE;
+}
+
CCL_NAMESPACE_END
#endif /* __SVM_RAMP_H__ */
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index b41e34ab407..e7fe6dc0857 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -88,6 +88,7 @@ typedef enum NodeType {
NODE_BRIGHTCONTRAST,
NODE_RGB_RAMP,
NODE_RGB_CURVES,
+ NODE_VECTOR_CURVES,
NODE_MIN_MAX,
NODE_LIGHT_FALLOFF,
NODE_OBJECT_INFO,
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 3f8055b3540..aef28449e44 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -3018,9 +3018,56 @@ void RGBCurvesNode::compile(SVMCompiler& compiler)
void RGBCurvesNode::compile(OSLCompiler& compiler)
{
+ float ramp[RAMP_TABLE_SIZE][3];
+
+ for (int i = 0; i < RAMP_TABLE_SIZE; ++i) {
+ ramp[i][0] = curves[i].x;
+ ramp[i][1] = curves[i].y;
+ ramp[i][2] = curves[i].z;
+ }
+
+ compiler.parameter_color_array("ramp", ramp, RAMP_TABLE_SIZE);
compiler.add(this, "node_rgb_curves");
}
+/* VectorCurvesNode */
+
+VectorCurvesNode::VectorCurvesNode()
+: ShaderNode("rgb_curves")
+{
+ add_input("Fac", SHADER_SOCKET_FLOAT);
+ add_input("Vector", SHADER_SOCKET_VECTOR);
+ add_output("Vector", SHADER_SOCKET_VECTOR);
+}
+
+void VectorCurvesNode::compile(SVMCompiler& compiler)
+{
+ ShaderInput *fac_in = input("Fac");
+ ShaderInput *vector_in = input("Vector");
+ ShaderOutput *vector_out = output("Vector");
+
+ compiler.stack_assign(fac_in);
+ compiler.stack_assign(vector_in);
+ compiler.stack_assign(vector_out);
+
+ compiler.add_node(NODE_VECTOR_CURVES, fac_in->stack_offset, vector_in->stack_offset, vector_out->stack_offset);
+ compiler.add_array(curves, RAMP_TABLE_SIZE);
+}
+
+void VectorCurvesNode::compile(OSLCompiler& compiler)
+{
+ float ramp[RAMP_TABLE_SIZE][3];
+
+ for (int i = 0; i < RAMP_TABLE_SIZE; ++i) {
+ ramp[i][0] = curves[i].x;
+ ramp[i][1] = curves[i].y;
+ ramp[i][2] = curves[i].z;
+ }
+
+ compiler.parameter_color_array("ramp", ramp, RAMP_TABLE_SIZE);
+ compiler.add(this, "node_vector_curves");
+}
+
/* RGBRampNode */
RGBRampNode::RGBRampNode()
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 67733142dd1..5e357cff56c 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -455,6 +455,12 @@ public:
float4 curves[RAMP_TABLE_SIZE];
};
+class VectorCurvesNode : public ShaderNode {
+public:
+ SHADER_NODE_CLASS(VectorCurvesNode)
+ float4 curves[RAMP_TABLE_SIZE];
+};
+
class RGBRampNode : public ShaderNode {
public:
SHADER_NODE_CLASS(RGBRampNode)