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:
authorCharlie Jolly <mistajolly@gmail.com>2018-07-13 00:40:18 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-07-13 12:00:10 +0300
commit30bffb5a3afa2fde165d4fb63a115310d5ddc3e3 (patch)
tree543109969a99e176340071dfdf85a87594f0db07 /source/blender/nodes/shader/nodes/node_shader_math.c
parentf4213c1408619d1071004247ed099e2ba98a3e9a (diff)
Nodes: add sqrt, ceil, floor and fract to math nodes.
This works for Cycles, Eevee, texture nodes and compositing. It helps to reduce the number of math nodes required in various node setups. Differential Revision: https://developer.blender.org/D3537
Diffstat (limited to 'source/blender/nodes/shader/nodes/node_shader_math.c')
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.c46
1 files changed, 45 insertions, 1 deletions
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];