diff options
author | Charlie Jolly <charlie> | 2021-03-23 12:21:56 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-03-23 12:59:20 +0300 |
commit | d3758892987d76749fdf1211ed27ff77f39b5b3b (patch) | |
tree | 0e0b6b2a614b9829255cae77fb75f93696e7df7b /source/blender/nodes/NOD_math_functions.hh | |
parent | 4c19fcacc0b71271ca2fafc87ef5772a819e7075 (diff) |
Nodes: Add Refract and Faceforward functions to Vector Maths nodes
Cycles, Eevee, OSL, Geo, Attribute
Based on outdated refract patch D6619 by @cubic_sloth
`refract` and `faceforward` are standard functions in GLSL, OSL and Godot shader languages.
Adding these functions provides Blender shader artists access to these standard functions.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D10622
Diffstat (limited to 'source/blender/nodes/NOD_math_functions.hh')
-rw-r--r-- | source/blender/nodes/NOD_math_functions.hh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index c662220fea7..08496e044c5 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -351,6 +351,35 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return dispatch([](float3 a, float3 b, float3 c) { 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 float3::faceforward(a, b, c); }); + default: + return false; + } + return false; +} + +/** + * This is similar to try_dispatch_float_math_fl_to_fl, just with a different callback signature. + */ +template<typename Callback> +inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, + Callback &&callback) +{ + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); + if (info == nullptr) { + return false; + } + + /* This is just a utility function to keep the individual cases smaller. */ + auto dispatch = [&](auto math_function) -> bool { + callback(math_function, *info); + return true; + }; + + switch (operation) { + case NODE_VECTOR_MATH_REFRACT: + return dispatch([](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); default: return false; } |