Files
armorpaint/lab/sources/nodes/tiling_node.ts
T

166 lines
4.2 KiB
TypeScript
Raw Normal View History

2024-03-14 23:58:24 +01:00
type tiling_node_t = {
base?: logic_node_t;
2025-06-19 19:55:16 +02:00
result?: gpu_texture_t;
2024-03-14 23:58:24 +01:00
};
2025-06-19 19:55:16 +02:00
let tiling_node_image: gpu_texture_t = null;
2024-03-14 23:58:24 +01:00
let tiling_node_prompt: string = "";
let tiling_node_strength: f32 = 0.5;
let tiling_node_auto: bool = true;
2024-10-19 23:37:47 +02:00
function tiling_node_create(raw: ui_node_t, args: f32_array_t): tiling_node_t {
2024-03-14 23:58:24 +01:00
let n: float_node_t = {};
2024-10-21 19:28:43 +02:00
n.base = logic_node_create(n);
2024-03-14 23:58:24 +01:00
n.base.get_as_image = tiling_node_get_as_image;
n.base.get_cached_image = tiling_node_get_cached_image;
tiling_node_init();
return n;
}
function tiling_node_init() {
if (tiling_node_image == null) {
2025-03-10 20:38:53 +01:00
tiling_node_image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
2024-03-14 23:58:24 +01:00
}
}
2024-10-21 19:28:43 +02:00
function tiling_node_button(node_id: i32) {
let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id);
2024-10-23 14:00:19 +02:00
tiling_node_auto = node.buttons[0].default_value[0] == 0 ? false : true;
2024-03-14 23:58:24 +01:00
if (!tiling_node_auto) {
2024-09-03 15:52:05 +02:00
let tiling_node_strength_handle: ui_handle_t = ui_handle(__ID__);
2024-04-24 12:14:47 +02:00
if (tiling_node_strength_handle.init) {
tiling_node_strength_handle.value = tiling_node_strength;
}
2024-09-03 15:52:05 +02:00
tiling_node_strength = ui_slider(tiling_node_strength_handle, tr("strength"), 0, 1, true);
tiling_node_prompt = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true);
2024-03-20 16:13:54 +01:00
node.buttons[1].height = 1 + string_split(tiling_node_prompt, "\n").length;
}
else {
node.buttons[1].height = 0;
2024-03-14 23:58:24 +01:00
}
}
2025-06-19 19:55:16 +02:00
function tiling_node_get_as_image(self: tiling_node_t, from: i32): gpu_texture_t {
let source: gpu_texture_t = logic_node_input_get_as_image(self.base.inputs[0]);
2025-03-10 20:26:45 +01:00
draw_begin(tiling_node_image);
2025-03-02 19:44:26 +01:00
draw_scaled_image(source, 0, 0, config_get_texture_res_x(), config_get_texture_res_y());
2025-03-10 20:26:45 +01:00
draw_end();
2024-04-02 15:45:49 +02:00
console_progress(tr("Processing") + " - " + tr("Tiling"));
2024-03-14 23:58:24 +01:00
2024-04-02 15:45:49 +02:00
if (tiling_node_auto){
self.result = inpaint_node_texsynth_inpaint(tiling_node_image, true, null);
}
else {
self.result = tiling_node_sd_tiling(tiling_node_image, -1);
}
return self.result;
2024-03-14 23:58:24 +01:00
}
2025-06-19 19:55:16 +02:00
function tiling_node_get_cached_image(self: tiling_node_t): gpu_texture_t {
2024-03-14 23:58:24 +01:00
return self.result;
}
2025-06-19 19:55:16 +02:00
function tiling_node_sd_tiling(image: gpu_texture_t, seed: i32): gpu_texture_t {
2024-03-14 23:58:24 +01:00
text_to_photo_node_tiling = false;
2025-06-19 19:55:16 +02:00
let tile: gpu_texture_t = gpu_create_render_target(512, 512);
2025-03-10 20:26:45 +01:00
draw_begin(tile);
2025-03-02 19:44:26 +01:00
draw_scaled_image(image, -256, -256, 512, 512);
draw_scaled_image(image, 256, -256, 512, 512);
draw_scaled_image(image, -256, 256, 512, 512);
draw_scaled_image(image, 256, 256, 512, 512);
2025-03-10 20:26:45 +01:00
draw_end();
2024-03-14 23:58:24 +01:00
2024-08-31 17:24:01 +02:00
let u8a: u8_array_t = u8_array_create(512 * 512);
2024-03-21 21:06:41 +01:00
for (let i: i32 = 0; i < 512 * 512; ++i) {
2024-08-31 17:24:01 +02:00
let x: i32 = i % 512;
let y: i32 = math_floor(i / 512);
let l: i32 = y < 256 ? y : (511 - y);
2024-03-14 23:58:24 +01:00
u8a[i] = (x > 256 - l && x < 256 + l) ? 0 : 255;
}
2024-03-21 21:06:41 +01:00
// for (let i: i32 = 0; i < 512 * 512; ++i) u8a[i] = 255;
// for (let x: i32 = (256 - 32); x < (256 + 32); ++x) {
// for (let y: i32 = 0; y < 512; ++y) {
2024-03-14 23:58:24 +01:00
// u8a[y * 512 + x] = 0;
// }
// }
2024-03-21 21:06:41 +01:00
// for (let x: i32 = 0; x < 512; ++x) {
// for (let y: i32 = (256 - 32); y < 256 + 32); ++y) {
2024-03-14 23:58:24 +01:00
// u8a[y * 512 + x] = 0;
// }
// }
2025-06-19 19:55:16 +02:00
let mask: gpu_texture_t = gpu_create_texture_from_bytes(u8a, 512, 512, tex_format_t.R8);
2024-03-14 23:58:24 +01:00
inpaint_node_prompt = tiling_node_prompt;
inpaint_node_strength = tiling_node_strength;
2024-03-20 16:13:54 +01:00
if (seed >= 0) {
random_node_set_seed(seed);
}
2024-04-02 15:45:49 +02:00
return inpaint_node_sd_inpaint(tile, mask);
2024-03-14 23:58:24 +01:00
}
2024-09-03 15:52:05 +02:00
let tiling_node_def: ui_node_t = {
2024-03-14 23:58:24 +01:00
id: 0,
name: _tr("Tiling"),
type: "tiling_node",
x: 0,
y: 0,
color: 0xff4982a0,
inputs: [
{
id: 0,
node_id: 0,
name: _tr("Color"),
type: "RGBA",
color: 0xffc7c729,
2024-04-15 21:28:01 +02:00
default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
2024-04-10 19:39:17 +02:00
min: 0.0,
max: 1.0,
precision: 100,
display: 0
2024-03-14 23:58:24 +01:00
}
],
outputs: [
{
id: 0,
node_id: 0,
name: _tr("Color"),
type: "RGBA",
color: 0xffc7c729,
2024-04-15 21:28:01 +02:00
default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
2024-04-10 19:39:17 +02:00
min: 0.0,
max: 1.0,
precision: 100,
display: 0
2024-03-14 23:58:24 +01:00
}
],
buttons: [
{
name: _tr("auto"),
type: "BOOL",
2024-04-10 19:39:17 +02:00
output: 0,
2024-04-24 12:14:47 +02:00
default_value: f32_array_create_x(1),
2024-04-10 19:39:17 +02:00
data: null,
min: 0.0,
max: 1.0,
precision: 100,
height: 0
2024-03-14 23:58:24 +01:00
},
{
2024-10-21 19:28:43 +02:00
name: "tiling_node_button",
2024-03-14 23:58:24 +01:00
type: "CUSTOM",
2024-04-10 19:39:17 +02:00
output: -1,
2024-10-21 19:28:43 +02:00
default_value: f32_array_create_x(0),
2024-04-10 19:39:17 +02:00
data: null,
min: 0.0,
max: 1.0,
precision: 100,
2024-03-14 23:58:24 +01:00
height: 0
}
2024-04-10 19:39:17 +02:00
],
width: 0
2024-03-14 23:58:24 +01:00
};