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
diff options
context:
space:
mode:
authorThomas Dinges <blender@dingto.org>2013-05-20 18:38:47 +0400
committerThomas Dinges <blender@dingto.org>2013-05-20 18:38:47 +0400
commit38dc85f296a27a5641d296c8f41834db41dac18b (patch)
treeb47567b3c6fd455a6a92b359fc92509ff33e85fb /intern/cycles/kernel
parent0fb5c9117fdb9ad24184a2dad2ad1c8c66565aaa (diff)
Math Node:
* Added a Modulo operation to the math node, available in Compositor, Shader and Texture Nodes.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/shaders/node_math.osl14
-rw-r--r--intern/cycles/kernel/svm/svm_math.h2
-rw-r--r--intern/cycles/kernel/svm/svm_types.h1
3 files changed, 17 insertions, 0 deletions
diff --git a/intern/cycles/kernel/shaders/node_math.osl b/intern/cycles/kernel/shaders/node_math.osl
index 2ec1a5f0a32..214ef931660 100644
--- a/intern/cycles/kernel/shaders/node_math.osl
+++ b/intern/cycles/kernel/shaders/node_math.osl
@@ -30,6 +30,18 @@ float safe_divide(float a, float b)
return result;
}
+float safe_modulo(float a, float b)
+{
+ float result;
+
+ if (b == 0.0)
+ result = 0.0;
+ else
+ result = fmod(a, b);
+
+ return result;
+}
+
float safe_log(float a, float b)
{
if (a < 0.0 || b < 0.0)
@@ -81,6 +93,8 @@ shader node_math(
Value = Value1 < Value2;
else if (type == "Greater Than")
Value = Value1 > Value2;
+ else if (type == "Modulo")
+ Value = safe_modulo(Value1, Value2);
if (Clamp)
Value = clamp(Value1, 0.0, 1.0);
diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h
index c7cd5200cd0..dbf477a0a96 100644
--- a/intern/cycles/kernel/svm/svm_math.h
+++ b/intern/cycles/kernel/svm/svm_math.h
@@ -56,6 +56,8 @@ __device float svm_math(NodeMath type, float Fac1, float Fac2)
Fac = Fac1 < Fac2;
else if(type == NODE_MATH_GREATER_THAN)
Fac = Fac1 > Fac2;
+ else if(type == NODE_MATH_MODULO)
+ Fac = safe_modulo(Fac1, Fac2);
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 d89fde898dc..2cf3ccbe575 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -210,6 +210,7 @@ typedef enum NodeMath {
NODE_MATH_ROUND,
NODE_MATH_LESS_THAN,
NODE_MATH_GREATER_THAN,
+ NODE_MATH_MODULO,
NODE_MATH_CLAMP /* used for the clamp UI option */
} NodeMath;