paint: use iris for neural nodes

This commit is contained in:
luboslenco
2026-06-18 16:57:31 +02:00
parent 963014674b
commit d73d4d8a0d
9 changed files with 56 additions and 207 deletions
-1
View File
@@ -779,7 +779,6 @@ void neural_node_load_result(ui_node_t *node);
void text_to_image_node_run(ui_node_t *node, void (*callback)(ui_node_t *));
void upscale_image_node_init();
void image_to_pbr_node_init();
void inpaint_image_node_init();
void text_to_image_node_init();
void texture_mesh_node_init();
void text_to_text_node_clear();
-1
View File
@@ -105,7 +105,6 @@
#include "nodes_neural/edit_image_node.c"
#include "nodes_neural/image_to_3d_mesh_node.c"
#include "nodes_neural/image_to_pbr_node.c"
#include "nodes_neural/inpaint_image_node.c"
#include "nodes_neural/neural_node.c"
#include "nodes_neural/neural_node_models.c"
#include "nodes_neural/repeat_node.c"
-1
View File
@@ -91,7 +91,6 @@ void nodes_material_init() {
image_to_3d_mesh_node_init();
#endif
image_to_pbr_node_init();
inpaint_image_node_init();
repeat_node_init();
save_image_node_init();
text_to_image_node_init();
+44 -11
View File
@@ -23,33 +23,52 @@ void edit_image_node_button(i32 node_id) {
char *prompt = ui_text_area(ui_nest(h, 1), UI_ALIGN_LEFT, true, tr("prompt"), true);
node->buttons->buffer[0]->height = string_split(prompt, "\n")->length + 4;
ui_handle_t *hs = ui_nest(h, 2);
if (hs->init) {
hs->f = 1.0;
}
f32 strength = ui_slider(hs, tr("Strength"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
f32 variance = ui_slider(ui_nest(h, 2), tr("Variance"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
bool tiled = ui_check(ui_nest(h, 3), tr("Tiled"), "");
bool tiled = ui_check(ui_nest(h, 3), tr("Tile"), "");
if (neural_node_button(node, models->buffer[model])) {
ui_node_t *from_node = neural_from_node(node->inputs->buffer[0], 0);
gpu_texture_t *input = ui_nodes_get_node_preview_image(from_node);
if (input != NULL) {
ui_node_t *mask_node = neural_from_node(node->inputs->buffer[1], 1);
gpu_texture_t *mask = mask_node != NULL ? ui_nodes_get_node_preview_image(mask_node) : NULL;
char *dir = neural_node_dir();
#ifdef IRON_BGRA
buffer_t *input_buf = buffer_bgra_swap(gpu_get_texture_pixels(input)); // Vulkan non-rt textures need a flip
#else
buffer_t *input_buf = gpu_get_texture_pixels(input);
#endif
char *dir = neural_node_dir();
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
if (mask != NULL) {
buffer_t *mask_buf = gpu_get_texture_pixels(mask);
for (uint32_t i = 0; i < mask_buf->length / 4; ++i) {
if (mask_buf->buffer[i * 4] < 200 || mask_buf->buffer[i * 4 + 1] < 200 || mask_buf->buffer[i * 4 + 2] < 200) {
mask_buf->buffer[i * 4] = 255;
mask_buf->buffer[i * 4 + 1] = 255;
mask_buf->buffer[i * 4 + 2] = 255;
}
else {
mask_buf->buffer[i * 4] = 0;
mask_buf->buffer[i * 4 + 1] = 0;
mask_buf->buffer[i * 4 + 2] = 0;
}
}
iron_write_png(string("%s%smask.png", dir, PATH_SEP), mask_buf, mask->width, mask->height, 0);
}
string_array_t *argv;
if (model == 0) {
argv = edit_image_node_flux_klein_args(dir);
}
// string_array_push(argv, string("%f", strength));
if (variance > 0.0) {
string_array_push(argv, "--vary");
string_array_push(argv, string("%f", variance));
}
string_array_push(argv, "--seed");
string_array_push(argv, "-1");
string_array_push(argv, "-W");
@@ -60,10 +79,14 @@ void edit_image_node_button(i32 node_id) {
string_array_push(argv, prompt);
string_array_push(argv, "-i");
string_array_push(argv, string("%s/input.png", dir));
if (mask != NULL) {
string_array_push(argv, "--mask");
string_array_push(argv, string("%s/mask.png", dir));
}
string_array_push(argv, "-o");
string_array_push(argv, string("%s/output.png", dir));
if (tiled) {
string_array_push(argv, "--tileable");
string_array_push(argv, "--tile");
}
if (g_config->neural_res >= 2048) {
string_array_push(argv, "--vae-tiling");
@@ -97,8 +120,18 @@ void edit_image_node_init() {
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Mask"),
.type = "VALUE",
.color = 0xffa1a1a1,
.default_value = f32_array_create_x(1.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
},
1),
2),
.outputs = any_array_create_from_raw(
(void *[]){
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
@@ -63,7 +63,7 @@ void image_to_pbr_node_check_result(void (*done)(gpu_texture_t *)) {
}
}
void image_to_pbr_node_run_da3(bool tileable, int width, int height, void (*done)(gpu_texture_t *)) {
void image_to_pbr_node_run_da3(bool tile, int width, int height, void (*done)(gpu_texture_t *)) {
char *dir = neural_node_dir();
string_array_t *argv = any_array_create_from_raw(
(void *[]){
@@ -81,8 +81,8 @@ void image_to_pbr_node_run_da3(bool tileable, int width, int height, void (*done
string("%s/output.png", dir),
},
12);
if (tileable) {
string_array_push(argv, "--tileable");
if (tile) {
string_array_push(argv, "--tile");
}
string_array_push(argv, NULL);
@@ -288,9 +288,9 @@ void image_to_pbr_node_button(i32 node_id) {
#endif
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
bool tileable = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
bool tile = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
image_to_pbr_node_node_id = node_id;
image_to_pbr_node_run_da3(tileable, input->width, input->height, &image_to_pbr_node_depth_done);
image_to_pbr_node_run_da3(tile, input->width, input->height, &image_to_pbr_node_depth_done);
}
}
}
@@ -383,7 +383,7 @@ void image_to_pbr_node_init() {
.max = 1.0,
.precision = 100,
.height = 2}),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
.type = "BOOL",
.output = 0,
.default_value = f32_array_create_x(0),
@@ -1,180 +0,0 @@
#include "../global.h"
f32 inpaint_image_node_strength;
bool inpaint_image_node_tiled;
static string_array_t *inpaint_image_node_flux_klein_args(char *dir) {
string_array_t *argv = any_array_create_from_raw(
(void *[]){
string("%s/%s", dir, neural_node_iris_bin()),
"-d",
string("%s", dir),
},
3);
return argv;
}
void inpaint_image_node_button_on_next_frame(ui_node_t *node) {
ui_node_t *from_node = neural_from_node(node->inputs->buffer[0], 0);
ui_node_t *mask_node = neural_from_node(node->inputs->buffer[1], 1);
gpu_texture_t *input = ui_nodes_get_node_preview_image(from_node);
gpu_texture_t *mask = ui_nodes_get_node_preview_image(mask_node);
if (input != NULL && mask != NULL) {
char *node_name = parser_material_node_name(node, NULL);
ui_handle_t *h = ui_handle(node_name);
i32 model = ui_nest(h, 0)->i;
char *dir = neural_node_dir();
if (model == 0) {
#ifdef IRON_BGRA
buffer_t *input_buf = buffer_bgra_swap(gpu_get_texture_pixels(input)); // Vulkan non-rt textures need a flip
#else
buffer_t *input_buf = gpu_get_texture_pixels(input);
#endif
iron_write_png(string("%s%sinput.png", dir, PATH_SEP), input_buf, input->width, input->height, 0);
buffer_t *mask_buf = gpu_get_texture_pixels(mask);
for (uint32_t i = 0; i < mask_buf->length / 4; ++i) {
if (mask_buf->buffer[i * 4] < 200 || mask_buf->buffer[i * 4 + 1] < 200 || mask_buf->buffer[i * 4 + 2] < 200) {
mask_buf->buffer[i * 4] = 255;
mask_buf->buffer[i * 4 + 1] = 255;
mask_buf->buffer[i * 4 + 2] = 255;
}
else {
mask_buf->buffer[i * 4] = 0;
mask_buf->buffer[i * 4 + 1] = 0;
mask_buf->buffer[i * 4 + 2] = 0;
}
}
iron_write_png(string("%s%smask.png", dir, PATH_SEP), mask_buf, mask->width, mask->height, 0);
}
string_array_t *argv;
if (model == 0) {
argv = edit_image_node_flux_klein_args(dir);
string_array_push(argv, "-p");
string_array_push(argv, "");
string_array_push(argv, "-i");
string_array_push(argv, string("%s/input.png", dir));
string_array_push(argv, "--mask");
string_array_push(argv, string("%s/mask.png", dir));
}
if (g_config->neural_res >= 2048) {
string_array_push(argv, "--vae-tiling");
}
// string_array_push(argv, string("%f", inpaint_image_node_strength));
string_array_push(argv, "--seed");
string_array_push(argv, "-1");
string_array_push(argv, "-W");
string_array_push(argv, string("%d", g_config->neural_res));
string_array_push(argv, "-H");
string_array_push(argv, string("%d", g_config->neural_res));
string_array_push(argv, "-o");
string_array_push(argv, string("%s/output.png", dir));
if (inpaint_image_node_tiled) {
string_array_push(argv, "--tileable");
}
string_array_push(argv, NULL);
iron_exec_async(argv->buffer[0], argv->buffer);
sys_notify_on_update(neural_node_check_result, node);
}
}
void inpaint_image_node_button(i32 node_id) {
ui_node_canvas_t *canvas = ui_nodes_get_canvas(true);
ui_node_t *node = ui_get_node(canvas->nodes, node_id);
char *node_name = parser_material_node_name(node, NULL);
ui_handle_t *h = ui_handle(node_name);
string_array_t *models = any_array_create_from_raw(
(void *[]){
"FLUX 2 klein",
},
1);
i32 model = ui_combo(ui_nest(h, 0), models, tr("Model"), false, UI_ALIGN_LEFT, true);
ui_handle_t *hs = ui_nest(h, 1);
if (hs->init) {
hs->f = 1.0;
}
inpaint_image_node_strength = ui_slider(hs, tr("Strength"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_LEFT, true);
inpaint_image_node_tiled = ui_check(ui_nest(h, 2), tr("Tiled"), "");
if (neural_node_button(node, models->buffer[model])) {
sys_notify_on_next_frame(&inpaint_image_node_button_on_next_frame, node);
}
}
void inpaint_image_node_init() {
ui_node_t *inpaint_image_node_def =
GC_ALLOC_INIT(ui_node_t, {.id = 0,
.name = _tr("Inpaint Image"),
.type = "NEURAL_INPAINT_IMAGE",
.x = 0,
.y = 0,
.color = 0xff4982a0,
.inputs = any_array_create_from_raw(
(void *[]){
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Color"),
.type = "RGBA",
.color = 0xffc7c729,
.default_value = f32_array_create_xyzw(0.0, 0.0, 0.0, 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("Mask"),
.type = "VALUE",
.color = 0xffa1a1a1,
.default_value = f32_array_create_x(1.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
},
2),
.outputs = any_array_create_from_raw(
(void *[]){
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Color"),
.type = "RGBA",
.color = 0xffc7c729,
.default_value = f32_array_create_xyzw(0.0, 0.0, 0.0, 1.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 = "inpaint_image_node_button",
.type = "CUSTOM",
.output = -1,
.default_value = f32_array_create_x(0),
.data = NULL,
.min = 0.0,
.max = 1.0,
.precision = 100,
.height = 4}),
},
1),
.width = 0,
.flags = 0});
any_array_push(nodes_material_neural, inpaint_image_node_def);
any_map_set(parser_material_node_vectors, "NEURAL_INPAINT_IMAGE", neural_node_vector);
any_map_set(ui_nodes_custom_buttons, "inpaint_image_node_button", inpaint_image_node_button);
}
@@ -38,7 +38,7 @@ void text_to_image_node_run(ui_node_t *node, void (*callback)(ui_node_t *)) {
string_array_push(argv, "-p");
string_array_push(argv, string("'%s'", prompt));
if (node->buttons->buffer[1]->default_value->buffer[0] > 0.0) {
string_array_push(argv, "--tileable");
string_array_push(argv, "--tile");
}
string_array_push(argv, NULL);
@@ -112,7 +112,7 @@ void text_to_image_node_init() {
.max = 1.0,
.precision = 100,
.height = 1}),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
.type = "BOOL",
.output = 0,
.default_value = f32_array_create_x(0),
@@ -38,9 +38,8 @@ void upscale_image_node_button(i32 node_id) {
},
8);
bool tileable = node->buttons->buffer[1]->default_value->buffer[0] > 0.0;
if (tileable) {
string_array_push(argv, "--tileable");
if (node->buttons->buffer[1]->default_value->buffer[0] > 0.0) {
string_array_push(argv, "--tile");
}
string_array_push(argv, NULL);
@@ -98,7 +97,7 @@ void upscale_image_node_init() {
.max = 1.0,
.precision = 100,
.height = 2}),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tiled"),
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Tile"),
.type = "BOOL",
.output = 0,
.default_value = f32_array_create_x(0),
+1 -1
View File
@@ -100,7 +100,7 @@ gpu_texture_t *ui_nodes_get_node_preview_image(ui_node_t *n) {
img = rt->_image;
}
}
else if (starts_with(n->type, "NEURAL_")) {
else if (starts_with(n->type, "NEURAL_") && n->outputs->length > 0) {
i32 socket = i32_imap_get(g_context->node_preview_socket_map, n->id);
if (socket < 0 || socket >= n->outputs->length) {
socket = 0;