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 /intern/cycles/kernel/shaders
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 'intern/cycles/kernel/shaders')
-rw-r--r--intern/cycles/kernel/shaders/node_math.osl20
1 files changed, 20 insertions, 0 deletions
diff --git a/intern/cycles/kernel/shaders/node_math.osl b/intern/cycles/kernel/shaders/node_math.osl
index c5fcbc311d3..aa9f6e671c3 100644
--- a/intern/cycles/kernel/shaders/node_math.osl
+++ b/intern/cycles/kernel/shaders/node_math.osl
@@ -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);