[Bf-blender-cvs] [3fbc984] master: Nodes: add absolute value operation to all math nodes
Matt Heimlich
noreply at git.blender.org
Wed May 7 16:48:11 CEST 2014
Commit: 3fbc984b069fed441cccdd3416ec71e064235e36
Author: Matt Heimlich
Date: Wed May 7 16:20:17 2014 +0200
https://developer.blender.org/rB3fbc984b069fed441cccdd3416ec71e064235e36
Nodes: add absolute value operation to all math nodes
Reviewed By: dingto, brecht
Differential Revision: https://developer.blender.org/D507
===================================================================
M intern/cycles/kernel/shaders/node_math.osl
M intern/cycles/kernel/svm/svm_math.h
M intern/cycles/kernel/svm/svm_types.h
M intern/cycles/render/nodes.cpp
M intern/cycles/util/util_math.h
M source/blender/compositor/nodes/COM_MathNode.cpp
M source/blender/compositor/operations/COM_MathBaseOperation.cpp
M source/blender/compositor/operations/COM_MathBaseOperation.h
M source/blender/gpu/shaders/gpu_shader_material.glsl
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/shader/nodes/node_shader_math.c
M source/blender/nodes/texture/nodes/node_texture_math.c
===================================================================
diff --git a/intern/cycles/kernel/shaders/node_math.osl b/intern/cycles/kernel/shaders/node_math.osl
index 066e5f8..abb6a35 100644
--- a/intern/cycles/kernel/shaders/node_math.osl
+++ b/intern/cycles/kernel/shaders/node_math.osl
@@ -93,6 +93,8 @@ shader node_math(
Value = Value1 > Value2;
else if (type == "Modulo")
Value = safe_modulo(Value1, Value2);
+ else if (type == "Absolute")
+ Value = fabs(Value1);
if (Clamp)
Value = clamp(Value, 0.0, 1.0);
diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h
index bb46d44..1ce9386 100644
--- a/intern/cycles/kernel/svm/svm_math.h
+++ b/intern/cycles/kernel/svm/svm_math.h
@@ -56,6 +56,8 @@ ccl_device float svm_math(NodeMath type, float Fac1, float Fac2)
Fac = Fac1 > Fac2;
else if(type == NODE_MATH_MODULO)
Fac = safe_modulo(Fac1, Fac2);
+ else if(type == NODE_MATH_ABSOLUTE)
+ Fac = fabsf(Fac1);
else if(type == NODE_MATH_CLAMP)
Fac = clamp(Fac1, 0.0f, 1.0f);
else
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index a7deb0b..80972ec 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -221,6 +221,7 @@ typedef enum NodeMath {
NODE_MATH_LESS_THAN,
NODE_MATH_GREATER_THAN,
NODE_MATH_MODULO,
+ NODE_MATH_ABSOLUTE,
NODE_MATH_CLAMP /* used for the clamp UI option */
} NodeMath;
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index e269074..a53e0b3 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -3544,6 +3544,7 @@ static ShaderEnum math_type_init()
enm.insert("Less Than", NODE_MATH_LESS_THAN);
enm.insert("Greater Than", NODE_MATH_GREATER_THAN);
enm.insert("Modulo", NODE_MATH_MODULO);
+ enm.insert("Absolute", NODE_MATH_ABSOLUTE);
return enm;
}
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index ded7576..69c0d84 100644
--- a/intern/cycles/util/util_math.h
+++ b/intern/cycles/util/util_math.h
@@ -183,7 +183,7 @@ ccl_device_inline float signf(float f)
ccl_device_inline float nonzerof(float f, float eps)
{
- if(fabsf(f) < eps)
+ if(fabsf(f) < eps)
return signf(f)*eps;
else
return f;
diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp
index 42a8cb0..ac1c2b3 100644
--- a/source/blender/compositor/nodes/COM_MathNode.cpp
+++ b/source/blender/compositor/nodes/COM_MathNode.cpp
@@ -83,6 +83,9 @@ void MathNode::convertToOperations(NodeConverter &converter, const CompositorCon
case 17: /* Modulo */
operation = new MathModuloOperation();
break;
+ case 18: /* Absolute Value */
+ operation = new MathAbsoluteOperation();
+ break;
}
if (operation) {
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
index 9da55df..cbc60b5 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
@@ -333,3 +333,14 @@ void MathModuloOperation::executePixelSampled(float output[4], float x, float y,
clampIfNeeded(output);
}
+void MathAbsoluteOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = fabs(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h
index 4ea7c43..05d2bb0 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.h
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.h
@@ -163,4 +163,10 @@ public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
};
+class MathAbsoluteOperation : public MathBaseOperation {
+public:
+ MathAbsoluteOperation() : MathBaseOperation() {}
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+};
+
#endif
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 4452d4e..a224f8e 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -299,6 +299,11 @@ void math_modulo(float val1, float val2, out float outval)
outval = mod(val1, val2);
}
+void math_abs(float val1, out float outval)
+{
+ outval = abs(val1);
+}
+
void squeeze(float val, float width, float center, out float outval)
{
outval = 1.0/(1.0 + pow(2.71828183, -((val-center)*width)));
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 0f2380c..c39d382 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -129,7 +129,8 @@ EnumPropertyItem node_math_items[] = {
{14, "ROUND", 0, "Round", ""},
{15, "LESS_THAN", 0, "Less Than", ""},
{16, "GREATER_THAN", 0, "Greater Than", ""},
- {17, "MODULO", 0, "Modulo", ""},
+ {17, "MODULO", 0, "Modulo", ""},
+ {18, "ABSOLUTE", 0, "Absolute", ""},
{0, NULL, 0, NULL, NULL}
};
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c
index b6c7555..ed88e80 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.c
+++ b/source/blender/nodes/shader/nodes/node_shader_math.c
@@ -216,6 +216,11 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode
r = fmod(a, b);
break;
}
+ case 18: /* Absolute */
+ {
+ r = fabs(a);
+ break;
+ }
}
out[0]->vec[0] = r;
@@ -226,7 +231,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
static const char *names[] = {"math_add", "math_subtract", "math_multiply",
"math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin",
"math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max",
- "math_round", "math_less_than", "math_greater_than", "math_modulo"};
+ "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_absolute"};
switch (node->custom1) {
case 0:
diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c
index 8d69d79..86d693f 100644
--- a/source/blender/nodes/texture/nodes/node_texture_math.c
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -174,7 +174,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
break;
}
- case 17: /* Modulo */
+ case 17: /* Modulo */
{
if (in1 == 0.0f)
*out = 0.0f;
@@ -182,6 +182,13 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
*out = fmod(in0, in1);
break;
}
+
+ case 18: /* Absolute */
+ {
+ *out = fabs(in0);
+ break;
+ }
+
default:
{
BLI_assert(0);
More information about the Bf-blender-cvs
mailing list