38 [](
const float a,
const float b) {
return safe_powf(a,
b); },
40 pow_generic = &pow_generic_fn;
60 float exponent_single;
62 const int exponent_int = int(exponent_single);
64 if (
float(exponent_int) == exponent_single) {
65 switch (exponent_int) {
78 pow_2->call(
mask, sub_params, context);
85 pow_3->call(
mask, sub_params, context);
94 pow_generic->call(
mask, params, context);
112 divide_generic = ÷_generic_fn;
126 const GVArray &a = params.readonly_single_input(0,
"A");
127 const GVArray &
b = params.readonly_single_input(1,
"B");
132 b.get_internal_single(&divisor);
133 if (divisor == 0.0f) {
138 if (divisor == 1.0f) {
145 const float inverse = 1.0f / divisor;
150 multiply->call(
mask, sub_params, context);
157 if (dividend == 0.0f) {
164 divide_generic->call(
mask, params, context);
173 const float fraction = frexpf(
x, &
exp);
174 return fraction == 0.5f;
184 "float ** 2", [](
const float a) {
return a * a; }, exec_fast);
188 "float ** 3", [](
const float a) {
return a * a * a; }, exec_fast);
195 "sqrt(float)", [](
const float a) {
return safe_sqrtf(a); }, exec_fast);
199 "inverse_sqrt(float)", [](
const float a) {
return safe_inverse_sqrtf(a); }, exec_fast);
203 "abs(float)", [](
const float a) {
return fabsf(a); }, exec_fast);
207 "radians(float)", [](
const float a) {
return float(
DEG2RAD(a)); }, exec_fast);
211 "degrees(float)", [](
const float a) {
return float(
RAD2DEG(a)); }, exec_fast);
215 "sign(float)", [](
const float a) {
return compatible_signf(a); }, exec_fast);
219 "round(float)", [](
const float a) {
return floorf(a + 0.5f); }, exec_fast);
223 "floor(float)", [](
const float a) {
return floorf(a); }, exec_fast);
227 "ceil(float)", [](
const float a) {
return ceilf(a); }, exec_fast);
231 "frac(float)", [](
const float a) {
return a -
floorf(a); }, exec_fast);
235 "trunc(float)", [](
const float a) {
return a >= 0.0f ?
floorf(a) :
ceilf(a); }, exec_fast);
266 "float + float", [](
const float a,
const float b) {
return a +
b; }, exec_fast);
270 "float - float", [](
const float a,
const float b) {
return a -
b; }, exec_fast);
274 "float * float", [](
const float a,
const float b) {
return a *
b; }, exec_fast);
281 [](
const float a,
const float b) {
return safe_logf(a,
b); },
287 [](
const float a,
const float b) {
return std::min(a,
b); },
293 [](
const float a,
const float b) {
return std::max(a,
b); },
298 "float(float < float)",
299 [](
const float a,
const float b) {
return float(a <
b); },
304 "float(float > float)",
305 [](
const float a,
const float b) {
return float(a >
b); },
310 "float % float", [](
const float a,
const float b) {
return safe_modf(a,
b); }, exec_fast);
314 "floor_mod(float, float)",
320 "snap(float, float)",
326 "atan2(float, float)",
327 [](
const float a,
const float b) {
return atan2f(a,
b); },
332 "pingpong(float, float)",
333 [](
const float a,
const float b) {
return pingpongf(a,
b); },
338 "float * float + float",
339 [](
const float a,
const float b,
const float c) {
return a *
b + c; },
344 "compare(float, float, float)",
345 [](
const float a,
const float b,
const float c) {
352 "smooth_min(float, float, float)",
353 [](
const float a,
const float b,
const float c) {
return smoothminf(a,
b, c); },
358 "smooth_max(float, float, float)",
359 [](
const float a,
const float b,
const float c) {
return -
smoothminf(-a, -
b, c); },
364 "wrap(float, float, float)",
365 [](
const float a,
const float b,
const float c) {
return wrapf(a,
b, c); },
370 "float3 + float3", [](
const float3 &a,
const float3 &
b) {
return a +
b; }, exec_fast);
374 "float3 - float3", [](
const float3 &a,
const float3 &
b) {
return a -
b; }, exec_fast);
378 "float3 * float3", [](
const float3 &a,
const float3 &
b) {
return a *
b; }, exec_fast);
388 "cross_product(float3, float3)",
394 "project(float3, float3)",
400 "reflect(float3, float3)",
406 "snap(float3, float3)",
416 "min(float3, float3)",
422 "max(float3, float3)",
433 "dot_product(float3, float3)",
439 "distance(float3, float3)",
445 "float3 * float3 + float3",
457 "faceforward(float3, float3, float3)",
465 "refract(float3, float3, float)", [](
const float3 &a,
const float3 &
b,
float c) {
475 "float3 * float", [](
const float3 &a,
float b) {
return a *
b; }, exec_fast);
483 "round(float3)", [](
const float3 &a) {
return math::floor(a + 0.5f); }, exec_fast);
499 "abs(float3)", [](
const float3 &a) {
return math::abs(a); }, exec_fast);
518 return mf::build::SI2_SO<int, int, int>(
519 "int + int", [](
int a,
int b) {
return a +
b; }, exec_fast);
522 return mf::build::SI2_SO<int, int, int>(
523 "int - int", [](
int a,
int b) {
return a -
b; }, exec_fast);
526 return mf::build::SI2_SO<int, int, int>(
527 "int * int", [](
int a,
int b) {
return a *
b; }, exec_fast);
530 return mf::build::SI2_SO<int, int, int>(
534 return mf::build::SI2_SO<int, int, int>(
540 return mf::build::SI2_SO<int, int, int>(
541 "divide_ceil(int, int)",
546 return mf::build::SI2_SO<int, int, int>(
547 "divide_round(int, int)",
557 return mf::build::SI2_SO<int, int, int>(
559 [](
int base,
int exponent) {
561 if (base == 1 || base == -1) {
562 return (base < 0 && (exponent & 1) != 0) ? -1 : 1;
566 return pow_i(base, exponent);
571 return mf::build::SI3_SO<int, int, int, int>(
572 "int * int + int", [](
int a,
int b,
int c) {
return a *
b + c; }, exec_fast);
575 return mf::build::SI2_SO<int, int, int>(
576 "mod_periodic(int, int)",
581 return mf::build::SI2_SO<int, int, int>(
582 "int % int", [](
int a,
int b) {
return b != 0 ? a %
b : 0; }, exec_fast);
585 return mf::build::SI1_SO<int, int>(
"abs(int)", [](
int a) {
return math::abs(a); }, exec_fast);
588 return mf::build::SI1_SO<int, int>(
589 "sign(int)", [](
int a) {
return math::sign(a); }, exec_fast);
592 return mf::build::SI2_SO<int, int, int>(
593 "min(int, int)", [](
int a,
int b) {
return math::min(a,
b); }, exec_fast);
596 return mf::build::SI2_SO<int, int, int>(
597 "max(int, int)", [](
int a,
int b) {
return math::max(a,
b); }, exec_fast);
600 return mf::build::SI2_SO<int, int, int>(
"gcd(int, int)",
601 [](
int a,
int b) {
return std::gcd(a,
b); });
604 return mf::build::SI2_SO<int, int, int>(
"lcm(int, int)",
605 [](
int a,
int b) {
return std::lcm(a,
b); });
608 [] {
return mf::build::SI1_SO<int, int>(
"-int", [](
int a) {
return -a; }, exec_fast); });
610 return mf::build::SI2_SO<bool, bool, bool>(
611 "bool && bool", [](
bool a,
bool b) {
return a &&
b; }, exec_fast);
614 return mf::build::SI2_SO<bool, bool, bool>(
615 "bool || bool", [](
bool a,
bool b) {
return a ||
b; }, exec_fast);
618 [] {
return mf::build::SI1_SO<bool, bool>(
"!bool", [](
bool a) {
return !a; }, exec_fast); });
620 return mf::build::SI2_SO<bool, bool, bool>(
621 "!(bool && bool)", [](
bool a,
bool b) {
return !(a &&
b); }, exec_fast);
624 return mf::build::SI2_SO<bool, bool, bool>(
625 "!(bool || bool)", [](
bool a,
bool b) {
return !(a ||
b); }, exec_fast);
628 return mf::build::SI2_SO<bool, bool, bool>(
629 "bool == bool", [](
bool a,
bool b) {
return a ==
b; }, exec_fast);
632 return mf::build::SI2_SO<bool, bool, bool>(
633 "bool != bool", [](
bool a,
bool b) {
return a !=
b; }, exec_fast);
636 return mf::build::SI2_SO<bool, bool, bool>(
637 "!bool || bool", [](
bool a,
bool b) {
return !a ||
b; }, exec_fast);
640 return mf::build::SI2_SO<bool, bool, bool>(
641 "bool && !bool", [](
bool a,
bool b) {
return a && !
b; }, exec_fast);
644 return mf::build::SI2_SO<int, int, int>(
645 "int & int", [](
int a,
int b) {
return a &
b; }, exec_fast);
648 return mf::build::SI2_SO<int, int, int>(
649 "int | int", [](
int a,
int b) {
return a |
b; }, exec_fast);
652 return mf::build::SI2_SO<int, int, int>(
653 "int ^ int", [](
int a,
int b) {
return a ^
b; }, exec_fast);
664 const uint64_t wide_result = shift > 0 ? wide_value << shift : wide_value >> -shift;
676 const uint64_t double_result = (wide_value << shift);
677 return uint32_t((double_result | (double_result >> 32)) & ((
uint64_t(1) << 33) - 1));
682 return mf::build::SI2_SO<float3, int, float>(
697 [[maybe_unused]]
static bool registered = []() {
void materialize_to_uninitialized(void *dst) const
void get_internal_single(void *r_value) const
void call(const IndexMask &mask, mf::Params params, mf::Context context) const override
static bool is_inverse_exact(float x)
const Signature & signature() const
void set_signature(const Signature *signature)
void add_uninitialized_single_output(T *value, StringRef expected_name="")
void add_readonly_single_input(const T *value, StringRef expected_name="")
void add_readonly_single_input_value(T value, StringRef expected_name="")
MutableSpan< T > uninitialized_single_output(int param_index, StringRef name="")
VArray< T > readonly_single_input(int param_index, StringRef name="")
void call(const IndexMask &mask, Params params, Context context) const override
void single_output(const char *name, const ParamFlag flag=ParamFlag::None)
void single_input(const char *name)
MatBase< C, R > inverse(MatBase< C, R >) RET
auto SI2_SO(const char *name, ElementFn &&element_fn, const ExecPreset exec_preset=exec_presets::Materialized())
auto SI3_SO(const char *name, ElementFn &&element_fn, const ExecPreset exec_preset=exec_presets::Materialized())
auto SI1_SO(const char *name, ElementFn &&element_fn, const ExecPreset exec_preset=exec_presets::Materialized())
const MultiFunction & lookup(UString id)
void add_new_cb(CreateFn &&create_fn)
static void register_common_functions_impl()
void register_common_functions()
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T clamp(const T &a, const T &min, const T &max)
T safe_divide(const T &a, const T &b)
VecBase< T, Size > project(const VecBase< T, Size > &p, const VecBase< T, Size > &v_proj)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
VecBase< float, 3 > cross_high_precision(const VecBase< float, 3 > &a, const VecBase< float, 3 > &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T safe_mod(const T &a, const T &b)
VecBase< T, Size > refract(const VecBase< T, Size > &incident, const VecBase< T, Size > &normal, const T &eta)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, Size > faceforward(const VecBase< T, Size > &vector, const VecBase< T, Size > &incident, const VecBase< T, Size > &reference)
T mod_periodic(const T &a, const T &b)
VecBase< T, Size > reflect(const VecBase< T, Size > &incident, const VecBase< T, Size > &normal)
T max(const T &a, const T &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
MINLINE float safe_asinf(float a)
MINLINE float wrapf(float value, float max, float min)
MINLINE float safe_sqrtf(float a)
MINLINE float safe_acosf(float a)
MINLINE float pingpongf(float value, float scale)
MINLINE float compatible_signf(float f)
MINLINE float smoothminf(float a, float b, float c)
MINLINE float safe_powf(float base, float exponent)
int pow_i(int base, int exp)
MINLINE float safe_floored_modf(float a, float b)
VecBase< float, 3 > float3
MINLINE float safe_divide(float a, float b)
MINLINE int divide_floor_i(int a, int b)
MINLINE float safe_inverse_sqrtf(float a)
MINLINE float safe_logf(float a, float base)
MINLINE float safe_modf(float a, float b)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float