2024-10-09 04:09:24 +02:00
|
|
|
function __init_mask_modifier(_mask_index) {
|
2024-08-08 06:57:51 +02:00
|
|
|
var _ind = array_length(inputs);
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(_ind + 0, nodeValue_Bool("Invert mask", self, false));
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(_ind + 1, nodeValue_Float("Mask feather", self, 0))
|
2024-03-24 04:58:08 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 32, 0.1] });
|
2023-11-24 10:41:53 +01:00
|
|
|
|
|
|
|
__mask_index = _mask_index;
|
|
|
|
__mask_mod_index = _ind;
|
|
|
|
__mask_invert = false;
|
|
|
|
__mask_feather = 0;
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
function __step_mask_modifier() {
|
2023-11-24 10:41:53 +01:00
|
|
|
var _msk = is_surface(getSingleValue(__mask_index));
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[__mask_mod_index + 0].setVisible(_msk);
|
|
|
|
inputs[__mask_mod_index + 1].setVisible(_msk);
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
function __process_mask_modifier(data) {
|
2023-11-24 10:41:53 +01:00
|
|
|
__mask_invert = data[__mask_mod_index + 0];
|
|
|
|
__mask_feather = data[__mask_mod_index + 1];
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
function mask_modify(mask, invert = false, feather = 0) {
|
2023-11-24 10:41:53 +01:00
|
|
|
if(!is_surface(mask)) return mask;
|
|
|
|
if(!invert && feather == 0) return mask;
|
|
|
|
|
|
|
|
if(!struct_has(self, "__temp_mask")) __temp_mask = surface_create(1, 1);
|
|
|
|
|
|
|
|
__temp_mask = surface_verify(__temp_mask, surface_get_width_safe(mask), surface_get_height_safe(mask));
|
|
|
|
|
2024-04-02 09:49:26 +02:00
|
|
|
surface_set_shader(__temp_mask, sh_mask_invert);
|
|
|
|
shader_set_i("invert", invert);
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(mask);
|
2023-11-24 10:41:53 +01:00
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
if(feather > 0) {
|
|
|
|
if(!struct_has(self, "__blur_hori")) surface_blur_init();
|
|
|
|
__temp_mask = surface_apply_gaussian(__temp_mask, feather, false, c_white, 1, noone);
|
|
|
|
}
|
|
|
|
|
|
|
|
return __temp_mask;
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|
2023-11-24 10:41:53 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
function mask_apply(original, edited, mask, mix = 1) {
|
2023-02-17 11:31:33 +01:00
|
|
|
if(!is_surface(mask) && mix == 1) return edited;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var _f = surface_get_format(edited);
|
|
|
|
var _s = surface_create_size(original, _f);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
if(is_surface(mask) && __mask_feather > 0) {
|
|
|
|
if(!struct_has(self, "__blur_hori")) surface_blur_init();
|
|
|
|
mask = surface_apply_gaussian(mask, __mask_feather, false, c_white, 1, noone);
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_set_shader(_s, sh_mask);
|
|
|
|
shader_set_surface("original", original);
|
|
|
|
shader_set_surface("edited", edited);
|
|
|
|
shader_set_surface("mask", mask);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
shader_set_i("useMask", is_surface(mask));
|
|
|
|
shader_set_i("invMask", __mask_invert);
|
|
|
|
shader_set_f("mixRatio", mix);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-10-09 06:38:35 +02:00
|
|
|
draw_empty();
|
2023-11-24 10:41:53 +01:00
|
|
|
surface_reset_shader();
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-11-09 04:02:41 +01:00
|
|
|
surface_free(edited);
|
|
|
|
return _s;
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|
2023-11-09 04:02:41 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
function channel_apply(original, edited, channel) {
|
2023-11-09 04:02:41 +01:00
|
|
|
if(channel == 0b1111) return edited;
|
2024-10-13 11:43:44 +02:00
|
|
|
if(!surface_exists(original)) return edited;
|
2023-11-09 04:02:41 +01:00
|
|
|
|
|
|
|
var _f = surface_get_format(edited);
|
|
|
|
var _s = surface_create_size(original, _f);
|
|
|
|
|
|
|
|
surface_set_target(_s);
|
|
|
|
DRAW_CLEAR
|
2024-10-09 04:09:24 +02:00
|
|
|
BLEND_ADD_ONE
|
2023-11-09 04:02:41 +01:00
|
|
|
|
|
|
|
gpu_set_colorwriteenable(!(channel & 0b0001), !(channel & 0b0010), !(channel & 0b0100), !(channel & 0b1000));
|
2024-10-09 04:09:24 +02:00
|
|
|
draw_surface(original, 0, 0);
|
2023-11-09 04:02:41 +01:00
|
|
|
|
|
|
|
gpu_set_colorwriteenable(channel & 0b0001, channel & 0b0010, channel & 0b0100, channel & 0b1000);
|
2024-10-09 04:09:24 +02:00
|
|
|
draw_surface(edited, 0, 0);
|
2023-11-09 04:02:41 +01:00
|
|
|
|
|
|
|
gpu_set_colorwriteenable(1, 1, 1, 1);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
surface_free(edited);
|
|
|
|
return _s;
|
2024-10-09 04:09:24 +02:00
|
|
|
}
|