From b81bea76986400717f7bba0ea91156191404b8e6 Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Mon, 30 Dec 2024 14:10:30 +0100 Subject: [PATCH] Implement replace node --- base/sources/nodes_material.ts | 69 +++++++++++++++++++++++++++++++++ base/sources/parser_material.ts | 8 ++++ 2 files changed, 77 insertions(+) diff --git a/base/sources/nodes_material.ts b/base/sources/nodes_material.ts index 2b896a584..7403c7cfc 100644 --- a/base/sources/nodes_material.ts +++ b/base/sources/nodes_material.ts @@ -2484,6 +2484,75 @@ let nodes_material_color: ui_node_t[] = [ buttons: [], width: 0 }, + { + id: 0, + name: _tr("Replace Color"), + type: "REPLACECOL", + x: 0, + y: 0, + color: 0xff448c6d, + inputs: [ + { + id: 0, + node_id: 0, + name: _tr("Color"), + type: "RGBA", + color: 0xffc7c729, + default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) + }, + { + id: 0, + node_id: 0, + name: _tr("Old Color"), + type: "RGBA", + color: 0xffc7c729, + default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) + }, + { + id: 0, + node_id: 0, + name: _tr("New Color"), + type: "RGBA", + color: 0xffc7c729, + default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) + }, + { + id: 0, + node_id: 0, + name: _tr("Radius"), + type: "VALUE", + color: 0xffa1a1a1, + default_value: f32_array_create_x(0.1), + min: 0.0, + max: 1.74, + precision: 100, + display: 0 + }, + { + id: 0, + node_id: 0, + name: _tr("Fuzziness"), + type: "VALUE", + color: 0xffa1a1a1, + default_value: f32_array_create_x(0.0), + min: 0.0, + max: 1.0, + precision: 100, + display: 0 + } + ], + outputs: [ + { + id: 0, + node_id: 0, + name: _tr("Color"), + type: "RGBA", + color: 0xffc7c729, + default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) + } + ], + buttons: [] + }, { id: 0, name: _tr("Warp"), diff --git a/base/sources/parser_material.ts b/base/sources/parser_material.ts index e97c2886e..0ca9ab376 100644 --- a/base/sources/parser_material.ts +++ b/base/sources/parser_material.ts @@ -734,6 +734,14 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t) let col: string = parser_material_parse_vector_input(node.inputs[1]); return "(floor(100.0 * " + strength + " * " + col + ") / (100.0 * " + strength + "))"; } + else if (node.type == "REPLACECOL") { + let inputColor: string = parser_material_parse_vector_input(node.inputs[0]); + let oldColor: string = parser_material_parse_vector_input(node.inputs[1]); + let newColor: string = parser_material_parse_vector_input(node.inputs[2]); + let radius: string = parser_material_parse_value_input(node.inputs[3]); + let fuzziness: string = parser_material_parse_value_input(node.inputs[4]); + return "mix(" + newColor + ", " + inputColor + ", clamp((distance(" + oldColor + ", " + inputColor + ") - " + radius + ") / max(" + fuzziness + ", " + parser_material_eps + "), 0.0, 1.0))"; + } else if (node.type == "VALTORGB") { // ColorRamp let fac: string = parser_material_parse_value_input(node.inputs[0]); let data0: i32 = node.buttons[0].data[0];