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 /source/blender
parent0fb5c9117fdb9ad24184a2dad2ad1c8c66565aaa (diff)
Math Node:
* Added a Modulo operation to the math node, available in Compositor, Shader and Texture Nodes.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/compositor/nodes/COM_MathNode.cpp3
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.cpp15
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.h6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl8
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c1
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.c10
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_math.c9
7 files changed, 51 insertions, 1 deletions
diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp
index 307590b977b..23e9a9d623d 100644
--- a/source/blender/compositor/nodes/COM_MathNode.cpp
+++ b/source/blender/compositor/nodes/COM_MathNode.cpp
@@ -80,6 +80,9 @@ void MathNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co
case 16: /* Greater Than */
operation = new MathGreaterThanOperation();
break;
+ case 17: /* Modulo */
+ operation = new MathModuloOperation();
+ break;
}
if (operation != NULL) {
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
index 7039689aa5f..3749bcf42d8 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
@@ -317,4 +317,19 @@ void MathGreaterThanOperation::executePixel(float output[4], float x, float y, P
clampIfNeeded(output);
}
+void MathModuloOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
+ this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+
+ if (inputValue2[0] == 0)
+ output[0] = 0.0;
+ else
+ output[0] = fmod(inputValue1[0], inputValue2[0]);
+
+ clampIfNeeded(output);
+}
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h
index febfa9662c6..649a9688037 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.h
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.h
@@ -157,4 +157,10 @@ public:
void executePixel(float output[4], float x, float y, PixelSampler sampler);
};
+class MathModuloOperation : public MathBaseOperation {
+public:
+ MathModuloOperation() : MathBaseOperation() {}
+ void executePixel(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 fd519a86fc9..3a68b79d154 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -279,6 +279,14 @@ void math_greater_than(float val1, float val2, out float outval)
outval = 0.0;
}
+void math_modulo(float val1, float val2, out float outval)
+{
+ if (val2 == 0.0)
+ outval = 0.0;
+ else
+ outval = mod(val1, val2);
+}
+
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 6238e3f7d3d..a40d85ae954 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -127,6 +127,7 @@ EnumPropertyItem node_math_items[] = {
{14, "ROUND", 0, "Round", ""},
{15, "LESS_THAN", 0, "Less Than", ""},
{16, "GREATER_THAN", 0, "Greater Than", ""},
+ {17, "MODULO", 0, "Modulo", ""},
{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 c3e2fc54c78..bef777e5d59 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.c
+++ b/source/blender/nodes/shader/nodes/node_shader_math.c
@@ -203,6 +203,14 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode
out[0]->vec[0] = 0.0f;
}
break;
+ case 17: /* Modulo */
+ {
+ if (in[1]->vec[0] == 0.0f)
+ out[0]->vec[0] = 0.0f;
+ else
+ out[0]->vec[0] = fmod(in[0]->vec[0], in[1]->vec[0]);
+ }
+ break;
}
}
@@ -211,7 +219,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_round", "math_less_than", "math_greater_than", "math_modulo"};
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 03349a57832..1e456416159 100644
--- a/source/blender/nodes/texture/nodes/node_texture_math.c
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -174,6 +174,15 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
}
break;
+ case 17: /* Modulo */
+ {
+ if (in1 == 0.0f)
+ *out = 0.0f;
+ else
+ *out= fmod(in0, in1);
+ }
+ break;
+
default:
fprintf(stderr,
"%s:%d: unhandeld value in switch statement: %d\n",