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
This commit is contained in:

committed by
Brecht Van Lommel

parent
f4213c1408
commit
30bffb5a3a
@@ -40,6 +40,18 @@ float safe_modulo(float a, float b)
|
||||
return result;
|
||||
}
|
||||
|
||||
float safe_sqrt(float a)
|
||||
{
|
||||
float result;
|
||||
|
||||
if (a > 0.0)
|
||||
result = sqrt(a);
|
||||
else
|
||||
result = 0.0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float safe_log(float a, float b)
|
||||
{
|
||||
if (a < 0.0 || b < 0.0)
|
||||
@@ -97,6 +109,14 @@ shader node_math(
|
||||
Value = fabs(Value1);
|
||||
else if (type == "arctan2")
|
||||
Value = atan2(Value1, Value2);
|
||||
else if (type == "floor")
|
||||
Value = floor(Value1);
|
||||
else if (type == "ceil")
|
||||
Value = ceil(Value1);
|
||||
else if (type == "fract")
|
||||
Value = Value1 - floor(Value1);
|
||||
else if (type == "sqrt")
|
||||
Value = safe_sqrt(Value1);
|
||||
|
||||
if (use_clamp)
|
||||
Value = clamp(Value, 0.0, 1.0);
|
||||
|
@@ -94,6 +94,14 @@ ccl_device float svm_math(NodeMath type, float Fac1, float Fac2)
|
||||
Fac = fabsf(Fac1);
|
||||
else if(type == NODE_MATH_ARCTAN2)
|
||||
Fac = atan2f(Fac1, Fac2);
|
||||
else if (type == NODE_MATH_FLOOR)
|
||||
Fac = floorf(Fac1);
|
||||
else if (type == NODE_MATH_CEIL)
|
||||
Fac = ceilf(Fac1);
|
||||
else if (type == NODE_MATH_FRACT)
|
||||
Fac = Fac1 - floorf(Fac1);
|
||||
else if (type == NODE_MATH_SQRT)
|
||||
Fac = safe_sqrtf(Fac1);
|
||||
else if(type == NODE_MATH_CLAMP)
|
||||
Fac = saturate(Fac1);
|
||||
else
|
||||
|
@@ -261,6 +261,10 @@ typedef enum NodeMath {
|
||||
NODE_MATH_MODULO,
|
||||
NODE_MATH_ABSOLUTE,
|
||||
NODE_MATH_ARCTAN2,
|
||||
NODE_MATH_FLOOR,
|
||||
NODE_MATH_CEIL,
|
||||
NODE_MATH_FRACT,
|
||||
NODE_MATH_SQRT,
|
||||
NODE_MATH_CLAMP /* used for the clamp UI option */
|
||||
} NodeMath;
|
||||
|
||||
|
@@ -5071,6 +5071,10 @@ NODE_DEFINE(MathNode)
|
||||
type_enum.insert("modulo", NODE_MATH_MODULO);
|
||||
type_enum.insert("absolute", NODE_MATH_ABSOLUTE);
|
||||
type_enum.insert("arctan2", NODE_MATH_ARCTAN2);
|
||||
type_enum.insert("floor", NODE_MATH_FLOOR);
|
||||
type_enum.insert("ceil", NODE_MATH_CEIL);
|
||||
type_enum.insert("fract", NODE_MATH_FRACT);
|
||||
type_enum.insert("sqrt", NODE_MATH_SQRT);
|
||||
SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD);
|
||||
|
||||
SOCKET_BOOLEAN(use_clamp, "Use Clamp", false);
|
||||
|
Reference in New Issue
Block a user