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/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/blender/compositor/nodes/COM_MathNode.cpp12
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.cpp47
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.h24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl23
-rw-r--r--source/blender/makesdna/DNA_node_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.c46
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_math.c27
8 files changed, 186 insertions, 1 deletions
diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp
index d16300ebff4..25c617a3487 100644
--- a/source/blender/compositor/nodes/COM_MathNode.cpp
+++ b/source/blender/compositor/nodes/COM_MathNode.cpp
@@ -89,6 +89,18 @@ void MathNode::convertToOperations(NodeConverter &converter, const CompositorCon
case NODE_MATH_ATAN2:
operation = new MathArcTan2Operation();
break;
+ case NODE_MATH_FLOOR:
+ operation = new MathFloorOperation();
+ break;
+ case NODE_MATH_CEIL:
+ operation = new MathCeilOperation();
+ break;
+ case NODE_MATH_FRACT:
+ operation = new MathFractOperation();
+ break;
+ case NODE_MATH_SQRT:
+ operation = new MathSqrtOperation();
+ break;
}
if (operation) {
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
index 0a515da1877..99385a5073a 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
@@ -356,3 +356,50 @@ void MathArcTan2Operation::executePixelSampled(float output[4], float x, float y
clampIfNeeded(output);
}
+
+void MathFloorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = floor(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathCeilOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = ceil(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathFractOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = inputValue1[0] - floor(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathSqrtOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ if (inputValue1[0] > 0)
+ output[0] = sqrt(inputValue1[0]);
+ else
+ output[0] = 0.0f;
+
+ clampIfNeeded(output);
+}
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h
index c636117451f..5435cc82ba7 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.h
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.h
@@ -175,4 +175,28 @@ public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
};
+class MathFloorOperation : public MathBaseOperation {
+public:
+ MathFloorOperation() : MathBaseOperation() {}
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+};
+
+class MathCeilOperation : public MathBaseOperation {
+public:
+ MathCeilOperation() : MathBaseOperation() {}
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+};
+
+class MathFractOperation : public MathBaseOperation {
+public:
+ MathFractOperation() : MathBaseOperation() {}
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+};
+
+class MathSqrtOperation : public MathBaseOperation {
+public:
+ MathSqrtOperation() : 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 ce9e82b34f8..2cb92fd1cbc 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -418,6 +418,29 @@ void math_atan2(float val1, float val2, out float outval)
outval = atan(val1, val2);
}
+void math_floor(float val, out float outval)
+{
+ outval = floor(val);
+}
+
+void math_ceil(float val, out float outval)
+{
+ outval = ceil(val);
+}
+
+void math_fract(float val, out float outval)
+{
+ outval = val - floor(val);
+}
+
+void math_sqrt(float val, out float outval)
+{
+ if (val > 0.0)
+ outval = sqrt(val);
+ else
+ outval = 0.0;
+}
+
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/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index b95506cea48..f6d92a95c3a 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1073,6 +1073,10 @@ enum {
NODE_MATH_MOD = 17,
NODE_MATH_ABS = 18,
NODE_MATH_ATAN2 = 19,
+ NODE_MATH_FLOOR = 20,
+ NODE_MATH_CEIL = 21,
+ NODE_MATH_FRACT = 22,
+ NODE_MATH_SQRT = 23,
};
/* mix rgb node flags */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a2ab00a482b..5fe42e11765 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -141,6 +141,10 @@ const EnumPropertyItem rna_enum_node_math_items[] = {
{NODE_MATH_MOD, "MODULO", 0, "Modulo", ""},
{NODE_MATH_ABS, "ABSOLUTE", 0, "Absolute", ""},
{NODE_MATH_ATAN2, "ARCTAN2", 0, "Arctan2", ""},
+ {NODE_MATH_FLOOR, "FLOOR", 0, "Floor", ""},
+ {NODE_MATH_CEIL, "CEIL", 0, "Ceil", ""},
+ {NODE_MATH_FRACT, "FRACT", 0, "Fract", ""},
+ {NODE_MATH_SQRT, "SQRT", 0, "Square Root", ""},
{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 0a75a0f8bf0..605c869099a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.c
+++ b/source/blender/nodes/shader/nodes/node_shader_math.c
@@ -226,6 +226,46 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode
r = atan2(a, b);
break;
}
+ case NODE_MATH_FLOOR:
+ {
+ if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */
+ r = floorf(a);
+ else
+ r = floorf(b);
+ break;
+ }
+ case NODE_MATH_CEIL:
+ {
+ if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */
+ r = ceilf(a);
+ else
+ r = ceilf(b);
+ break;
+ }
+ case NODE_MATH_FRACT:
+ {
+ if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */
+ r = a - floorf(a);
+ else
+ r = b - floorf(b);
+ break;
+ }
+ case NODE_MATH_SQRT:
+ {
+ if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */
+ if (a > 0)
+ r = sqrt(a);
+ else
+ r = 0.0;
+ }
+ else {
+ if (b > 0)
+ r = sqrt(b);
+ else
+ r = 0.0;
+ }
+ break;
+ }
}
if (node->custom2 & SHD_MATH_CLAMP) {
CLAMP(r, 0.0f, 1.0f);
@@ -240,7 +280,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
"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_abs",
- "math_atan2"
+ "math_atan2", "math_floor", "math_ceil", "math_fract", "math_sqrt"
};
switch (node->custom1) {
@@ -266,6 +306,10 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
case NODE_MATH_ATAN:
case NODE_MATH_ROUND:
case NODE_MATH_ABS:
+ case NODE_MATH_FLOOR:
+ case NODE_MATH_FRACT:
+ case NODE_MATH_CEIL:
+ case NODE_MATH_SQRT:
if (in[0].hasinput || !in[1].hasinput) {
/* use only first item and terminator */
GPUNodeStack tmp_in[2];
diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c
index d8dc2a62625..f786a293080 100644
--- a/source/blender/nodes/texture/nodes/node_texture_math.c
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -195,6 +195,33 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
break;
}
+ case NODE_MATH_FLOOR:
+ {
+ *out = floorf(in0);
+ break;
+ }
+
+ case NODE_MATH_CEIL:
+ {
+ *out = ceilf(in0);
+ break;
+ }
+
+ case NODE_MATH_FRACT:
+ {
+ *out = in0 - floorf(in0);
+ break;
+ }
+
+ case NODE_MATH_SQRT:
+ {
+ if (in0 > 0.0f)
+ *out = sqrtf(in0);
+ else
+ *out = 0.0f;
+ break;
+ }
+
default:
{
BLI_assert(0);