Pixel-Composer/scripts/draw_surface_blend/draw_surface_blend.gml

58 lines
2.1 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
globalvar BLEND_TYPES;
2023-03-07 14:29:47 +01:00
BLEND_TYPES = [ "Normal", "Add", "Subtract", "Multiply", "Screen", "Overlay", "Hue", "Saturation", "Luminosity", "Maximum", "Minimum", "Replace", "Difference" ];
2022-01-13 05:24:03 +01:00
function draw_surface_blend(background, foreground, blend = 0, alpha = 1, _pre_alp = true, _mask = 0, tile = 0) {
2022-01-13 05:24:03 +01:00
if(!is_surface(background)) return;
var sh = sh_blend_normal
2023-02-19 02:13:19 +01:00
switch(array_safe_get(BLEND_TYPES, blend)) {
2023-02-17 11:31:33 +01:00
case "Normal" : sh = sh_blend_normal break;
case "Add" : sh = sh_blend_add; break;
case "Subtract" : sh = sh_blend_subtract; break;
case "Multiply" : sh = sh_blend_multiply; break;
case "Screen" : sh = sh_blend_screen; break;
case "Overlay" : sh = sh_blend_overlay; break;
case "Hue" : sh = sh_blend_hue; break;
case "Saturation" : sh = sh_blend_sat; break;
case "Luminosity" : sh = sh_blend_luma; break;
2023-02-14 05:32:32 +01:00
2023-02-17 11:31:33 +01:00
case "Maximum" : sh = sh_blend_max; break;
case "Minimum" : sh = sh_blend_min; break;
2023-02-19 13:49:20 +01:00
case "Replace" : sh = sh_blend_replace; break;
2023-03-07 14:29:47 +01:00
case "Difference" : sh = sh_blend_difference; break;
2023-02-17 11:31:33 +01:00
default: return;
2022-01-13 05:24:03 +01:00
}
2023-01-17 08:11:55 +01:00
2023-01-25 06:49:00 +01:00
var surf = surface_get_target();
2023-09-08 21:37:36 +02:00
var surf_w = surface_get_width_safe(surf);
var surf_h = surface_get_height_safe(surf);
2023-01-25 06:49:00 +01:00
if(is_surface(foreground)) {
shader_set(sh);
2023-09-09 13:52:16 +02:00
shader_set_surface("fore", foreground);
shader_set_surface("mask", _mask);
shader_set_i("useMask", _mask != 0? 1 : 0);
shader_set_f("dimension", surface_get_width_safe(background) / surface_get_width_safe(foreground), surface_get_height_safe(background) / surface_get_height_safe(foreground));
shader_set_f("opacity", alpha);
shader_set_i("preserveAlpha", _pre_alp);
shader_set_i("tile_type", tile);
2023-01-25 06:49:00 +01:00
}
2023-02-19 02:13:19 +01:00
BLEND_ALPHA
2023-01-25 06:49:00 +01:00
draw_surface_stretched_safe(background, 0, 0, surf_w, surf_h);
BLEND_NORMAL
2022-01-13 05:24:03 +01:00
shader_reset();
}
function draw_surface_blend_ext(bg, fg, _x, _y, _sx = 1, _sy = 1, _rot = 0, _col = c_white, _alpha = 1, _blend = 0) {
var _tmpS = surface_create_size(bg);
surface_set_shader(_tmpS);
shader_set_interpolation(fg);
2023-09-09 13:52:16 +02:00
draw_surface_ext_safe(fg, _x, _y, _sx, _sy, _rot, _col, 1);
surface_reset_shader();
draw_surface_blend(bg, _tmpS, _blend, _alpha, false);
surface_free(_tmpS);
2022-01-13 05:24:03 +01:00
}