26 b.add_input<
decl::Float>(
N_(
"Value")).
min(-10000.0f).max(10000.0f).default_value(1.0f);
28 b.add_input<
decl::Float>(
N_(
"From Max")).
min(-10000.0f).max(10000.0f).default_value(1.0f);
30 b.add_input<
decl::Float>(
N_(
"To Max")).
min(-10000.0f).max(10000.0f).default_value(1.0f);
31 b.add_input<
decl::Float>(
N_(
"Steps")).
min(-10000.0f).max(10000.0f).default_value(4.0f);
74 new_input_availability[index] = socket->type ==
type;
77 new_output_availability[index] = socket->type ==
type;
82 new_input_availability[5] =
false;
85 new_input_availability[11] =
false;
103 node->custom1 =
true;
125 switch (socket.
type) {
173 return "vector_map_range_linear";
175 return "vector_map_range_stepped";
177 return "vector_map_range_smoothstep";
179 return "vector_map_range_smootherstep";
185 return "map_range_linear";
187 return "map_range_stepped";
189 return "map_range_smoothstep";
191 return "map_range_smootherstep";
209 if (name !=
nullptr) {
215 if (
ret && storage.
clamp && !use_vector &&
217 GPU_link(mat,
"clamp_range",
out[0].link, in[3].link, in[4].link, &
out[0].link);
242 Clamp ?
"Map Range (clamped)" :
"Map Range (unclamped)",
243 [](
float value,
float from_min,
float from_max,
float to_min,
float to_max,
float *r_value) {
244 const float factor =
safe_divide(value - from_min, from_max - from_min);
245 float result = to_min + factor * (to_max - to_min);
246 if constexpr (
Clamp) {
263 Clamp ?
"Map Range Stepped (clamped)" :
"Map Range Stepped (unclamped)",
271 float factor =
safe_divide(value - from_min, from_max - from_min);
273 float result = to_min + factor * (to_max - to_min);
274 if constexpr (
Clamp) {
290 Clamp ?
"Vector Map Range (clamped)" :
"Vector Map Range (unclamped)",
299 if constexpr (
Clamp) {
316 Clamp ?
"Vector Map Range Stepped (clamped)" :
"Vector Map Range Stepped (unclamped)",
327 if constexpr (
Clamp) {
343 switch (interpolation_type) {
346 static auto fn = build_vector_linear<true>();
350 static auto fn = build_vector_linear<false>();
357 static auto fn = build_vector_stepped<true>();
361 static auto fn = build_vector_stepped<false>();
373 fn{
"Vector Map Range Smoothstep",
382 factor = (
float3(3.0f) - 2.0f * factor) * (factor * factor);
383 *r_value = factor * (to_max - to_min) + to_min;
396 fn{
"Vector Map Range Smootherstep",
405 factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f);
406 *r_value = factor * (to_max - to_min) + to_min;
417 switch (interpolation_type) {
420 static auto fn = build_float_linear<true>();
424 static auto fn = build_float_linear<false>();
431 static auto fn = build_float_stepped<true>();
435 static auto fn = build_float_stepped<false>();
447 fn{
"Map Range Smoothstep",
454 float factor =
safe_divide(value - from_min, from_max - from_min);
456 factor = (3.0f - 2.0f * factor) * (factor * factor);
457 *r_value = to_min + factor * (to_max - to_min);
470 fn{
"Map Range Smoothstep",
477 float factor =
safe_divide(value - from_min, from_max - from_min);
479 factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f);
480 *r_value = to_min + factor * (to_max - to_min);
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define SH_NODE_MAP_RANGE
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
#define NODE_CLASS_OP_VECTOR
void nodeRegisterType(struct bNodeType *ntype)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE void clamp_v3(float vec[3], float min, float max)
@ NODE_MAP_RANGE_SMOOTHERSTEP
@ NODE_MAP_RANGE_SMOOTHSTEP
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const MultiFunction *fn)
void operator()(LinkSearchOpParams ¶ms)
eCustomDataType data_type
T clamp(const T &a, const T &min, const T &max)
T safe_divide(const T &a, const T &b)
static void node_shader_init_map_range(bNodeTree *UNUSED(ntree), bNode *node)
static const char * gpu_shader_get_name(int mode, bool use_vector)
static auto build_vector_linear()
static void sh_node_map_range_build_multi_function(NodeMultiFunctionBuilder &builder)
static auto build_vector_stepped()
static void node_shader_buts_map_range(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static auto build_float_linear()
static int node_shader_map_range_ui_class(const bNode *node)
static std::optional< eCustomDataType > node_type_from_other_socket(const bNodeSocket &socket)
static float clamp_range(const float value, const float min, const float max)
static void node_shader_update_map_range(bNodeTree *ntree, bNode *node)
static int gpu_shader_map_range(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_map_range_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void sh_node_map_range_declare(NodeDeclarationBuilder &b)
static auto build_float_stepped()
vec_base< float, 3 > float3
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_map_range()
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
int RNA_enum_get(PointerRNA *ptr, const char *name)
uint8_t interpolation_type
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
NodeMultiFunctionBuildFunction build_multi_function
NodeDeclareFunction declare
int(* ui_class)(const struct bNode *node)