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:
authorOmarSquircleArt <omar.squircleart@gmail.com>2019-08-18 12:16:04 +0300
committerOmarSquircleArt <omar.squircleart@gmail.com>2019-08-18 12:16:04 +0300
commite5618725fd1ebdf558e963d959eb3950b5a9874c (patch)
treed1e02f93f36aefa5bf6a87ca75b91558a34ae5d1 /intern/cycles/kernel/shaders
parente12c17b3054b9a3d9636268c2a2904ecb9df632b (diff)
Shading: Refactor Math node and use dynamic inputs.
- Implement dynamic inputs. The second input is now unavailable in single operand math operators. - Reimplemenet the clamp option using graph expansion for Cycles. - Clean up code and unify naming between Blender and Cycles. - Remove unused code. Reviewers: brecht Differential Revision: https://developer.blender.org/D5481
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r--intern/cycles/kernel/shaders/node_math.osl93
1 files changed, 33 insertions, 60 deletions
diff --git a/intern/cycles/kernel/shaders/node_math.osl b/intern/cycles/kernel/shaders/node_math.osl
index 8830339e05f..fb59c783770 100644
--- a/intern/cycles/kernel/shaders/node_math.osl
+++ b/intern/cycles/kernel/shaders/node_math.osl
@@ -17,57 +17,31 @@
#include "stdosl.h"
float safe_divide(float a, float b)
-{
- float result;
-
- if (b == 0.0)
- result = 0.0;
- else
- result = a / b;
-
- return result;
+{
+ return (b != 0.0) ? a / b : 0.0;
}
float safe_modulo(float a, float b)
{
- float result;
-
- if (b == 0.0)
- result = 0.0;
- else
- result = fmod(a, b);
-
- return result;
+ return (b != 0.0) ? fmod(a, b) : 0.0;
}
float safe_sqrt(float a)
{
- float result;
-
- if (a > 0.0)
- result = sqrt(a);
- else
- result = 0.0;
-
- return result;
+ return (a > 0.0) ? sqrt(a) : 0.0;
}
float safe_log(float a, float b)
{
- if (a < 0.0 || b < 0.0)
- return 0.0;
-
- return log(a) / log(b);
+ return (a > 0.0 && b > 0.0) ? log(a) / log(b) : 0.0;
}
+/* OSL asin, acos, and pow functions are safe by default. */
shader node_math(string type = "add",
- int use_clamp = 0,
- float Value1 = 0.0,
- float Value2 = 0.0,
+ float Value1 = 0.5,
+ float Value2 = 0.5,
output float Value = 0.0)
{
- /* OSL asin, acos, pow check for values that could give rise to nan */
-
if (type == "add")
Value = Value1 + Value2;
else if (type == "subtract")
@@ -76,47 +50,46 @@ shader node_math(string type = "add",
Value = Value1 * Value2;
else if (type == "divide")
Value = safe_divide(Value1, Value2);
- else if (type == "sine")
- Value = sin(Value1);
- else if (type == "cosine")
- Value = cos(Value1);
- else if (type == "tangent")
- Value = tan(Value1);
- else if (type == "arcsine")
- Value = asin(Value1);
- else if (type == "arccosine")
- Value = acos(Value1);
- else if (type == "arctangent")
- Value = atan(Value1);
else if (type == "power")
Value = pow(Value1, Value2);
else if (type == "logarithm")
Value = safe_log(Value1, Value2);
+ else if (type == "sqrt")
+ Value = safe_sqrt(Value1);
+ else if (type == "absolute")
+ Value = fabs(Value1);
else if (type == "minimum")
Value = min(Value1, Value2);
else if (type == "maximum")
Value = max(Value1, Value2);
- else if (type == "round")
- Value = floor(Value1 + 0.5);
else if (type == "less_than")
Value = Value1 < Value2;
else if (type == "greater_than")
Value = Value1 > Value2;
- else if (type == "modulo")
- Value = safe_modulo(Value1, Value2);
- else if (type == "absolute")
- Value = fabs(Value1);
- else if (type == "arctan2")
- Value = atan2(Value1, Value2);
+ else if (type == "round")
+ Value = floor(Value1 + 0.5);
else if (type == "floor")
Value = floor(Value1);
else if (type == "ceil")
Value = ceil(Value1);
- else if (type == "fract")
+ else if (type == "fraction")
Value = Value1 - floor(Value1);
- else if (type == "sqrt")
- Value = safe_sqrt(Value1);
-
- if (use_clamp)
- Value = clamp(Value, 0.0, 1.0);
+ else if (type == "modulo")
+ Value = safe_modulo(Value1, Value2);
+ else if (type == "sine")
+ Value = sin(Value1);
+ else if (type == "cosine")
+ Value = cos(Value1);
+ else if (type == "tangent")
+ Value = tan(Value1);
+ else if (type == "arcsine")
+ Value = asin(Value1);
+ else if (type == "arccosine")
+ Value = acos(Value1);
+ else if (type == "arctangent")
+ Value = atan(Value1);
+ else if (type == "arctan2")
+ Value = atan2(Value1, Value2);
+ else
+ warning("%s", "Unknown math operator!");
}