117 lines
10 KiB
C
117 lines
10 KiB
C
|
|
#include "../global.h"
|
|
|
|
char *map_range_node_value(ui_node_t *node, ui_node_socket_t *socket) {
|
|
char *val = parser_material_parse_value_input(node->inputs->buffer[0], false);
|
|
char *fmin = parser_material_parse_value_input(node->inputs->buffer[1], false);
|
|
char *fmax = parser_material_parse_value_input(node->inputs->buffer[2], false);
|
|
char *tmin = parser_material_parse_value_input(node->inputs->buffer[3], false);
|
|
char *tmax = parser_material_parse_value_input(node->inputs->buffer[4], false);
|
|
bool use_clamp = node->buttons->buffer[0]->default_value->buffer[0] > 0;
|
|
char *a = string("((%s - %s) / (%s - %s))", tmin, tmax, fmin, fmax);
|
|
char *out_val = string("(%s * %s + %s - %s * %s)", a, val, tmin, a, fmin);
|
|
if (use_clamp) {
|
|
return string("(clamp(%s, %s, %s))", out_val, tmin, tmax);
|
|
}
|
|
else {
|
|
return out_val;
|
|
}
|
|
}
|
|
|
|
void map_range_node_init() {
|
|
|
|
map_range_node_def = GC_ALLOC_INIT(ui_node_t, {.id = 0,
|
|
.name = _tr("Map Range"),
|
|
.type = "MAPRANGE",
|
|
.x = 0,
|
|
.y = 0,
|
|
.color = 0xff62676d,
|
|
.inputs = any_array_create_from_raw(
|
|
(void *[]){
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("Value"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(0.5),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("From Min"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(0.0),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("From Max"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(1.0),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("To Min"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(0.0),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("To Max"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(1.0),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
},
|
|
5),
|
|
.outputs = any_array_create_from_raw(
|
|
(void *[]){
|
|
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
|
.node_id = 0,
|
|
.name = _tr("Value"),
|
|
.type = "VALUE",
|
|
.color = 0xffa1a1a1,
|
|
.default_value = f32_array_create_x(0.0),
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.display = 0}),
|
|
},
|
|
1),
|
|
.buttons = any_array_create_from_raw(
|
|
(void *[]){
|
|
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Clamp"),
|
|
.type = "BOOL",
|
|
.output = 0,
|
|
.default_value = f32_array_create_x(0),
|
|
.data = NULL,
|
|
.min = 0.0,
|
|
.max = 1.0,
|
|
.precision = 100,
|
|
.height = 0}),
|
|
},
|
|
1),
|
|
.width = 0,
|
|
.flags = 0});
|
|
gc_root(map_range_node_def);
|
|
|
|
any_array_push(nodes_material_utilities, map_range_node_def);
|
|
any_map_set(parser_material_node_values, "MAPRANGE", map_range_node_value);
|
|
}
|