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 <charlie>2019-12-06 02:02:05 +0300
committerCharlie Jolly <mistajolly@gmail.com>2019-12-07 15:33:07 +0300
commit0406eb110332a863811d7fb6228f9a7ca514e022 (patch)
tree9809062966699e31c785ae0dc97ccb6e9f6c60f7 /source/blender/blenlib
parent6a78ace569ec7c0e076e5af34d9496ce3363b81e (diff)
Maths Node: Additional functions
When creating shaders and using maths functions it is expected that Blender should match functions in other DCC applications, game engines and shading languages such as GLSL and OSL. This patch adds missing functions to the Blender maths node. Ideally, it would be nice to have these functions available to vectors too but that is not part of this patch. This patch adds the following functions trunc, snap, wrap, compare, pingpong, sign, radians, degrees, cosh, sinh, tanh, exp, smoothmin and inversesqrt. Sign function is based on GLSL and OSL functions and returns zero when x == 0. Differential Revision: https://developer.blender.org/D5957
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 85c6425bb2f..a1c88edca6f 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -363,6 +363,18 @@ MINLINE int mod_i(int i, int n)
return (i % n + n) % n;
}
+MINLINE float fractf(float a)
+{
+ return a - floorf(a);
+}
+
+/* Adapted from godotengine math_funcs.h. */
+MINLINE float wrapf(float value, float max, float min)
+{
+ float range = max - min;
+ return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min;
+}
+
MINLINE float min_ff(float a, float b)
{
return (a < b) ? a : b;
@@ -371,6 +383,17 @@ MINLINE float max_ff(float a, float b)
{
return (a > b) ? a : b;
}
+/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */
+MINLINE float smoothminf(float a, float b, float c)
+{
+ if (c != 0.0f) {
+ float h = max_ff(c - fabsf(a - b), 0.0f) / c;
+ return min_ff(a, b) - h * h * h * c * (1.0f / 6.0f);
+ }
+ else {
+ return min_ff(a, b);
+ }
+}
MINLINE double min_dd(double a, double b)
{
@@ -504,6 +527,19 @@ MINLINE float signf(float f)
return (f < 0.f) ? -1.f : 1.f;
}
+MINLINE float compatible_signf(float f)
+{
+ if (f > 0.0f) {
+ return 1.0f;
+ }
+ if (f < 0.0f) {
+ return -1.0f;
+ }
+ else {
+ return 0.0f;
+ }
+}
+
MINLINE int signum_i_ex(float a, float eps)
{
if (a > eps) {