Skip to content

Commit

Permalink
Merge pull request #1807 from MathemanFlo/ReplaceColorNode
Browse files Browse the repository at this point in the history
Implement replace node
  • Loading branch information
luboslenco authored Dec 30, 2024
2 parents 60a4b5d + b81bea7 commit 820beb2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
69 changes: 69 additions & 0 deletions base/sources/nodes_material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 8 additions & 0 deletions base/sources/parser_material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 820beb2

Please sign in to comment.