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:
Diffstat (limited to 'source/blender/nodes/NOD_math_functions.hh')
-rw-r--r--source/blender/nodes/NOD_math_functions.hh75
1 files changed, 44 insertions, 31 deletions
diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh
index 6ea89beee2e..a0a2e6f81f8 100644
--- a/source/blender/nodes/NOD_math_functions.hh
+++ b/source/blender/nodes/NOD_math_functions.hh
@@ -18,9 +18,9 @@
#include "DNA_node_types.h"
+#include "BLI_float3.hh"
#include "BLI_math_base_safe.h"
#include "BLI_math_rotation.h"
-#include "BLI_math_vec_types.hh"
#include "BLI_string_ref.hh"
namespace blender::nodes {
@@ -240,8 +240,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -261,21 +259,40 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation
case NODE_VECTOR_MATH_MULTIPLY:
return dispatch([](float3 a, float3 b) { return a * b; });
case NODE_VECTOR_MATH_DIVIDE:
- return dispatch([](float3 a, float3 b) { return safe_divide(a, b); });
+ return dispatch([](float3 a, float3 b) {
+ return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z));
+ });
case NODE_VECTOR_MATH_CROSS_PRODUCT:
- return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); });
+ return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); });
case NODE_VECTOR_MATH_PROJECT:
- return dispatch([](float3 a, float3 b) { return project(a, b); });
+ return dispatch([](float3 a, float3 b) {
+ float length_squared = b.length_squared();
+ return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f);
+ });
case NODE_VECTOR_MATH_REFLECT:
- return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); });
+ return dispatch([](float3 a, float3 b) {
+ b.normalize();
+ return a.reflected(b);
+ });
case NODE_VECTOR_MATH_SNAP:
- return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; });
+ return dispatch([](float3 a, float3 b) {
+ return float3(floor(safe_divide(a.x, b.x)),
+ floor(safe_divide(a.y, b.y)),
+ floor(safe_divide(a.z, b.z))) *
+ b;
+ });
case NODE_VECTOR_MATH_MODULO:
- return dispatch([](float3 a, float3 b) { return mod(a, b); });
+ return dispatch([](float3 a, float3 b) {
+ return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z));
+ });
case NODE_VECTOR_MATH_MINIMUM:
- return dispatch([](float3 a, float3 b) { return min(a, b); });
+ return dispatch([](float3 a, float3 b) {
+ return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z));
+ });
case NODE_VECTOR_MATH_MAXIMUM:
- return dispatch([](float3 a, float3 b) { return max(a, b); });
+ return dispatch([](float3 a, float3 b) {
+ return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z));
+ });
default:
return false;
}
@@ -289,8 +306,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -304,9 +319,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation
switch (operation) {
case NODE_VECTOR_MATH_DOT_PRODUCT:
- return dispatch([](float3 a, float3 b) { return dot(a, b); });
+ return dispatch([](float3 a, float3 b) { return float3::dot(a, b); });
case NODE_VECTOR_MATH_DISTANCE:
- return dispatch([](float3 a, float3 b) { return distance(a, b); });
+ return dispatch([](float3 a, float3 b) { return float3::distance(a, b); });
default:
return false;
}
@@ -320,8 +335,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -341,7 +354,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera
return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z));
});
case NODE_VECTOR_MATH_FACEFORWARD:
- return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); });
+ return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); });
default:
return false;
}
@@ -355,8 +368,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -370,7 +381,8 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat
switch (operation) {
case NODE_VECTOR_MATH_REFRACT:
- return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); });
+ return dispatch(
+ [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); });
default:
return false;
}
@@ -384,8 +396,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -399,7 +409,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper
switch (operation) {
case NODE_VECTOR_MATH_LENGTH:
- return dispatch([](float3 in) { return length(in); });
+ return dispatch([](float3 in) { return in.length(); });
default:
return false;
}
@@ -440,8 +450,6 @@ template<typename Callback>
inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation,
Callback &&callback)
{
- using namespace blender::math;
-
const FloatMathOperationInfo *info = get_float3_math_operation_info(operation);
if (info == nullptr) {
return false;
@@ -455,15 +463,20 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope
switch (operation) {
case NODE_VECTOR_MATH_NORMALIZE:
- return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */
+ return dispatch([](float3 in) {
+ float3 out = in;
+ out.normalize();
+ return out;
+ }); /* Should be safe. */
case NODE_VECTOR_MATH_FLOOR:
- return dispatch([](float3 in) { return floor(in); });
+ return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); });
case NODE_VECTOR_MATH_CEIL:
- return dispatch([](float3 in) { return ceil(in); });
+ return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); });
case NODE_VECTOR_MATH_FRACTION:
- return dispatch([](float3 in) { return fract(in); });
+ return dispatch(
+ [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); });
case NODE_VECTOR_MATH_ABSOLUTE:
- return dispatch([](float3 in) { return abs(in); });
+ return dispatch([](float3 in) { return float3::abs(in); });
case NODE_VECTOR_MATH_SINE:
return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); });
case NODE_VECTOR_MATH_COSINE: