diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 9c3536258..a6fbaead6 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -288,6 +288,7 @@ {"name":"surface_functions","order":5,"path":"scripts/surface_functions/surface_functions.yy",}, {"name":"__node_iterator_inline","order":8,"path":"scripts/__node_iterator_inline/__node_iterator_inline.yy",}, {"name":"s_MKFX","order":6,"path":"sprites/s_MKFX/s_MKFX.yy",}, + {"name":"sh_region_fill_inner","order":3,"path":"shaders/sh_region_fill_inner/sh_region_fill_inner.yy",}, {"name":"_f_sdf","order":13,"path":"fonts/_f_sdf/_f_sdf.yy",}, {"name":"dynaSurf_iso","order":1,"path":"scripts/dynaSurf_iso/dynaSurf_iso.yy",}, {"name":"sh_fd_add_velocity_glsl","order":1,"path":"shaders/sh_fd_add_velocity_glsl/sh_fd_add_velocity_glsl.yy",}, @@ -488,6 +489,7 @@ {"name":"GMSSimpleMIDI","order":15,"path":"extensions/GMSSimpleMIDI/GMSSimpleMIDI.yy",}, {"name":"s_node_fluidSim_domain","order":6,"path":"sprites/s_node_fluidSim_domain/s_node_fluidSim_domain.yy",}, {"name":"s_node_displace","order":17,"path":"sprites/s_node_displace/s_node_displace.yy",}, + {"name":"sh_region_fill_map","order":4,"path":"shaders/sh_region_fill_map/sh_region_fill_map.yy",}, {"name":"sh_polar","order":1,"path":"shaders/sh_polar/sh_polar.yy",}, {"name":"s_node_warp_mesh","order":10,"path":"sprites/s_node_warp_mesh/s_node_warp_mesh.yy",}, {"name":"sh_pixel_cloud","order":4,"path":"shaders/sh_pixel_cloud/sh_pixel_cloud.yy",}, @@ -965,6 +967,7 @@ {"name":"node_perlin","order":8,"path":"scripts/node_perlin/node_perlin.yy",}, {"name":"node_blur_non_uniform","order":4,"path":"scripts/node_blur_non_uniform/node_blur_non_uniform.yy",}, {"name":"node_feedback_input","order":1,"path":"scripts/node_feedback_input/node_feedback_input.yy",}, + {"name":"node_bend","order":18,"path":"scripts/node_bend/node_bend.yy",}, {"name":"s_node_vfx_trail","order":13,"path":"sprites/s_node_vfx_trail/s_node_vfx_trail.yy",}, {"name":"s_node_gui_in","order":37,"path":"sprites/s_node_gui_in/s_node_gui_in.yy",}, {"name":"s_node_base_conversion","order":10,"path":"sprites/s_node_base_conversion/s_node_base_conversion.yy",}, @@ -1003,6 +1006,7 @@ {"name":"FirebaseREST_HTTP_Success_Firestore","order":19,"path":"scripts/FirebaseREST_HTTP_Success_Firestore/FirebaseREST_HTTP_Success_Firestore.yy",}, {"name":"s_node_pb_draw_rectangle","order":13,"path":"sprites/s_node_pb_draw_rectangle/s_node_pb_draw_rectangle.yy",}, {"name":"panel_animation","order":1,"path":"scripts/panel_animation/panel_animation.yy",}, + {"name":"sh_bend_arc","order":13,"path":"shaders/sh_bend_arc/sh_bend_arc.yy",}, {"name":"node_array_rearrange","order":19,"path":"scripts/node_array_rearrange/node_array_rearrange.yy",}, {"name":"sh_pb_to_mask","order":7,"path":"shaders/sh_pb_to_mask/sh_pb_to_mask.yy",}, {"name":"d3d_gizmo_plane","order":5,"path":"scripts/d3d_gizmo_plane/d3d_gizmo_plane.yy",}, @@ -1203,6 +1207,7 @@ {"name":"s_node_flood_fill","order":24,"path":"sprites/s_node_flood_fill/s_node_flood_fill.yy",}, {"name":"json_compare","order":21,"path":"scripts/json_compare/json_compare.yy",}, {"name":"node_rigid_force_apply","order":4,"path":"scripts/node_rigid_force_apply/node_rigid_force_apply.yy",}, + {"name":"checkboxActive","order":38,"path":"scripts/checkboxActive/checkboxActive.yy",}, {"name":"__node_shader","order":21,"path":"scripts/__node_shader/__node_shader.yy",}, {"name":"__node_iterator","order":6,"path":"scripts/__node_iterator/__node_iterator.yy",}, {"name":"s_node_rigid_variable","order":8,"path":"sprites/s_node_rigid_variable/s_node_rigid_variable.yy",}, @@ -1552,6 +1557,7 @@ {"name":"node_scale_algo","order":12,"path":"scripts/node_scale_algo/node_scale_algo.yy",}, {"name":"s_node_image_replace","order":49,"path":"sprites/s_node_image_replace/s_node_image_replace.yy",}, {"name":"node_alpha_hash","order":11,"path":"scripts/node_alpha_hash/node_alpha_hash.yy",}, + {"name":"sh_region_fill_border","order":5,"path":"shaders/sh_region_fill_border/sh_region_fill_border.yy",}, {"name":"sh_mask_modify","order":2,"path":"shaders/sh_mask_modify/sh_mask_modify.yy",}, {"name":"toggleGroup","order":31,"path":"scripts/toggleGroup/toggleGroup.yy",}, {"name":"mouse_input","order":1,"path":"scripts/mouse_input/mouse_input.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 56ec3ef82..7b664d2ec 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -480,6 +480,7 @@ {"id":{"name":"surface_functions","path":"scripts/surface_functions/surface_functions.yy",},}, {"id":{"name":"__node_iterator_inline","path":"scripts/__node_iterator_inline/__node_iterator_inline.yy",},}, {"id":{"name":"s_MKFX","path":"sprites/s_MKFX/s_MKFX.yy",},}, + {"id":{"name":"sh_region_fill_inner","path":"shaders/sh_region_fill_inner/sh_region_fill_inner.yy",},}, {"id":{"name":"_f_sdf","path":"fonts/_f_sdf/_f_sdf.yy",},}, {"id":{"name":"dynaSurf_iso","path":"scripts/dynaSurf_iso/dynaSurf_iso.yy",},}, {"id":{"name":"sh_fd_add_velocity_glsl","path":"shaders/sh_fd_add_velocity_glsl/sh_fd_add_velocity_glsl.yy",},}, @@ -710,6 +711,7 @@ {"id":{"name":"GMSSimpleMIDI","path":"extensions/GMSSimpleMIDI/GMSSimpleMIDI.yy",},}, {"id":{"name":"s_node_fluidSim_domain","path":"sprites/s_node_fluidSim_domain/s_node_fluidSim_domain.yy",},}, {"id":{"name":"s_node_displace","path":"sprites/s_node_displace/s_node_displace.yy",},}, + {"id":{"name":"sh_region_fill_map","path":"shaders/sh_region_fill_map/sh_region_fill_map.yy",},}, {"id":{"name":"sh_polar","path":"shaders/sh_polar/sh_polar.yy",},}, {"id":{"name":"s_node_warp_mesh","path":"sprites/s_node_warp_mesh/s_node_warp_mesh.yy",},}, {"id":{"name":"sh_pixel_cloud","path":"shaders/sh_pixel_cloud/sh_pixel_cloud.yy",},}, @@ -1254,6 +1256,7 @@ {"id":{"name":"node_perlin","path":"scripts/node_perlin/node_perlin.yy",},}, {"id":{"name":"node_blur_non_uniform","path":"scripts/node_blur_non_uniform/node_blur_non_uniform.yy",},}, {"id":{"name":"node_feedback_input","path":"scripts/node_feedback_input/node_feedback_input.yy",},}, + {"id":{"name":"node_bend","path":"scripts/node_bend/node_bend.yy",},}, {"id":{"name":"s_node_vfx_trail","path":"sprites/s_node_vfx_trail/s_node_vfx_trail.yy",},}, {"id":{"name":"o_dialog_add_multiple_images","path":"objects/o_dialog_add_multiple_images/o_dialog_add_multiple_images.yy",},}, {"id":{"name":"assets_data","path":"scripts/assets_data/assets_data.yy",},}, @@ -1298,6 +1301,7 @@ {"id":{"name":"node_surface_from_color","path":"scripts/node_surface_from_color/node_surface_from_color.yy",},}, {"id":{"name":"s_node_pb_draw_rectangle","path":"sprites/s_node_pb_draw_rectangle/s_node_pb_draw_rectangle.yy",},}, {"id":{"name":"panel_animation","path":"scripts/panel_animation/panel_animation.yy",},}, + {"id":{"name":"sh_bend_arc","path":"shaders/sh_bend_arc/sh_bend_arc.yy",},}, {"id":{"name":"node_array_rearrange","path":"scripts/node_array_rearrange/node_array_rearrange.yy",},}, {"id":{"name":"sh_pb_to_mask","path":"shaders/sh_pb_to_mask/sh_pb_to_mask.yy",},}, {"id":{"name":"d3d_gizmo_plane","path":"scripts/d3d_gizmo_plane/d3d_gizmo_plane.yy",},}, @@ -1519,6 +1523,7 @@ {"id":{"name":"node_iterate_each_inline","path":"scripts/node_iterate_each_inline/node_iterate_each_inline.yy",},}, {"id":{"name":"json_compare","path":"scripts/json_compare/json_compare.yy",},}, {"id":{"name":"node_rigid_force_apply","path":"scripts/node_rigid_force_apply/node_rigid_force_apply.yy",},}, + {"id":{"name":"checkboxActive","path":"scripts/checkboxActive/checkboxActive.yy",},}, {"id":{"name":"__node_shader","path":"scripts/__node_shader/__node_shader.yy",},}, {"id":{"name":"__node_iterator","path":"scripts/__node_iterator/__node_iterator.yy",},}, {"id":{"name":"s_node_rigid_variable","path":"sprites/s_node_rigid_variable/s_node_rigid_variable.yy",},}, @@ -1924,6 +1929,7 @@ {"id":{"name":"node_scale_algo","path":"scripts/node_scale_algo/node_scale_algo.yy",},}, {"id":{"name":"s_node_image_replace","path":"sprites/s_node_image_replace/s_node_image_replace.yy",},}, {"id":{"name":"node_alpha_hash","path":"scripts/node_alpha_hash/node_alpha_hash.yy",},}, + {"id":{"name":"sh_region_fill_border","path":"shaders/sh_region_fill_border/sh_region_fill_border.yy",},}, {"id":{"name":"node_PCX_condition","path":"scripts/node_PCX_condition/node_PCX_condition.yy",},}, {"id":{"name":"sh_mask_modify","path":"shaders/sh_mask_modify/sh_mask_modify.yy",},}, {"id":{"name":"toggleGroup","path":"scripts/toggleGroup/toggleGroup.yy",},}, diff --git a/datafiles/data/Theme.zip b/datafiles/data/Theme.zip index 6b7b4369f..23a0ac77c 100644 Binary files a/datafiles/data/Theme.zip and b/datafiles/data/Theme.zip differ diff --git a/fonts/_f_sdf/_f_sdf.old.png b/fonts/_f_sdf/_f_sdf.old.png index 15dbd80d0..779d3e88b 100644 Binary files a/fonts/_f_sdf/_f_sdf.old.png and b/fonts/_f_sdf/_f_sdf.old.png differ diff --git a/fonts/_f_sdf/_f_sdf.png b/fonts/_f_sdf/_f_sdf.png index 9f12ae0cb..fba7c8447 100644 Binary files a/fonts/_f_sdf/_f_sdf.png and b/fonts/_f_sdf/_f_sdf.png differ diff --git a/fonts/_f_sdf_medium/_f_sdf_medium.old.png b/fonts/_f_sdf_medium/_f_sdf_medium.old.png index fd2587d20..fd12457a6 100644 Binary files a/fonts/_f_sdf_medium/_f_sdf_medium.old.png and b/fonts/_f_sdf_medium/_f_sdf_medium.old.png differ diff --git a/fonts/_f_sdf_medium/_f_sdf_medium.png b/fonts/_f_sdf_medium/_f_sdf_medium.png index f8fd0a2b8..5be21924c 100644 Binary files a/fonts/_f_sdf_medium/_f_sdf_medium.png and b/fonts/_f_sdf_medium/_f_sdf_medium.png differ diff --git a/objects/o_dialog_palette/Create_0.gml b/objects/o_dialog_palette/Create_0.gml index ad89afea3..011150f5c 100644 --- a/objects/o_dialog_palette/Create_0.gml +++ b/objects/o_dialog_palette/Create_0.gml @@ -88,7 +88,7 @@ event_inherited(); if(mouse_press(mb_left, interactable && sFOCUS)) { palette = array_create(array_length(pal.palette)); for( var j = 0; j < array_length(pal.palette); j++ ) - palette[j] = pal.palette[j]; + palette[j] = cola(pal.palette[j]); onApply(palette); index_selecting = 0; diff --git a/scripts/buttonGradient/buttonGradient.gml b/scripts/buttonGradient/buttonGradient.gml index 61b669bf4..ec968ab07 100644 --- a/scripts/buttonGradient/buttonGradient.gml +++ b/scripts/buttonGradient/buttonGradient.gml @@ -5,12 +5,12 @@ function buttonGradient(_onApply, dialog = noone) : widget() constructor { current_gradient = noone; side_button = noone; - function apply(value) { + function apply(value) { #region if(!interactable) return; onApply(value); - } + } #endregion - static trigger = function() { + static trigger = function() { #region var dialog = dialogCall(o_dialog_gradient, WIN_W / 2, WIN_H / 2); dialog.setDefault(current_gradient.clone()); dialog.onApply = apply; @@ -18,13 +18,11 @@ function buttonGradient(_onApply, dialog = noone) : widget() constructor { if(parentDialog) parentDialog.addChildren(dialog); - } + } #endregion - static drawParam = function(params) { - return draw(params.x, params.y, params.w, params.h, params.data, params.m); - } + static drawParam = function(params) { return draw(params.x, params.y, params.w, params.h, params.data, params.m); } - static draw = function(_x, _y, _w, _h, _gradient, _m) { + static draw = function(_x, _y, _w, _h, _gradient, _m) { #region x = _x; y = _y; w = _w; @@ -91,5 +89,5 @@ function buttonGradient(_onApply, dialog = noone) : widget() constructor { resetFocus(); return h; - } + } #endregion } \ No newline at end of file diff --git a/scripts/buttonPalette/buttonPalette.gml b/scripts/buttonPalette/buttonPalette.gml index 99fb591f6..aa3d8a24f 100644 --- a/scripts/buttonPalette/buttonPalette.gml +++ b/scripts/buttonPalette/buttonPalette.gml @@ -1,14 +1,16 @@ function buttonPalette(_onApply, dialog = noone) : widget() constructor { - onApply = _onApply; + onApply = _onApply; parentDialog = dialog; - current_palette = []; - function apply(value) { + current_palette = []; + side_button = noone; + + function apply(value) { #region if(!interactable) return; onApply(value); - } + } #endregion - static trigger = function() { + static trigger = function() { #region var dialog = dialogCall(o_dialog_palette, WIN_W / 2, WIN_H / 2); dialog.setDefault(current_palette); dialog.onApply = apply; @@ -16,18 +18,22 @@ function buttonPalette(_onApply, dialog = noone) : widget() constructor { if(parentDialog) parentDialog.addChildren(dialog); - } + } #endregion - static drawParam = function(params) { - return draw(params.x, params.y, params.w, params.h, params.data, params.m); - } + static drawParam = function(params) { return draw(params.x, params.y, params.w, params.h, params.data, params.m); } - static draw = function(_x, _y, _w, _h, _color, _m) { + static draw = function(_x, _y, _w, _h, _color, _m) { #region x = _x; y = _y; w = _w; h = _h; + if(side_button && instanceof(side_button) == "buttonClass") { + side_button.setFocusHover(active, hover); + side_button.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide); + _w -= ui(40); + } + var _pw = _w - ui(8); var _ph = _h - ui(8); @@ -83,7 +89,7 @@ function buttonPalette(_onApply, dialog = noone) : widget() constructor { resetFocus(); return h; - } + } #endregion } function drawPalette(_pal, _x, _y, _w, _h, _a = 1) { #region diff --git a/scripts/checkboxActive/checkboxActive.gml b/scripts/checkboxActive/checkboxActive.gml new file mode 100644 index 000000000..37b565f47 --- /dev/null +++ b/scripts/checkboxActive/checkboxActive.gml @@ -0,0 +1,48 @@ +function checkBoxActive(_onClick) : widget() constructor { + onClick = _onClick; + spr = THEME.checkbox_active; + + static trigger = function() { + if(!is_callable(onClick)) + return noone; + onClick(); + } + + static drawParam = function(params) { return draw(params.x, params.y, params.data, params.m, params.w, params.h); } + + static draw = function(_x, _y, _value, _m, _w, _h) { + x = _x; + y = _y; + w = _w; + h = _h; + + var bw = ui(96); + var bh = h; + var bx = x + w / 2 - bw / 2; + var by = y; + + draw_sprite_stretched_ext(spr, _value, bx - 8, by - 8, bw + 16, bh + 16, c_white, 1); + + if(hover && point_in_rectangle(_m[0], _m[1], bx, by, bx + bw, by + bh)) { + BLEND_ADD + draw_sprite_stretched_ext(THEME.slider, 3, bx, by, bw, bh, COLORS._main_icon_dark, 1); + BLEND_NORMAL + + if(mouse_press(mb_left, active)) + trigger(); + } else { + if(mouse_press(mb_left)) + deactivate(); + } + + draw_set_text(f_p1, fa_center, fa_center, _value? COLORS._main_value_positive : COLORS._main_value_negative); + draw_text_add(bx + bw / 2, by + bh / 2, _value? "ACTIVE" : "INACTIVE"); + + if(WIDGET_CURRENT == self) + draw_sprite_stretched_ext(THEME.widget_selecting, 0, bx - ui(3), by - ui(3), bw + ui(6), bh + ui(6), COLORS._main_accent, 1); + + resetFocus(); + + return h; + } +} diff --git a/scripts/checkboxActive/checkboxActive.yy b/scripts/checkboxActive/checkboxActive.yy new file mode 100644 index 000000000..1785d98fe --- /dev/null +++ b/scripts/checkboxActive/checkboxActive.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "checkboxActive", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "widgets", + "path": "folders/widgets.yy", + }, +} \ No newline at end of file diff --git a/scripts/load_function/load_function.gml b/scripts/load_function/load_function.gml index a4a62a548..ee90be98b 100644 --- a/scripts/load_function/load_function.gml +++ b/scripts/load_function/load_function.gml @@ -134,6 +134,7 @@ function __LOAD_PATH(path, readonly = false, override = false) { #region if(struct_has(_load_content, "attributes")) struct_override(PROJECT.attributes, _load_content.attributes); + PROJECT.setPalette(); if(struct_has(_load_content, "notes")) { PROJECT.notes = array_create(array_length(_load_content.notes)); diff --git a/scripts/nodeValue_drawer/nodeValue_drawer.gml b/scripts/nodeValue_drawer/nodeValue_drawer.gml index 44d035497..37d16c6b7 100644 --- a/scripts/nodeValue_drawer/nodeValue_drawer.gml +++ b/scripts/nodeValue_drawer/nodeValue_drawer.gml @@ -313,6 +313,7 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover = false, _foc break; case VALUE_TYPE.boolean : + if(is_instanceof(wid, checkBoxActive)) break; param.halign = breakLine? fa_left : fa_center; param.s = breakLine? ui(24) : editBoxH; diff --git a/scripts/node_bend/node_bend.gml b/scripts/node_bend/node_bend.gml new file mode 100644 index 000000000..a06582c11 --- /dev/null +++ b/scripts/node_bend/node_bend.gml @@ -0,0 +1,29 @@ +function Node_Bend(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { + name = "Bend"; + + inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); + + inputs[| 1] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + active_index = 1; + + inputs[| 2] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Arc" ]); + + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); + + input_display_list = [ 1, + ["Surfaces", false], 0, + ["Bend", false], 2, + ] + + attribute_surface_depth(); + attribute_interpolation(); + + static processData = function(_outSurf, _data, _output_index, _array_index) { #region + var _typ = _data[2]; + + + + return _outSurf; + } #endregion +} \ No newline at end of file diff --git a/scripts/node_bend/node_bend.yy b/scripts/node_bend/node_bend.yy new file mode 100644 index 000000000..79b98b9dc --- /dev/null +++ b/scripts/node_bend/node_bend.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "node_bend", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "transform", + "path": "folders/nodes/data/transform.yy", + }, +} \ No newline at end of file diff --git a/scripts/node_bend/node_outline.yy b/scripts/node_bend/node_outline.yy new file mode 100644 index 000000000..86468bc09 --- /dev/null +++ b/scripts/node_bend/node_outline.yy @@ -0,0 +1,12 @@ +{ + "isDnD": false, + "isCompatibility": false, + "parent": { + "name": "process", + "path": "folders/nodes/data/process.yy", + }, + "resourceVersion": "1.0", + "name": "node_outline", + "tags": [], + "resourceType": "GMScript", +} \ No newline at end of file diff --git a/scripts/node_combine_rgb/node_combine_rgb.gml b/scripts/node_combine_rgb/node_combine_rgb.gml index 8573f148a..c45f929d1 100644 --- a/scripts/node_combine_rgb/node_combine_rgb.gml +++ b/scripts/node_combine_rgb/node_combine_rgb.gml @@ -8,7 +8,7 @@ function Node_Combine_RGB(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou inputs[| 3] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); inputs[| 4] = nodeValue("Sampling type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) - .setDisplay(VALUE_DISPLAY.enum_scroll, ["Brightness", "Channel value"]); + .setDisplay(VALUE_DISPLAY.enum_scroll, ["Channel value", "Greyscale"]); inputs[| 5] = nodeValue("Base value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0, "Set value to the unconnected color channels.") .setDisplay(VALUE_DISPLAY.slider) @@ -57,7 +57,7 @@ function Node_Combine_RGB(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou shader_set_i("useB", is_surface(_b)); shader_set_i("useA", is_surface(_a)); - shader_set_i("mode", _data[4]); + shader_set_i("mode", !_data[4]); shader_set_f_map("base", _data[5], _data[6], inputs[| 5]); draw_sprite_stretched(s_fx_pixel, 0, 0, 0, surface_get_width_safe(_outSurf), surface_get_height_safe(_outSurf)); diff --git a/scripts/node_gradient_points/node_gradient_points.gml b/scripts/node_gradient_points/node_gradient_points.gml index 5314f7236..79a323070 100644 --- a/scripts/node_gradient_points/node_gradient_points.gml +++ b/scripts/node_gradient_points/node_gradient_points.gml @@ -40,26 +40,28 @@ function Node_Gradient_Points(_x, _y, _group = noone) : Node_Processor(_x, _y, _ inputs[| 14] = nodeValue("Falloff 4", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 6 ) .setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 32, 1 ] }); + + inputs[| 15] = nodeValue("Normalize weight", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ) outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); input_display_list = [ ["Output", true], 0, ["Positions", false], 1, 3, 5, 7, - ["Falloff", true], 11, 12, 13, 14, + ["Falloff", true], 11, 12, 13, 14, 15, ["Colors", false], 9, 10, 2, 4, 6, 8, ]; attribute_surface_depth(); - static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { + static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { #region if(inputs[| 1].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; if(inputs[| 3].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; if(inputs[| 5].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; if(inputs[| 7].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; - } + } #endregion - static step = function() { + static step = function() { #region var _usePal = getInputData(9); inputs[| 10].setVisible(_usePal, _usePal); @@ -68,9 +70,9 @@ function Node_Gradient_Points(_x, _y, _group = noone) : Node_Processor(_x, _y, _ inputs[| 4].setVisible(!_usePal, !_usePal); inputs[| 6].setVisible(!_usePal, !_usePal); inputs[| 8].setVisible(!_usePal, !_usePal); - } + } #endregion - static processData = function(_outSurf, _data, _output_index, _array_index) { + static processData = function(_outSurf, _data, _output_index, _array_index) { #region var _dim = _data[0]; _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); @@ -78,20 +80,18 @@ function Node_Gradient_Points(_x, _y, _group = noone) : Node_Processor(_x, _y, _ var _usePal = _data[9]; var _pal = _data[10]; - var _1cen = _data[1]; - var _1col = _data[2]; - var _2cen = _data[3]; - var _2col = _data[4]; - var _3cen = _data[5]; - var _3col = _data[6]; - var _4cen = _data[7]; - var _4col = _data[8]; + var _1cen = _data[1], _1col = _data[2]; + var _2cen = _data[3], _2col = _data[4]; + var _3cen = _data[5], _3col = _data[6]; + var _4cen = _data[7], _4col = _data[8]; var _1str = _data[11]; var _2str = _data[12]; var _3str = _data[13]; var _4str = _data[14]; + var _blnd = _data[15]; + var colArr = []; if(_usePal) { @@ -100,18 +100,18 @@ function Node_Gradient_Points(_x, _y, _group = noone) : Node_Processor(_x, _y, _ } else colArr = array_merge(colorArrayFromReal(_1col), colorArrayFromReal(_2col), colorArrayFromReal(_3col), colorArrayFromReal(_4col)) - surface_set_target(_outSurf); - DRAW_CLEAR - shader_set(sh_gradient_points); - shader_set_f("dimension", _dim[0], _dim[1]); - shader_set_f("center", array_merge(_1cen, _2cen, _3cen, _4cen)); - shader_set_f("color", colArr); - shader_set_f("strength", _1str, _2str, _3str, _4str); + surface_set_shader(_outSurf, sh_gradient_points); + + shader_set_f("dimension", _dim); + shader_set_f("center", array_merge(_1cen, _2cen, _3cen, _4cen)); + shader_set_f("color", colArr); + shader_set_f("strength", _1str, _2str, _3str, _4str); + shader_set_i("blend", _blnd); draw_sprite_stretched_ext(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1], c_white, 1); - shader_reset(); - surface_reset_target(); + + surface_reset_shader(); return _outSurf; - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_level/node_level.gml b/scripts/node_level/node_level.gml index 91cacc6b4..4278a4911 100644 --- a/scripts/node_level/node_level.gml +++ b/scripts/node_level/node_level.gml @@ -3,19 +3,19 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); - inputs[| 1] = nodeValue("White", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + inputs[| 1] = nodeValue("White in", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) .setDisplay(VALUE_DISPLAY.slider_range); - inputs[| 2] = nodeValue("Red", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + inputs[| 2] = nodeValue("Red in", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) .setDisplay(VALUE_DISPLAY.slider_range); - inputs[| 3] = nodeValue("Green", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + inputs[| 3] = nodeValue("Green in", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) .setDisplay(VALUE_DISPLAY.slider_range); - inputs[| 4] = nodeValue("Blue", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + inputs[| 4] = nodeValue("Blue in", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) .setDisplay(VALUE_DISPLAY.slider_range); - inputs[| 5] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + inputs[| 5] = nodeValue("Alpha in", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) .setDisplay(VALUE_DISPLAY.slider_range); inputs[| 6] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); @@ -31,6 +31,21 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con __init_mask_modifier(6); // inputs 10, 11 + inputs[| 12] = nodeValue("White out", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + .setDisplay(VALUE_DISPLAY.slider_range); + + inputs[| 13] = nodeValue("Red out", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + .setDisplay(VALUE_DISPLAY.slider_range); + + inputs[| 14] = nodeValue("Green out", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + .setDisplay(VALUE_DISPLAY.slider_range); + + inputs[| 15] = nodeValue("Blue out", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + .setDisplay(VALUE_DISPLAY.slider_range); + + inputs[| 16] = nodeValue("Alpha out", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1]) + .setDisplay(VALUE_DISPLAY.slider_range); + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); attribute_surface_depth(); @@ -71,8 +86,11 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con input_display_list = [ 8, 9, level_renderer, ["Surfaces", true], 0, 6, 7, 10, 11, - ["Level", false], 1, - ["Channel", true], 2, 3, 4, 5 + ["Brightness", false], 1, 12, + ["Red", false], 2, 13, + ["Green", false], 3, 14, + ["Blue", false], 4, 15, + ["Alpha", false], 5, 16, ]; histogramInit(); @@ -94,18 +112,30 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con } #endregion static processData = function(_outSurf, _data, _output_index, _array_index) { #region - var _w = _data[1]; - var _r = _data[2]; - var _g = _data[3]; - var _b = _data[4]; - var _a = _data[5]; + var _wi = _data[1]; + var _ri = _data[2]; + var _gi = _data[3]; + var _bi = _data[4]; + var _ai = _data[5]; + + var _wo = _data[12]; + var _ro = _data[13]; + var _go = _data[14]; + var _bo = _data[15]; + var _ao = _data[16]; surface_set_shader(_outSurf, sh_level); - shader_set_f("lw", _w); - shader_set_f("lr", _r); - shader_set_f("lg", _g); - shader_set_f("lb", _b); - shader_set_f("la", _a); + shader_set_f("lwi", _wi); + shader_set_f("lri", _ri); + shader_set_f("lgi", _gi); + shader_set_f("lbi", _bi); + shader_set_f("lai", _ai); + + shader_set_f("lwo", _wo); + shader_set_f("lro", _ro); + shader_set_f("lgo", _go); + shader_set_f("lbo", _bo); + shader_set_f("lao", _ao); draw_surface_safe(_data[0]); surface_reset_shader(); diff --git a/scripts/node_mk_rain/node_mk_rain.gml b/scripts/node_mk_rain/node_mk_rain.gml index 7b35e8bcf..9b60137a8 100644 --- a/scripts/node_mk_rain/node_mk_rain.gml +++ b/scripts/node_mk_rain/node_mk_rain.gml @@ -10,10 +10,10 @@ function Node_MK_Rain(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c inputs[| 2] = nodeValue("Density", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 5); inputs[| 3] = nodeValue("Raindrop width", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 2 ]) - .setDisplay(VALUE_DISPLAY.vector_range); + .setDisplay(VALUE_DISPLAY.range); inputs[| 4] = nodeValue("Raindrop length", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 5, 10 ]) - .setDisplay(VALUE_DISPLAY.vector_range); + .setDisplay(VALUE_DISPLAY.range); inputs[| 5] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white)); @@ -21,7 +21,7 @@ function Node_MK_Rain(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c .setDisplay(VALUE_DISPLAY.slider_range); inputs[| 7] = nodeValue("Velocity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 2 ]) - .setDisplay(VALUE_DISPLAY.vector_range); + .setDisplay(VALUE_DISPLAY.range); inputs[| 8] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, irandom_range(100_000, 999_999)); @@ -31,7 +31,7 @@ function Node_MK_Rain(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c new scrollItem("Texture", s_node_mk_rain_type, 2) ]); inputs[| 10] = nodeValue("Snow size", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 3, 4 ]) - .setDisplay(VALUE_DISPLAY.vector_range); + .setDisplay(VALUE_DISPLAY.range); inputs[| 11] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); diff --git a/scripts/node_processor/node_processor.gml b/scripts/node_processor/node_processor.gml index eaad68468..d3292e4f4 100644 --- a/scripts/node_processor/node_processor.gml +++ b/scripts/node_processor/node_processor.gml @@ -134,10 +134,14 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct var data = processData(_out, _data, outIndex, 0); // Process data - if(manage_atlas && _atlas && is_surface(data)) { // Convert back to atlas - var _atl = _pAtl.clone(); - _atl.setSurface(data); - return _atl; + if(_output.type == VALUE_TYPE.surface) { + if(manage_atlas && _atlas && is_surface(data)) { // Convert back to atlas + var _atl = _pAtl.clone(); + _atl.setSurface(data); + return _atl; + } + + //data = surface_project_posterize(data); } return data; @@ -195,10 +199,14 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct } else { _out[l] = processData(_out[l], _data, outIndex, l); // Process data - if(manage_atlas && _atlas && is_surface(_out[l])) { // Convert back to atlas - var _atl = _pAtl.clone(); - _atl.setSurface(_out[l]); - _out[l] = _atl; + if(_output.type == VALUE_TYPE.surface) { + if(manage_atlas && _atlas && is_surface(_out[l])) { // Convert back to atlas + var _atl = _pAtl.clone(); + _atl.setSurface(_out[l]); + _out[l] = _atl; + } + + //data = surface_project_posterize(data); } } } diff --git a/scripts/node_region_fill/node_region_fill.gml b/scripts/node_region_fill/node_region_fill.gml index f4ad382e0..48f4bc157 100644 --- a/scripts/node_region_fill/node_region_fill.gml +++ b/scripts/node_region_fill/node_region_fill.gml @@ -5,23 +5,40 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou inputs[| 1] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); - inputs[| 2] = nodeValue("Colors", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE ) + inputs[| 2] = nodeValue("Fill Colors", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE ) .setDisplay(VALUE_DISPLAY.palette); - inputs[| 3] = nodeValue("Fill Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + inputs[| 3] = nodeValue("Fill", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); inputs[| 4] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, irandom_range(10000, 99999)); + inputs[| 5] = nodeValue("Target Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, cola(c_black, 0)); + + inputs[| 6] = nodeValue("Inner only", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false, "Only fill regions with surrounding pixels."); + + inputs[| 7] = nodeValue("Draw original", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + + inputs[| 8] = nodeValue("Fill type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Random", "Color map" ]); + + inputs[| 9] = nodeValue("Color map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); - input_display_list = [ + input_display_list = [ 4, ["Surfaces", false], 0, 1, - ["Fill", false, 3], 4, 2, + ["Fill", false, 3], 5, 8, 2, 9, 6, + ["Render", false], 7, ]; - temp_surface = [ surface_create(1, 1), surface_create(1, 1) ]; + temp_surface = array_create(3); - static step = function() {} + static step = function() { + var _filt = getInputData(8); + + inputs[| 2].setVisible(_filt == 0); + inputs[| 9].setVisible(_filt == 1, _filt == 1); + } static processData = function(_outSurf, _data, _output_index, _array_index) { var _surf = _data[0]; @@ -30,47 +47,97 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou var _colr = _data[2]; var _fill = _data[3]; var _seed = _data[4]; + var _targ = _data[5]; + var _innr = _data[6]; + var _rnbg = _data[7]; + var _filt = _data[8]; + var _cmap = _data[9]; var _sw = surface_get_width_safe(_surf); var _sh = surface_get_height_safe(_surf) - temp_surface[0] = surface_verify(temp_surface[0], _sw, _sh); - temp_surface[1] = surface_verify(temp_surface[1], _sw, _sh); - - surface_clear(temp_surface[0]); + for( var i = 0, n = array_length(temp_surface); i < n; i++ ) { + temp_surface[i] = surface_verify(temp_surface[i], _sw, _sh); + surface_clear(temp_surface[i]); + } surface_set_shader(temp_surface[1], sh_region_fill_init); - draw_surface_safe(_surf, 0, 0); + shader_set_color("targetColor", _targ); + + draw_surface_safe(_surf); surface_reset_shader(); var base = 0; + var amo = _sw; + + if(_innr) { + repeat( amo ) { + surface_set_shader(temp_surface[base], sh_region_fill_inner); + shader_set_f("dimension", _sw, _sh); + + draw_surface_safe(temp_surface[!base]); + surface_reset_shader(); + + base = !base; + } + } + var amo = _sw + _sh; - for( var i = 0; i < amo; i++ ) { + repeat( amo ) { surface_set_shader(temp_surface[base], sh_region_fill_coordinate); shader_set_f("dimension", _sw, _sh); - draw_surface_safe(temp_surface[!base], 0, 0); + draw_surface_safe(temp_surface[!base]); surface_reset_shader(); base = !base; } + surface_set_shader(temp_surface[base], sh_region_fill_border); + shader_set_f("dimension", _sw, _sh); + shader_set_surface("original", _surf); + + draw_surface_safe(temp_surface[!base]); + surface_reset_shader(); + if(_fill) { var _pal = []; for( var i = 0, n = array_length(_colr); i < n; i++ ) array_append(_pal, colToVec4(_colr[i])); - surface_set_shader(_outSurf, sh_region_fill_color); - shader_set_f("colors", _pal); - shader_set_f("seed", _seed); - shader_set_f("colorAmount", array_length(_colr)); + surface_set_shader(_outSurf); + switch(_filt) { + case 0 : + shader_set(sh_region_fill_color); - draw_surface_safe(temp_surface[base], 0, 0); + shader_set_f("colors", _pal); + shader_set_f("seed", _seed); + shader_set_f("colorAmount", array_length(_colr)); + + draw_surface_safe(temp_surface[base]); + break; + + case 1 : + shader_set(sh_region_fill_map); + + shader_set_surface("colorMap", _cmap); + + draw_surface_safe(temp_surface[base]); + break; + } + + if(_rnbg) { + shader_reset(); + shader_set(sh_sample); + draw_surface_safe(_surf); + } surface_reset_shader(); } else { surface_set_shader(_outSurf); - draw_surface_safe(temp_surface[base], 0, 0); + draw_surface_safe(temp_surface[base]); + if(_rnbg) + draw_surface_safe(_surf); surface_reset_shader(); } diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 7038420a5..88309af3e 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -1137,9 +1137,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru } break; case VALUE_TYPE.boolean : #region - editWidget = new checkBox(function() { - return setValueDirect(!animator.getValue()); - } ); + if(name == "Active") editWidget = new checkBoxActive(function() { return setValueDirect(!animator.getValue()); } ); + else editWidget = new checkBox(function() { return setValueDirect(!animator.getValue()); } ); key_inter = CURVE_TYPE.cut; extract_node = "Node_Boolean"; diff --git a/scripts/node_wrap/node_wrap.gml b/scripts/node_wrap/node_wrap.gml index c7a92a5ab..febb47552 100644 --- a/scripts/node_wrap/node_wrap.gml +++ b/scripts/node_wrap/node_wrap.gml @@ -44,6 +44,8 @@ function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons attributes[? "initalset"] = LOADING || APPENDING; + warp_surface = array_create(2); + static onValueFromUpdate = function(index) { #region if(index == 0 && attributes[? "initalset"] == false) { var _surf = getInputData(0); @@ -68,7 +70,7 @@ function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons dimension_index = _useDim? 7 : 0; } #endregion - static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { #region + static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny, params) { #region PROCESSOR_OVERLAY_CHECK var _surf = outputs[| 0].getValue(); @@ -92,6 +94,30 @@ function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons bl[1] = _y + bl[1] * _s; br[1] = _y + br[1] * _s; + #region preview + var sw = surface_get_width(_surf) * _s; + var sh = surface_get_height(_surf) * _s; + + warp_surface[0] = surface_verify(warp_surface[0], params.w, params.h); + warp_surface[1] = surface_verify(warp_surface[1], sw, sh); + + surface_set_target(warp_surface[1]); + draw_clear(c_black); + draw_set_color(c_dkgrey); + + for(var i = 0; i <= 1; i += 0.125) { + draw_line_width(0, i * sh, sw, i * sh, 2); + draw_line_width(i * sw, 0, i * sw, sh, 2); + } + surface_reset_target(); + + warpSurface( warp_surface[0], warp_surface[1], params.w, params.h, tl, tr, bl, br, true ); + + BLEND_ADD + draw_surface(warp_surface[0], 0, 0); + BLEND_NORMAL + #endregion + draw_set_color(COLORS._main_accent); draw_line(tl[0], tl[1], tr[0], tr[1]); draw_line(tl[0], tl[1], bl[0], bl[1]); @@ -117,100 +143,134 @@ function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons } } - draw_set_color(COLORS.node_overlay_gizmo_inactive); - if(drag_side == 0) { - draw_line_width(tl[0], tl[1], tr[0], tr[1], 3); - - var _tlx = value_snap(drag_s[0][0] + dx, _snx); - var _tly = value_snap(drag_s[0][1] + dy, _sny); - - var _trx = value_snap(drag_s[1][0] + dx, _snx); - var _try = value_snap(drag_s[1][1] + dy, _sny); - - var _up1 = inputs[| 1].setValue([ _tlx, _tly ]); - var _up2 = inputs[| 2].setValue([ _trx, _try ]); - - if(_up1 || _up2) UNDO_HOLDING = true; - } else if(drag_side == 1) { - draw_line_width(tl[0], tl[1], bl[0], bl[1], 3); - - var _tlx = value_snap(drag_s[0][0] + dx, _snx); - var _tly = value_snap(drag_s[0][1] + dy, _sny); - - var _blx = value_snap(drag_s[1][0] + dx, _snx); - var _bly = value_snap(drag_s[1][1] + dy, _sny); - - var _up1 = inputs[| 1].setValue([ _tlx, _tly ]); - var _up3 = inputs[| 3].setValue([ _blx, _bly ]); - - if(_up1 || _up3) UNDO_HOLDING = true; - } else if(drag_side == 2) { - draw_line_width(br[0], br[1], tr[0], tr[1], 3); - - var _brx = value_snap(drag_s[0][0] + dx, _snx); - var _bry = value_snap(drag_s[0][1] + dy, _sny); - - var _trx = value_snap(drag_s[1][0] + dx, _snx); - var _try = value_snap(drag_s[1][1] + dy, _sny); - - var _up4 = inputs[| 4].setValue([ _brx, _bry ]); - var _up2 = inputs[| 2].setValue([ _trx, _try ]); - - if(_up4 || _up2) UNDO_HOLDING = true; - } else if(drag_side == 3) { - draw_line_width(br[0], br[1], bl[0], bl[1], 3); - - var _brx = value_snap(drag_s[0][0] + dx, _snx); - var _bry = value_snap(drag_s[0][1] + dy, _sny); - - var _blx = value_snap(drag_s[1][0] + dx, _snx); - var _bly = value_snap(drag_s[1][1] + dy, _sny); - - var _up4 = inputs[| 4].setValue([ _brx, _bry ]); - var _up3 = inputs[| 3].setValue([ _blx, _bly ]); - - if(_up4 || _up3) UNDO_HOLDING = true; - } else if(_hactive) { - draw_set_color(COLORS._main_accent); - if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], tr[0], tr[1]) < 12) { + #region edit + draw_set_color(COLORS.node_overlay_gizmo_inactive); + if(drag_side == 0) { draw_line_width(tl[0], tl[1], tr[0], tr[1], 3); - if(mouse_press(mb_left)) { - drag_side = 0; - drag_mx = _mx; - drag_my = _my; - drag_s = [ current_data[1], current_data[2] ]; - } - } else if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], bl[0], bl[1]) < 12) { + + var _tlx = value_snap(drag_s[0][0] + dx, _snx); + var _tly = value_snap(drag_s[0][1] + dy, _sny); + + var _trx = value_snap(drag_s[1][0] + dx, _snx); + var _try = value_snap(drag_s[1][1] + dy, _sny); + + var _up1 = inputs[| 1].setValue([ _tlx, _tly ]); + var _up2 = inputs[| 2].setValue([ _trx, _try ]); + + if(_up1 || _up2) UNDO_HOLDING = true; + } else if(drag_side == 1) { draw_line_width(tl[0], tl[1], bl[0], bl[1], 3); - if(mouse_press(mb_left)) { - drag_side = 1; - drag_mx = _mx; - drag_my = _my; - drag_s = [ current_data[1], current_data[3] ]; - } - } else if(distance_to_line_infinite(_mx, _my, br[0], br[1], tr[0], tr[1]) < 12) { + + var _tlx = value_snap(drag_s[0][0] + dx, _snx); + var _tly = value_snap(drag_s[0][1] + dy, _sny); + + var _blx = value_snap(drag_s[1][0] + dx, _snx); + var _bly = value_snap(drag_s[1][1] + dy, _sny); + + var _up1 = inputs[| 1].setValue([ _tlx, _tly ]); + var _up3 = inputs[| 3].setValue([ _blx, _bly ]); + + if(_up1 || _up3) UNDO_HOLDING = true; + } else if(drag_side == 2) { draw_line_width(br[0], br[1], tr[0], tr[1], 3); - if(mouse_press(mb_left)) { - drag_side = 2; - drag_mx = _mx; - drag_my = _my; - drag_s = [ current_data[4], current_data[2] ]; - } - } else if(distance_to_line_infinite(_mx, _my, br[0], br[1], bl[0], bl[1]) < 12) { + + var _brx = value_snap(drag_s[0][0] + dx, _snx); + var _bry = value_snap(drag_s[0][1] + dy, _sny); + + var _trx = value_snap(drag_s[1][0] + dx, _snx); + var _try = value_snap(drag_s[1][1] + dy, _sny); + + var _up4 = inputs[| 4].setValue([ _brx, _bry ]); + var _up2 = inputs[| 2].setValue([ _trx, _try ]); + + if(_up4 || _up2) UNDO_HOLDING = true; + } else if(drag_side == 3) { draw_line_width(br[0], br[1], bl[0], bl[1], 3); - if(mouse_press(mb_left)) { - drag_side = 3; - drag_mx = _mx; - drag_my = _my; - drag_s = [ current_data[4], current_data[3] ]; + + var _brx = value_snap(drag_s[0][0] + dx, _snx); + var _bry = value_snap(drag_s[0][1] + dy, _sny); + + var _blx = value_snap(drag_s[1][0] + dx, _snx); + var _bly = value_snap(drag_s[1][1] + dy, _sny); + + var _up4 = inputs[| 4].setValue([ _brx, _bry ]); + var _up3 = inputs[| 3].setValue([ _blx, _bly ]); + + if(_up4 || _up3) UNDO_HOLDING = true; + } else if(_hactive) { + draw_set_color(COLORS._main_accent); + if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], tr[0], tr[1]) < 12) { + draw_line_width(tl[0], tl[1], tr[0], tr[1], 3); + if(mouse_press(mb_left)) { + drag_side = 0; + drag_mx = _mx; + drag_my = _my; + drag_s = [ current_data[1], current_data[2] ]; + } + } else if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], bl[0], bl[1]) < 12) { + draw_line_width(tl[0], tl[1], bl[0], bl[1], 3); + if(mouse_press(mb_left)) { + drag_side = 1; + drag_mx = _mx; + drag_my = _my; + drag_s = [ current_data[1], current_data[3] ]; + } + } else if(distance_to_line_infinite(_mx, _my, br[0], br[1], tr[0], tr[1]) < 12) { + draw_line_width(br[0], br[1], tr[0], tr[1], 3); + if(mouse_press(mb_left)) { + drag_side = 2; + drag_mx = _mx; + drag_my = _my; + drag_s = [ current_data[4], current_data[2] ]; + } + } else if(distance_to_line_infinite(_mx, _my, br[0], br[1], bl[0], bl[1]) < 12) { + draw_line_width(br[0], br[1], bl[0], bl[1], 3); + if(mouse_press(mb_left)) { + drag_side = 3; + drag_mx = _mx; + drag_my = _my; + drag_s = [ current_data[4], current_data[3] ]; + } } } - } - if(inputs[| 1].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; - if(inputs[| 2].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; - if(inputs[| 3].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; - if(inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; + if(inputs[| 1].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; + if(inputs[| 2].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; + if(inputs[| 3].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; + if(inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny)) active = false; + #endregion + } #endregion + + static warpSurface = function(surf, warp, sw, sh, tl, tr, bl, br, filt = false) { #region + var teq = round(tl[1]) == round(tr[1]); + var beq = round(bl[1]) == round(br[1]); + var leq = round(tl[0]) == round(bl[0]); + var req = round(tr[0]) == round(br[0]); + + if(teq && beq && leq && req) { + surface_set_shader(surf) + shader_set_interpolation(warp); + + if(filt) gpu_set_tex_filter(true); + draw_surface_stretched_safe(warp, tl[0], tl[1], tr[0] - tl[0], bl[1] - tl[1]); + if(filt) gpu_set_tex_filter(false); + surface_reset_shader(); + + } else { + surface_set_shader(surf, sh_warp_4points); + shader_set_interpolation(warp); + + shader_set_f("dimension", surface_get_dimension(warp)); + shader_set_f("p0", br[0] / sw, br[1] / sh); + shader_set_f("p1", tr[0] / sw, tr[1] / sh); + shader_set_f("p2", tl[0] / sw, tl[1] / sh); + shader_set_f("p3", bl[0] / sw, bl[1] / sh); + + if(filt) gpu_set_tex_filter(true); + draw_surface_stretched(warp, 0, 0, sw, sh); + if(filt) gpu_set_tex_filter(false); + surface_reset_shader(); + } } #endregion static processData = function(_outSurf, _data, _output_index, _array_index) { #region @@ -225,29 +285,7 @@ function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var sw = _useDim? _dim[0] : surface_get_width_safe(_data[0]); var sh = _useDim? _dim[1] : surface_get_height_safe(_data[0]); - var teq = round(tl[1]) == round(tr[1]); - var beq = round(bl[1]) == round(br[1]); - var leq = round(tl[0]) == round(bl[0]); - var req = round(tr[0]) == round(br[0]); - - if(teq && beq && leq && req) { - surface_set_shader(_outSurf) - shader_set_interpolation(_data[0]); - draw_surface_stretched_safe(_data[0], tl[0], tl[1], tr[0] - tl[0], bl[1] - tl[1]); - surface_reset_shader(); - } else { - surface_set_shader(_outSurf, sh_warp_4points); - shader_set_interpolation(_data[0]); - - shader_set_f("dimension", surface_get_dimension(_data[0])); - shader_set_f("p0", br[0] / sw, br[1] / sh); - shader_set_f("p1", tr[0] / sw, tr[1] / sh); - shader_set_f("p2", tl[0] / sw, tl[1] / sh); - shader_set_f("p3", bl[0] / sw, bl[1] / sh); - - draw_surface_stretched(_data[0], 0, 0, sw, sh); - surface_reset_shader(); - } + warpSurface(_outSurf, _data[0], sw, sh, tl, tr, bl, br); return _outSurf; } #endregion diff --git a/scripts/panel_animation/panel_animation.gml b/scripts/panel_animation/panel_animation.gml index fba018012..7538c95e1 100644 --- a/scripts/panel_animation/panel_animation.gml +++ b/scripts/panel_animation/panel_animation.gml @@ -709,7 +709,7 @@ function Panel_Animation() : PanelContent() constructor { #endregion } #endregion - function drawDopesheetGraphLine(animator, key_y, msx, msy, _gy_val_min = 999999, _gy_val_max = -999999) { #region + function __drawDopesheetGraphLine(animator, key_y, msx, msy, _gy_val_min = 999999, _gy_val_max = -999999) { #region var bar_total_w = TOTAL_FRAMES * timeline_scale; var bar_show_w = timeline_shift + bar_total_w; var hovering = noone; @@ -919,7 +919,7 @@ function Panel_Animation() : PanelContent() constructor { } #endregion } #endregion - function drawDopesheetGraph(prop, key_y, msx, msy) { #region + function _drawDopesheetGraph(prop, key_y, msx, msy) { #region var bar_total_w = TOTAL_FRAMES * timeline_scale; var bar_show_w = timeline_shift + bar_total_w; var _gy_top = key_y + ui(16); @@ -981,17 +981,21 @@ function Panel_Animation() : PanelContent() constructor { } for( var i = 0, n = array_length(prop.animators); i < n; i++ ) - drawDopesheetGraphLine(prop.animators[i], key_y, msx, msy, _min, _max); + __drawDopesheetGraphLine(prop.animators[i], key_y, msx, msy, _min, _max); } else - drawDopesheetGraphLine(prop.animator, key_y, msx, msy); + __drawDopesheetGraphLine(prop.animator, key_y, msx, msy); #endregion } #endregion - function drawDopesheetAnimatorKeysBG(animator, msx, msy) { #region + function _drawDopesheetAnimatorKeysBG(animator, msx, msy) { #region var prop_dope_y = animator.y; var key_hover = noone; var key_list = animator.values; + //if(animator.prop.name == "Active") { #region active prop + + //} #endregion + if((animator.prop.on_end == KEYFRAME_END.loop || animator.prop.on_end == KEYFRAME_END.ping) && ds_list_size(key_list) > 1) { var keyframe_s = animator.prop.loop_range == -1? key_list[| 0].time : key_list[| ds_list_size(key_list) - 1 - animator.prop.loop_range].time; var keyframe_e = key_list[| ds_list_size(key_list) - 1].time; @@ -1004,7 +1008,7 @@ function Panel_Animation() : PanelContent() constructor { draw_line_width(ks_x, prop_dope_y - 1, ke_x, prop_dope_y - 1, 4); draw_set_alpha(1); } - + for( var k = 0; k < ds_list_size(key_list); k++ ) { //draw easing var key = key_list[| k]; var t = key.dopesheet_x; @@ -1045,7 +1049,7 @@ function Panel_Animation() : PanelContent() constructor { return key_hover; } #endregion - function drawDopesheetAnimatorKeys(_cont, animator, msx, msy) { #region + function _drawDopesheetAnimatorKeys(_cont, animator, msx, msy) { #region var _node = _cont.node; var prop_y = animator.y; var node_y = _cont.y + dope_sheet_node_padding; @@ -1122,7 +1126,7 @@ function Panel_Animation() : PanelContent() constructor { return key_hover; } #endregion - function drawDopesheetLabelAnimator(_item, _node, animator, msx, msy) { #region + function __drawDopesheetLabelAnimator(_item, _node, animator, msx, msy) { #region var prop = animator.prop; var aa = _node.group == PANEL_GRAPH.getCurrentContext()? 1 : 0.9; var tx = tool_width; @@ -1237,7 +1241,7 @@ function Panel_Animation() : PanelContent() constructor { draw_set_alpha(1); } #endregion - function drawDopesheetLabelItem(_item, _x, _y, msx = -1, msy = -1, alpha = 1) { #region + function __drawDopesheetLabelItem(_item, _x, _y, msx = -1, msy = -1, alpha = 1) { #region var _itx = _x; var _ity = _y; var _itw = tool_width; @@ -1261,7 +1265,7 @@ function Panel_Animation() : PanelContent() constructor { } } #endregion - function drawDopesheetLabel() { #region + function _drawDopesheetLabel() { #region surface_set_target(dope_sheet_name_surface); draw_clear_alpha(COLORS.panel_bg_clear, 0); var msx = mx - ui(8); @@ -1330,11 +1334,11 @@ function Panel_Animation() : PanelContent() constructor { continue; } - drawDopesheetLabelItem(_cont, 0, _cont.y + dope_sheet_node_padding, msx, msy); + __drawDopesheetLabelItem(_cont, 0, _cont.y + dope_sheet_node_padding, msx, msy); if(_cont.type == "node" && _cont.item.show) for( var j = 0; j < array_length(_cont.animators); j++ ) - drawDopesheetLabelAnimator(_cont, _cont.node, _cont.animators[j], msx, msy); + __drawDopesheetLabelAnimator(_cont, _cont.node, _cont.animators[j], msx, msy); } //end node loop if(_itx != -1) { @@ -1658,14 +1662,14 @@ function Panel_Animation() : PanelContent() constructor { var _prop = prop.prop; for( var k = 0; k < array_length(prop.animators); k++ ) { - var key = drawDopesheetAnimatorKeysBG(prop.animators[k], msx, msy); + var key = _drawDopesheetAnimatorKeysBG(prop.animators[k], msx, msy); _dy = prop.animators[k].y; if(key != noone) key_hover = key; } if(isGraphable(_prop) && _prop.show_graph) - drawDopesheetGraph(_prop, _dy, msx, msy); + _drawDopesheetGraph(_prop, _dy, msx, msy); } } #endregion @@ -1688,7 +1692,7 @@ function Panel_Animation() : PanelContent() constructor { for( var j = 0, m = array_length(_cont.animators); j < m; j++ ) { var _anim = _cont.animators[j]; - var key = drawDopesheetAnimatorKeys(_cont, _anim, msx, msy); + var key = _drawDopesheetAnimatorKeys(_cont, _anim, msx, msy); if(key != noone) key_hover = key; } } @@ -1921,7 +1925,7 @@ function Panel_Animation() : PanelContent() constructor { gpu_set_blendmode(bm_normal); surface_reset_target(); - drawDopesheetLabel(); + _drawDopesheetLabel(); if(mouse_press(mb_right, pFOCUS)) { #region context menu if(point_in_rectangle(mx, my, bar_x, ui(8), bar_x + dope_sheet_w, ui(8) + dope_sheet_h)) { @@ -1945,7 +1949,7 @@ function Panel_Animation() : PanelContent() constructor { draw_sprite_stretched(THEME.ui_panel_bg_cover, 1, bar_x, ui(8), bar_w, dope_sheet_h); - if(item_dragging != noone) drawDopesheetLabelItem(item_dragging, mx - item_dragging_dx, my - item_dragging_dy,,, 0.5); + if(item_dragging != noone) __drawDopesheetLabelItem(item_dragging, mx - item_dragging_dx, my - item_dragging_dy,,, 0.5); } #endregion function drawAnimationControl() { #region diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index dd69a8fab..c6d14999f 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -46,10 +46,11 @@ function Panel_Preview() : PanelContent() constructor { #endregion #region ---- preview ---- - preview_node = [ noone, noone ]; - preview_surface = [ 0, 0 ]; - tile_surface = surface_create(1, 1); - + preview_node = [ noone, noone ]; + preview_surfaces = [ 0, 0 ]; + preview_surface = [ 0, 0 ]; + tile_surface = surface_create(1, 1); + preview_x = 0; preview_x_to = 0; preview_x_max = 0; @@ -301,11 +302,11 @@ function Panel_Preview() : PanelContent() constructor { function resetNodePreview() { preview_node = [ noone, noone ]; } function getNodePreview() { return preview_node[splitView? splitSelection : 0]; } - function getNodePreviewSurface() { return preview_surface[splitView? splitSelection : 0]; } + function getNodePreviewSurface() { return preview_surfaces[splitView? splitSelection : 0]; } function getNodePreviewSequence() { return preview_sequence[splitView? splitSelection : 0]; } function getPreviewData() { #region - preview_surface = [ noone, noone ]; + preview_surfaces = [ noone, noone ]; preview_sequence = [ noone, noone ]; for( var i = 0; i < 2; i++ ) { @@ -323,13 +324,13 @@ function Panel_Preview() : PanelContent() constructor { preview_sequence[i] = value; canvas_a = array_length(value); } else { - preview_surface[i] = value; + preview_surfaces[i] = value; canvas_a = 0; } if(preview_sequence[i] != noone) { if(array_length(preview_sequence[i]) == 0) return; - preview_surface[i] = preview_sequence[i][safe_mod(node.preview_index, array_length(preview_sequence[i]))]; + preview_surfaces[i] = preview_sequence[i][safe_mod(node.preview_index, array_length(preview_sequence[i]))]; } } @@ -555,7 +556,7 @@ function Panel_Preview() : PanelContent() constructor { } #endregion function drawOnionSkin(node, psx, psy, ss) { #region - var _surf = preview_surface[0]; + var _surf = preview_surfaces[0]; var _rang = PROJECT.onion_skin.range; var _alph = PROJECT.onion_skin.alpha; @@ -599,12 +600,12 @@ function Panel_Preview() : PanelContent() constructor { var ssx = 0, ssy = 0; var ssw = 0, ssh = 0; - if(is_surface(preview_surface[0])) { + if(is_surface(preview_surfaces[0])) { psx = canvas_x + preview_node[0].preview_x * ss; psy = canvas_y + preview_node[0].preview_y * ss; - psw = surface_get_width_safe(preview_surface[0]); - psh = surface_get_height_safe(preview_surface[0]); + psw = surface_get_width_safe(preview_surfaces[0]); + psh = surface_get_height_safe(preview_surfaces[0]); pswd = psw * ss; pshd = psh * ss; @@ -612,99 +613,131 @@ function Panel_Preview() : PanelContent() constructor { psy1 = psy + pshd; } - if(is_surface(preview_surface[1])) { + if(is_surface(preview_surfaces[1])) { var ssx = canvas_x + preview_node[1].preview_x * ss; var ssy = canvas_y + preview_node[1].preview_y * ss; - var ssw = surface_get_width_safe(preview_surface[1]); - var ssh = surface_get_height_safe(preview_surface[1]); + var ssw = surface_get_width_safe(preview_surfaces[1]); + var ssh = surface_get_height_safe(preview_surfaces[1]); } var _node = getNodePreview(); if(_node) title = _node.renamed? _node.display_name : _node.name; - if(splitView == 0 && tileMode == 0) { - var node = preview_node[0]; - if(is_surface(preview_surface[0])) { - node.previewing = 1; - var aa = node.preview_alpha; + #region >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Draw Surfaces <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + var _ps0 = is_surface(preview_surfaces[0]); + var _ps1 = is_surface(preview_surfaces[1]); - if(PROJECT.onion_skin.enabled) drawOnionSkin(node, psx, psy, ss); - else draw_surface_ext_safe(preview_surface[0], psx, psy, ss, ss, 0, c_white, aa); + if(_ps0) { + var _sw = surface_get_width(preview_surfaces[0]); + var _sh = surface_get_height(preview_surfaces[0]); + + preview_surface[0] = surface_verify(preview_surface[0], _sw, _sh); + + surface_set_shader(preview_surface[0], PROJECT.attributes.palette_fix? sh_posterize_palette : sh_sample); + shader_set_f("palette", PROJECT.palettes); + shader_set_i("keys", array_length(PROJECT.attributes.palette)); + shader_set_i("alpha", 1); + + draw_surface(preview_surfaces[0], 0, 0); + surface_reset_shader(); } - } - - switch(splitView) { #region draw surfaces - case 0 : - if(is_surface(preview_surface[0])) { - preview_node[0].previewing = 1; + + if(_ps1) { + var _sw = surface_get_width(preview_surfaces[1]); + var _sh = surface_get_height(preview_surfaces[1]); + + preview_surface[1] = surface_verify(preview_surface[1], _sw, _sh); + + surface_set_shader(preview_surface[1], PROJECT.attributes.palette_fix? sh_posterize_palette : sh_sample); + shader_set_f("palette", PROJECT.palettes); + shader_set_i("keys", array_length(PROJECT.attributes.palette)); + shader_set_i("alpha", 1); - switch(tileMode) { - case 1 : - tile_surface = surface_verify(tile_surface, w, surface_get_height_safe(preview_surface[0]) * ss); - surface_set_target(tile_surface); - DRAW_CLEAR - draw_surface_tiled_ext_safe(preview_surface[0], psx, 0, ss, ss, 0, c_white, 1); - surface_reset_target(); - draw_surface_safe(tile_surface, 0, psy); - break; - case 2 : - tile_surface = surface_verify(tile_surface, surface_get_width_safe(preview_surface[0]) * ss, h); - surface_set_target(tile_surface); - DRAW_CLEAR - draw_surface_tiled_ext_safe(preview_surface[0], 0, psy, ss, ss, 0, c_white, 1); - surface_reset_target(); - draw_surface_safe(tile_surface, psx, 0); - break; - case 3 : draw_surface_tiled_ext_safe(preview_surface[0], psx, psy, ss, ss, 0, c_white, 1); break; + draw_surface(preview_surfaces[1], 0, 0); + surface_reset_shader(); + } + + switch(splitView) { + case 0 : + if(_ps0) { + preview_node[0].previewing = 1; + + switch(tileMode) { + case 0 : + if(PROJECT.onion_skin.enabled) drawOnionSkin(node, psx, psy, ss); + else draw_surface_ext(preview_surface[0], psx, psy, ss, ss, 0, c_white, preview_node[0].preview_alpha); + break; + + case 1 : + tile_surface = surface_verify(tile_surface, w, surface_get_height_safe(preview_surface[0]) * ss); + surface_set_target(tile_surface); + DRAW_CLEAR + draw_surface_tiled_ext_safe(preview_surface[0], psx, 0, ss, ss, 0, c_white, 1); + surface_reset_target(); + draw_surface_safe(tile_surface, 0, psy); + break; + + case 2 : + tile_surface = surface_verify(tile_surface, surface_get_width_safe(preview_surface[0]) * ss, h); + surface_set_target(tile_surface); + DRAW_CLEAR + draw_surface_tiled_ext_safe(preview_surface[0], 0, psy, ss, ss, 0, c_white, 1); + surface_reset_target(); + draw_surface_safe(tile_surface, psx, 0); + break; + + case 3 : + draw_surface_tiled_ext_safe(preview_surface[0], psx, psy, ss, ss, 0, c_white, 1); break; + } } - } - break; - case 1 : - var sp = splitPosition * w; + break; + case 1 : + var sp = splitPosition * w; - if(is_surface(preview_surface[0])) { - preview_node[0].previewing = 2; - var maxX = min(sp, psx1); - var sW = min(psw, (maxX - psx) / ss); + if(_ps0) { + preview_node[0].previewing = 2; + var maxX = min(sp, psx1); + var sW = min(psw, (maxX - psx) / ss); - if(sW > 0) - draw_surface_part_ext_safe(preview_surface[0], 0, 0, sW, psh, psx, psy, ss, ss, 0, c_white, 1); - } + if(sW > 0) + draw_surface_part_ext_safe(preview_surface[0], 0, 0, sW, psh, psx, psy, ss, ss, 0, c_white, 1); + } - if(is_surface(preview_surface[1])) { - preview_node[1].previewing = 3; - var minX = max(ssx, sp); - var sX = (minX - ssx) / ss; - var spx = max(sp, ssx); + if(_ps1) { + preview_node[1].previewing = 3; + var minX = max(ssx, sp); + var sX = (minX - ssx) / ss; + var spx = max(sp, ssx); - if(sX >= 0 && sX < ssw) - draw_surface_part_ext_safe(preview_surface[1], sX, 0, ssw - sX, ssh, spx, ssy, ss, ss, 0, c_white, 1); - } - break; - case 2 : - var sp = splitPosition * h; + if(sX >= 0 && sX < ssw) + draw_surface_part_ext_safe(preview_surface[1], sX, 0, ssw - sX, ssh, spx, ssy, ss, ss, 0, c_white, 1); + } + break; + case 2 : + var sp = splitPosition * h; - if(is_surface(preview_surface[0])) { - preview_node[0].previewing = 4; - var maxY = min(sp, psy1); - var sH = min(psh, (maxY - psy) / ss); + if(_ps0) { + preview_node[0].previewing = 4; + var maxY = min(sp, psy1); + var sH = min(psh, (maxY - psy) / ss); - if(sH > 0) - draw_surface_part_ext_safe(preview_surface[0], 0, 0, psw, sH, psx, psy, ss, ss, 0, c_white, 1); - } + if(sH > 0) + draw_surface_part_ext_safe(preview_surface[0], 0, 0, psw, sH, psx, psy, ss, ss, 0, c_white, 1); + } - if(is_surface(preview_surface[1])) { - preview_node[1].previewing = 5; - var minY = max(ssy, sp); - var sY = (minY - ssy) / ss; - var spy = max(sp, ssy); + if(_ps1) { + preview_node[1].previewing = 5; + var minY = max(ssy, sp); + var sY = (minY - ssy) / ss; + var spy = max(sp, ssy); - if(sY >= 0 && sY < ssh) - draw_surface_part_ext_safe(preview_surface[1], 0, sY, ssw, ssh - sY, ssx, spy, ss, ss, 0, c_white, 1); - } - break; - } #endregion + if(sY >= 0 && sY < ssh) + draw_surface_part_ext_safe(preview_surface[1], 0, sY, ssw, ssh - sY, ssx, spy, ss, ss, 0, c_white, 1); + } + break; + } + #endregion if(!instance_exists(o_dialog_menubox)) { #region color sample sample_color = noone; @@ -723,7 +756,7 @@ function Panel_Preview() : PanelContent() constructor { } } #endregion - if(is_surface(preview_surface[0])) { #region outline + if(is_surface(preview_surfaces[0])) { #region outline if(PROJECT.previewGrid.show) { var _gw = PROJECT.previewGrid.size[0] * canvas_s; var _gh = PROJECT.previewGrid.size[1] * canvas_s; diff --git a/scripts/project_data/project_data.gml b/scripts/project_data/project_data.gml index e9c46c112..249a883fd 100644 --- a/scripts/project_data/project_data.gml +++ b/scripts/project_data/project_data.gml @@ -55,15 +55,29 @@ on_top: true, }; #endregion - attributes = { #region - surface_dimension: [ 32, 32 ], - palette: [ cola(c_black), cola(c_white) ] - } #endregion - - attributeEditor = [ #region - [ "Default Surface", "surface_dimension", new vectorBox(2, function(ind, val) { attributes.surface_dimension[ind] = val; RENDER_ALL return true; }) ], - [ "Palette", "palette", new buttonPalette(function(pal) { attributes.palette = pal; RENDER_ALL return true; }) ], - ]; #endregion + #region =================== ATTRIBUTES =================== + attributes = { + surface_dimension : [ 32, 32 ], + palette : [ cola(c_black), cola(c_white) ], + palette_fix : false, + } + + var _bpal = new buttonPalette(function(pal) { setPalette(pal); RENDER_ALL return true; }); + + //_bpal.side_button = button(function() { attributes.palette_fix = !attributes.palette_fix; RENDER_ALL return true; }) + // .setIcon( THEME.project_fix_palette, [ function() { return attributes.palette_fix; } ], COLORS._main_icon ) + // .setTooltip("Fix palette"); + + attributeEditor = [ + [ "Default Surface", "surface_dimension", new vectorBox(2, function(ind, val) { attributes.surface_dimension[ind] = val; RENDER_ALL return true; }) ], + [ "Palette", "palette", _bpal ], + ]; + + static setPalette = function(pal = noone) { + if(pal != noone) attributes.palette = pal; + palettes = paletteToArray(attributes.palette); + } setPalette(); + #endregion timelines = new timelineItemGroup(); diff --git a/scripts/surface_functions/surface_functions.gml b/scripts/surface_functions/surface_functions.gml index e2ef3d689..dd8239a9a 100644 --- a/scripts/surface_functions/surface_functions.gml +++ b/scripts/surface_functions/surface_functions.gml @@ -1,100 +1,101 @@ -//draw -function draw_surface_safe(surface, _x = 0, _y = 0) { #region - INLINE - - if(is_struct(surface)) { - if(is_instanceof(surface, dynaSurf)) { - surface.draw(_x, _y); - return; - } else if(is_instanceof(surface, SurfaceAtlas)) - surface = surface.getSurface(); - } - if(!surface_exists(surface)) return; - - __channel_pre(surface); - draw_surface(surface, _x, _y); - __channel_pos(surface); -} #endregion +#region ==================================== DRAW ==================================== -function draw_surface_stretched_safe(surface, _x, _y, _w, _h) { #region - INLINE + function draw_surface_safe(surface, _x = 0, _y = 0) { #region + INLINE - if(is_struct(surface)) { - if(is_instanceof(surface, dynaSurf)) { - surface.drawStretch(_x, _y, _w, _h); - return; - } else if(is_instanceof(surface, SurfaceAtlas)) - surface = surface.getSurface(); - } - if(!surface_exists(surface)) return; + if(is_struct(surface)) { + if(is_instanceof(surface, dynaSurf)) { + surface.draw(_x, _y); + return; + } else if(is_instanceof(surface, SurfaceAtlas)) + surface = surface.getSurface(); + } + if(!surface_exists(surface)) return; - __channel_pre(surface); - draw_surface_stretched(surface, _x, _y, _w, _h); - __channel_pos(surface); -} #endregion + __channel_pre(surface); + draw_surface(surface, _x, _y); + __channel_pos(surface); + } #endregion -function draw_surface_ext_safe(surface, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region - INLINE + function draw_surface_stretched_safe(surface, _x, _y, _w, _h) { #region + INLINE - if(is_struct(surface)) { - if(is_instanceof(surface, dynaSurf)) { - surface.draw(_x, _y, _xs, _ys, _rot, _col, _alpha); - return; - } else if(is_instanceof(surface, SurfaceAtlas)) - surface = surface.getSurface(); - } + if(is_struct(surface)) { + if(is_instanceof(surface, dynaSurf)) { + surface.drawStretch(_x, _y, _w, _h); + return; + } else if(is_instanceof(surface, SurfaceAtlas)) + surface = surface.getSurface(); + } + if(!surface_exists(surface)) return; - if(!surface_exists(surface)) return; - - __channel_pre(surface); - draw_surface_ext(surface, _x, _y, _xs, _ys, _rot, _col, _alpha); - __channel_pos(surface); -} #endregion + __channel_pre(surface); + draw_surface_stretched(surface, _x, _y, _w, _h); + __channel_pos(surface); + } #endregion -function draw_surface_tiled_safe(surface, _x, _y) { #region - INLINE + function draw_surface_ext_safe(surface, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region + INLINE - if(is_struct(surface)) { - if(is_instanceof(surface, dynaSurf)) { - surface.drawTile(_x, _y); - return; - } else if(is_instanceof(surface, SurfaceAtlas)) - surface = surface.getSurface(); - } - if(!surface_exists(surface)) return; + if(is_struct(surface)) { + if(is_instanceof(surface, dynaSurf)) { + surface.draw(_x, _y, _xs, _ys, _rot, _col, _alpha); + return; + } else if(is_instanceof(surface, SurfaceAtlas)) + surface = surface.getSurface(); + } - __channel_pre(surface); - draw_surface_tiled(surface, _x, _y); - __channel_pos(surface); -} #endregion + if(!surface_exists(surface)) return; + + __channel_pre(surface); + draw_surface_ext(surface, _x, _y, _xs, _ys, _rot, _col, _alpha); + __channel_pos(surface); + } #endregion -function draw_surface_tiled_ext_safe(surface, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region - INLINE + function draw_surface_tiled_safe(surface, _x, _y) { #region + INLINE - if(is_struct(surface)) { - if(is_instanceof(surface, dynaSurf)) { - surface.drawTile(_x, _y, _xs, _ys, _col, _alpha); - return; - } else if(is_instanceof(surface, SurfaceAtlas)) - surface = surface.getSurface(); - } - if(!surface_exists(surface)) return; + if(is_struct(surface)) { + if(is_instanceof(surface, dynaSurf)) { + surface.drawTile(_x, _y); + return; + } else if(is_instanceof(surface, SurfaceAtlas)) + surface = surface.getSurface(); + } + if(!surface_exists(surface)) return; - var back = surface_get_target(); - var bdim = surface_get_dimension(back); + __channel_pre(surface); + draw_surface_tiled(surface, _x, _y); + __channel_pos(surface); + } #endregion + + function draw_surface_tiled_ext_safe(surface, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region + INLINE - shader_set(sh_draw_tile); - shader_set_f("backDimension", bdim); - shader_set_f("foreDimension", surface_get_dimension(surface)); - shader_set_f("position" , [ _x, _y ]); - shader_set_f("scale" , [ _xs, _ys ]); - shader_set_f("rotation" , _rot); + if(is_struct(surface)) { + if(is_instanceof(surface, dynaSurf)) { + surface.drawTile(_x, _y, _xs, _ys, _col, _alpha); + return; + } else if(is_instanceof(surface, SurfaceAtlas)) + surface = surface.getSurface(); + } + if(!surface_exists(surface)) return; + + var back = surface_get_target(); + var bdim = surface_get_dimension(back); + + shader_set(sh_draw_tile); + shader_set_f("backDimension", bdim); + shader_set_f("foreDimension", surface_get_dimension(surface)); + shader_set_f("position" , [ _x, _y ]); + shader_set_f("scale" , [ _xs, _ys ]); + shader_set_f("rotation" , _rot); - draw_surface_stretched_ext(surface, 0, 0, bdim[0], bdim[1], _col, _alpha); - shader_reset(); -} #endregion + draw_surface_stretched_ext(surface, 0, 0, bdim[0], bdim[1], _col, _alpha); + shader_reset(); + } #endregion -function draw_surface_part_ext_safe(surface, _l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region + function draw_surface_part_ext_safe(surface, _l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alpha = 1) { #region INLINE if(is_struct(surface)) { @@ -110,56 +111,537 @@ function draw_surface_part_ext_safe(surface, _l, _t, _w, _h, _x, _y, _xs = 1, _y draw_surface_part_ext(surface, _l, _t, _w, _h, _x, _y, _xs, _ys, _col, _alpha); __channel_pos(surface); } #endregion + +#endregion ==================================== DRAW ==================================== -#macro surface_free surface_free_safe -#macro __surface_free surface_free +#region ==================================== CHECK =================================== -function surface_free_safe(surface) { #region + function is_surface(s) { #region + INLINE + + if(is_instanceof(s, dynaSurf) || is_instanceof(s, SurfaceAtlas)) return true; + if(is_numeric(s) && s > 0 && surface_exists(s)) return true; + return false; + } #endregion + + function surface_verify(surf, w, h, format = surface_rgba8unorm) { #region + INLINE + + if(!is_surface(surf)) return surface_create_valid(w, h, format); + return surface_size_to(surf, w, h, format, true); + } #endregion + + function surface_valid(surf, w, h, format = surface_rgba8unorm) { #region INLINE - if(!is_surface(surface)) return; - __surface_free(surface); + if(!is_surface(surf)) return false; + var _sw = surface_get_width(surf); + var _sh = surface_get_height(surf); + var _f = surface_get_format(surf); + + return _sw == w && _sh == h && _f == format; } #endregion -function surface_save_safe(surface, path) { #region - if(!is_surface(surface)) return; - var f = surface_get_format(surface); +#endregion ==================================== CHECK ==================================== + +#region ==================================== GET ===================================== + + function surface_get_width_safe(s, crop = true) { #region + INLINE - if(f == surface_rgba8unorm) { - surface_save(surface, path); - return; - } + if(is_struct(s)) { + if(is_instanceof(s, dynaSurf)) return s.getWidth(); + else if(is_instanceof(s, SurfaceAtlas)) return crop? surface_get_width(s.getSurface()) : s.oriSurf_w; + else return 1; + } - var w = surface_get_width_safe(surface); - var h = surface_get_height_safe(surface); - var s = surface_create(w, h, surface_rgba8unorm); + return surface_get_width(s); + } #endregion + + function surface_get_height_safe(s, crop = true) { #region + INLINE - switch(f) { - case surface_rgba4unorm : - case surface_rgba8unorm : - case surface_rgba16float : - case surface_rgba32float : - surface_set_shader(s, sh_draw_normal); - draw_surface(surface, 0, 0); - surface_reset_shader(); - surface_save(s, path); + if(is_struct(s)) { + if(is_instanceof(s, dynaSurf)) return s.getHeight(); + else if(is_instanceof(s, SurfaceAtlas)) return crop? surface_get_height(s.getSurface()) : s.oriSurf_h; + else return 1; + } + + return surface_get_height(s); + } #endregion + + function surface_get_dimension(s) { #region + INLINE + + if(!is_surface(s)) return [ 1, 1 ]; + return [ surface_get_width_safe(s), surface_get_height_safe(s) ]; + } #endregion + + function surface_get_pixel(surface, _x, _y) { #region + INLINE + + if(!is_surface(surface)) return; + var f = surface_get_format(surface); + var fx = floor(_x); + var fy = floor(_y); + var rx = frac(_x); + var ry = frac(_y); + var px = surface_getpixel(surface, fx, fy); + + if(rx == 0 && ry == 0) { + if(is_numeric(px)) return px; + return make_color_rgb(px[0] * 256, px[1] * 256, px[2] * 256); + } + + var p1 = surface_getpixel(surface, fx + 1, fy + 0); + var p2 = surface_getpixel(surface, fx + 0, fy + 1); + var p3 = surface_getpixel(surface, fx + 1, fy + 1); + + return merge_color( + merge_color(px, p1, rx), + merge_color(p2, p3, rx), + ry); + + } #endregion + + function surface_get_pixel_ext(surface, _x, _y) { #region + INLINE + + if(!is_surface(surface)) return; + var px = surface_getpixel_ext(surface, _x, _y); + + if(is_numeric(px)) return px; + return round(px[0] * (255 * power(256, 0))) + round(px[1] * (255 * power(256, 1))) + round(px[2] * (255 * power(256, 2))) + round(px[3] * (255 * power(256, 3))); + } #endregion + +#endregion ==================================== GET ==================================== + +#region =================================== CREATE =================================== + + function surface_create_empty(w, h, format = surface_rgba8unorm) { #region + INLINE + + var s = surface_create(w, h, format); + surface_clear(s); + return s; + } #endregion + + function surface_create_size(surface, format = surface_rgba8unorm) { #region + INLINE + + return surface_create_valid(surface_get_width_safe(surface), surface_get_height_safe(surface), format); + } #endregion + + function surface_create_valid(w, h, format = surface_rgba8unorm) { #region + INLINE + + return surface_create_empty(surface_valid_size(w), surface_valid_size(h), format); + } #endregion + + function surface_create_from_buffer(w, h, buff, format = surface_rgba8unorm) { #region + INLINE + + if(buff < 0) return; + var s = surface_create_valid(surface_valid_size(w), surface_valid_size(h), format); + buffer_set_surface(buff, s, 0); + return s; + } #endregion + + function surface_from_buffer(buff) { #region + static header_length = 24; + + if(!buffer_exists(buff)) return noone; + if(buffer_get_size(buff) < header_length) return noone; + + buffer_seek(buff, buffer_seek_start, 0); + var text = ""; + repeat(4) text += chr(buffer_read(buff, buffer_u8)); + if(text != "PXCS") return noone; + + var w = buffer_read(buff, buffer_u16); + var h = buffer_read(buff, buffer_u16); + var format = buffer_read(buff, buffer_u8); + if(w < 1 || h < 1) return noone; + + var s = surface_create(w, h, format); + buffer_set_surface(buff, s, header_length); + return s; + } #endregion + + function surface_create_from_sprite(spr) { #region + if(!sprite_exists(spr)) return noone; + + if(sprite_get_number(spr) == 1) + return surface_create_from_sprite_ext(spr, 0); + + var s = []; + for( var i = 0; i < sprite_get_number(spr); i++ ) { + array_push(s, surface_create_from_sprite_ext(spr, i)); + } + + return s; + } #endregion + + function surface_create_from_sprite_ext(spr, ind, format = surface_rgba8unorm) { #region + if(!sprite_exists(spr)) return noone; + var sw = sprite_get_width(spr); + var sh = sprite_get_height(spr); + + var s = surface_create_valid(sw, sh, format); + surface_set_target(s); + BLEND_OVERRIDE; + DRAW_CLEAR + draw_sprite(spr, ind, sprite_get_xoffset(spr), sprite_get_yoffset(spr)); + BLEND_NORMAL + surface_reset_target(); + + return s; + } #endregion + + function surface_size_lim(surface, width, height) { #region + var sw = surface_get_width_safe(surface); + var sh = surface_get_height_safe(surface); + if(sw <= width && sh <= height) return surface; + + var ss = min(width / sw, height / sh); + var s = surface_create(max(1, sw * ss), max(1, sh * ss)); + surface_set_target(s); + DRAW_CLEAR + draw_surface_ext_safe(surface, 0, 0, ss, ss, 0, c_white, 1); + surface_reset_target(); + return s; + } #endregion + + function surface_size_to(surface, width, height, format = noone, skipCheck = false) { #region + if(!skipCheck && !is_surface(surface)) return surface; + if(!is_numeric(width) || !is_numeric(height)) return surface; + if(width < 1 && height < 1) return surface; + + if(format != noone && format != surface_get_format(surface)) { + surface_free(surface); + return surface_create(width, height, format); + } + + width = surface_valid_size(width); + height = surface_valid_size(height); + + var ww = surface_get_width_safe(surface); + var hh = surface_get_height_safe(surface); + + if(ww == width && hh == height) return surface; + + surface_resize(surface, width, height); + surface_clear(surface); + + return surface; + } #endregion + + function surface_clear(surface) { #region + INLINE + + if(!is_surface(surface)) return; + surface_set_target(surface); + DRAW_CLEAR + surface_reset_target(); + } #endregion + + function surface_copy_from(dst, src, format = noone) { #region + INLINE + + surface_set_target(dst); + DRAW_CLEAR + BLEND_OVERRIDE; + draw_surface_safe(src, 0, 0); + BLEND_NORMAL + surface_reset_target(); + } #endregion + + function surface_clone(surface, destination = noone, format = noone) { #region + INLINE + + if(is_struct(surface) && is_instanceof(surface, dynaSurf)) + return surface.clone(); + if(!is_surface(surface)) return noone; + + destination = surface_verify(destination, surface_get_width_safe(surface), surface_get_height_safe(surface), format == noone? surface_get_format(surface) : format); + + surface_set_target(destination); + DRAW_CLEAR + BLEND_OVERRIDE; + draw_surface_safe(surface, 0, 0); + BLEND_NORMAL + surface_reset_target(); + + return destination; + } #endregion + +#endregion ==================================== CREATE ==================================== + +#region =================================== MODIFY =================================== + + function surface_stretch(surf, _w, _h) { #region + INLINE + + if(!is_surface(surf)) return noone; + + _w = surface_valid_size(_w); + _h = surface_valid_size(_h); + + var _surf = surface_create(_w, _h); + surface_set_target(_surf); + DRAW_CLEAR + draw_surface_stretched(surf, 0, 0, _w, _h); + surface_reset_target(); + + surface_free(surf); + return _surf; + } #endregion + + function surface_mirror(surf, _h, _v) { #region + INLINE + + if(!is_surface(surf)) return noone; + var _surf = surface_create_size(surf); + + surface_set_target(_surf); + DRAW_CLEAR + + var x0 = _h * surface_get_width_safe(_surf); + var y0 = _v * surface_get_height_safe(_surf); + + draw_surface_ext_safe(surf, x0, y0, _h * 2 - 1, _v * 2 - 1, 0, c_white, 1); + surface_reset_target(); + surface_free(surf); + + return _surf; + } #endregion + + function surface_project_posterize(surf) { #region + INLINE + + if(!PROJECT.attributes.palette_fix) return surf; + if(!is_surface(surf)) return surf; + + var _surf = surface_create(surface_get_width(surf), surface_get_height(surf)); + + surface_set_shader(_surf, sh_posterize_palette); + shader_set_f("palette", PROJECT.palettes); + shader_set_i("keys", array_length(PROJECT.attributes.palette)); + shader_set_i("alpha", 1); + + draw_surface(surf, 0, 0); + surface_reset_shader(); + + surface_free(surf); + + return _surf; + } #endregion + +#endregion ==================================== MODIFY ==================================== + +#region =================================== OTHERS =================================== + + function surface_copy_size(dest, source, format = noone) { #region + INLINE + + if(!is_surface(dest)) return; + if(!is_surface(source)) return; + + surface_size_to(dest, surface_get_width_safe(source), surface_get_height_safe(source), format); + surface_set_target(dest); + DRAW_CLEAR + surface_reset_target(); + + surface_copy_from(dest, source); + } #endregion + + function surface_valid_size(s) { #region + INLINE + + if(!is_numeric(s)) return 1; + if(is_infinity(s)) return 1; + return clamp(round(s), 1, 8196); + } #endregion + + function surface_array_free(arr) { #region + INLINE + + if(!is_array(arr)) { + if(is_surface(arr)) surface_free(arr); return; - case surface_r8unorm : s = surface_create(w, h, surface_rgba8unorm); break; - case surface_r16float : s = surface_create(w, h, surface_rgba16float); break; - case surface_r32float : s = surface_create(w, h, surface_rgba32float); break; - default: return; - } + } - surface_set_shader(s, sh_draw_single_channel); - draw_surface(surface, 0, 0); - surface_reset_shader(); - - surface_save(s, path); - surface_free(s); - return; -} #endregion + for( var i = 0, n = array_length(arr); i < n; i++ ) + surface_array_free(arr[i]); + } #endregion -function surface_cvt_8unorm(target, surface) { #region + function surface_array_clone(arr) { #region + if(!is_array(arr)) { + if(is_surface(arr)) + return surface_clone(arr); + else + return arr; + } + + var _arr = []; + + for( var i = 0, n = array_length(arr); i < n; i++ ) + _arr[i] = surface_array_clone(arr[i]); + + return _arr; + } #endregion + + function surface_array_serialize(arr) { #region + INLINE + + var _arr = __surface_array_serialize(arr); + return json_stringify(_arr); + } #endregion + + function __surface_array_serialize(arr) { #region + if(!is_array(arr)) { + if(is_surface(arr)) { + var buff = buffer_create(surface_get_width_safe(arr) * surface_get_height_safe(arr) * 4, buffer_fixed, 1); + buffer_get_surface(buff, arr, 0); + var comp = buffer_compress(buff, 0, buffer_get_size(buff)); + var enc = buffer_base64_encode(comp, 0, buffer_get_size(comp)); + buffer_delete(buff); + return { width: surface_get_width_safe(arr), height: surface_get_height_safe(arr), buffer: enc }; + } else + return arr; + } + + var _arr = []; + + for( var i = 0, n = array_length(arr); i < n; i++ ) + _arr[i] = __surface_array_serialize(arr[i]); + + return _arr; + } #endregion + + function surface_array_deserialize(arr, index = -1) { #region + INLINE + + var _arr = json_try_parse(arr); + return index == -1? __surface_array_deserialize(_arr) : __surface_array_deserialize(_arr[index]); + } #endregion + + function __surface_array_deserialize(arr) { #region + if(!is_array(arr)) { + if(!is_struct(arr) || !struct_has(arr, "buffer")) + return noone; + + var buff = buffer_base64_decode(arr.buffer); + buff = buffer_decompress(buff); + return surface_create_from_buffer(arr.width, arr.height, buff); + } + + var _arr = []; + + for( var i = 0, n = array_length(arr); i < n; i++ ) + _arr[i] = __surface_array_deserialize(arr[i]); + + return _arr; + } #endregion + + function surface_encode(surface) { #region + if(!is_real(surface)) return ""; + if(!surface_exists(surface)) return ""; + + var buff = buffer_create(surface_get_width_safe(surface) * surface_get_height_safe(surface) * 4, buffer_fixed, 1); + buffer_get_surface(buff, surface, 0); + var comp = buffer_compress(buff, 0, buffer_get_size(buff)); + var enc = buffer_base64_encode(comp, 0, buffer_get_size(comp)); + buffer_delete(buff); + var str = { width: surface_get_width_safe(surface), height: surface_get_height_safe(surface), buffer: enc }; + return json_stringify(str); + } #endregion + + function surface_decode(struct) { #region + var buff = buffer_base64_decode(struct.buffer); + var buff = buffer_decompress(buff); + return surface_create_from_buffer(struct.width, struct.height, buff); + } #endregion + + function surface_format_get_bytes(format) { #region + switch(format) { + case surface_rgba4unorm : return 4 * 0.5; break; + case surface_rgba8unorm : return 4 * 1; break; + case surface_rgba16float : return 4 * 2; break; + case surface_rgba32float : return 4 * 4; break; + + case surface_r8unorm : return 1 * 1; break; + case surface_r16float : return 1 * 2; break; + case surface_r32float : return 1 * 3; break; + } + return 1; + } #endregion + + function surface_get_size(surface) { #region + INLINE + + var sw = surface_get_width_safe(surface); + var sh = surface_get_height_safe(surface); + var sz = sw * sh * surface_format_get_bytes(surface_get_format(surface)); + return sz; + } #endregion + + function surface_texture(surface) { #region + INLINE + + if(!is_surface(surface)) return -1; + return surface_get_texture(surface); + } #endregion + + #macro surface_free surface_free_safe + #macro __surface_free surface_free + + function surface_free_safe(surface) { #region + INLINE + + if(!is_surface(surface)) return; + __surface_free(surface); + } #endregion + + function surface_save_safe(surface, path) { #region + if(!is_surface(surface)) return; + var f = surface_get_format(surface); + + if(f == surface_rgba8unorm) { + surface_save(surface, path); + return; + } + + var w = surface_get_width_safe(surface); + var h = surface_get_height_safe(surface); + var s = surface_create(w, h, surface_rgba8unorm); + + switch(f) { + case surface_rgba4unorm : + case surface_rgba8unorm : + case surface_rgba16float : + case surface_rgba32float : + surface_set_shader(s, sh_draw_normal); + draw_surface(surface, 0, 0); + surface_reset_shader(); + surface_save(s, path); + return; + case surface_r8unorm : s = surface_create(w, h, surface_rgba8unorm); break; + case surface_r16float : s = surface_create(w, h, surface_rgba16float); break; + case surface_r32float : s = surface_create(w, h, surface_rgba32float); break; + default: return; + } + + surface_set_shader(s, sh_draw_single_channel); + draw_surface(surface, 0, 0); + surface_reset_shader(); + + surface_save(s, path); + surface_free(s); + return; + } #endregion + + function surface_cvt_8unorm(target, surface) { #region if(!is_surface(surface)) return target; target = surface_verify(target, surface_get_width_safe(surface), surface_get_height_safe(surface)); @@ -185,448 +667,4 @@ function surface_cvt_8unorm(target, surface) { #region return target; } #endregion -function surface_get_width_safe(s, crop = true) { #region - INLINE - - if(is_struct(s)) { - if(is_instanceof(s, dynaSurf)) return s.getWidth(); - else if(is_instanceof(s, SurfaceAtlas)) return crop? surface_get_width(s.getSurface()) : s.oriSurf_w; - else return 1; - } - - return surface_get_width(s); -} #endregion - -function surface_get_height_safe(s, crop = true) { #region - INLINE - - if(is_struct(s)) { - if(is_instanceof(s, dynaSurf)) return s.getHeight(); - else if(is_instanceof(s, SurfaceAtlas)) return crop? surface_get_height(s.getSurface()) : s.oriSurf_h; - else return 1; - } - - return surface_get_height(s); -} #endregion - -function surface_get_dimension(s) { #region - INLINE - - if(!is_surface(s)) return [ 1, 1 ]; - return [ surface_get_width_safe(s), surface_get_height_safe(s) ]; -} #endregion - -//check -function is_surface(s) { #region - INLINE - - if(is_instanceof(s, dynaSurf) || is_instanceof(s, SurfaceAtlas)) return true; - if(is_numeric(s) && s > 0 && surface_exists(s)) return true; - return false; -} #endregion - -function surface_verify(surf, w, h, format = surface_rgba8unorm) { #region - INLINE - - if(!is_surface(surf)) return surface_create_valid(w, h, format); - return surface_size_to(surf, w, h, format, true); -} #endregion - -function surface_valid(surf, w, h, format = surface_rgba8unorm) { #region - INLINE - - if(!is_surface(surf)) return false; - var _sw = surface_get_width(surf); - var _sh = surface_get_height(surf); - var _f = surface_get_format(surf); - - return _sw == w && _sh == h && _f == format; -} #endregion - -//get -function surface_get_pixel(surface, _x, _y) { #region - INLINE - - if(!is_surface(surface)) return; - var f = surface_get_format(surface); - var fx = floor(_x); - var fy = floor(_y); - var rx = frac(_x); - var ry = frac(_y); - var px = surface_getpixel(surface, fx, fy); - - if(rx == 0 && ry == 0) { - if(is_numeric(px)) return px; - return make_color_rgb(px[0] * 256, px[1] * 256, px[2] * 256); - } - - var p1 = surface_getpixel(surface, fx + 1, fy + 0); - var p2 = surface_getpixel(surface, fx + 0, fy + 1); - var p3 = surface_getpixel(surface, fx + 1, fy + 1); - - return merge_color( - merge_color(px, p1, rx), - merge_color(p2, p3, rx), - ry); - -} #endregion - -function surface_get_pixel_ext(surface, _x, _y) { #region - INLINE - - if(!is_surface(surface)) return; - var px = surface_getpixel_ext(surface, _x, _y); - - if(is_numeric(px)) return px; - return round(px[0] * (255 * power(256, 0))) + round(px[1] * (255 * power(256, 1))) + round(px[2] * (255 * power(256, 2))) + round(px[3] * (255 * power(256, 3))); -} #endregion - -//create -function surface_create_empty(w, h, format = surface_rgba8unorm) { #region - INLINE - - var s = surface_create(w, h, format); - surface_clear(s); - return s; -} #endregion - -function surface_create_size(surface, format = surface_rgba8unorm) { #region - INLINE - - return surface_create_valid(surface_get_width_safe(surface), surface_get_height_safe(surface), format); -} #endregion - -function surface_create_valid(w, h, format = surface_rgba8unorm) { #region - INLINE - - return surface_create_empty(surface_valid_size(w), surface_valid_size(h), format); -} #endregion - -function surface_create_from_buffer(w, h, buff, format = surface_rgba8unorm) { #region - INLINE - - if(buff < 0) return; - var s = surface_create_valid(surface_valid_size(w), surface_valid_size(h), format); - buffer_set_surface(buff, s, 0); - return s; -} #endregion - -function surface_from_buffer(buff) { #region - static header_length = 24; - - if(!buffer_exists(buff)) return noone; - if(buffer_get_size(buff) < header_length) return noone; - - buffer_seek(buff, buffer_seek_start, 0); - var text = ""; - repeat(4) text += chr(buffer_read(buff, buffer_u8)); - if(text != "PXCS") return noone; - - var w = buffer_read(buff, buffer_u16); - var h = buffer_read(buff, buffer_u16); - var format = buffer_read(buff, buffer_u8); - if(w < 1 || h < 1) return noone; - - var s = surface_create(w, h, format); - buffer_set_surface(buff, s, header_length); - return s; -} #endregion - -function surface_create_from_sprite(spr) { #region - if(!sprite_exists(spr)) return noone; - - if(sprite_get_number(spr) == 1) - return surface_create_from_sprite_ext(spr, 0); - - var s = []; - for( var i = 0; i < sprite_get_number(spr); i++ ) { - array_push(s, surface_create_from_sprite_ext(spr, i)); - } - - return s; -} #endregion - -function surface_create_from_sprite_ext(spr, ind, format = surface_rgba8unorm) { #region - if(!sprite_exists(spr)) return noone; - var sw = sprite_get_width(spr); - var sh = sprite_get_height(spr); - - var s = surface_create_valid(sw, sh, format); - surface_set_target(s); - BLEND_OVERRIDE; - DRAW_CLEAR - draw_sprite(spr, ind, sprite_get_xoffset(spr), sprite_get_yoffset(spr)); - BLEND_NORMAL - surface_reset_target(); - - return s; -} #endregion - -function surface_size_lim(surface, width, height) { #region - var sw = surface_get_width_safe(surface); - var sh = surface_get_height_safe(surface); - if(sw <= width && sh <= height) return surface; - - var ss = min(width / sw, height / sh); - var s = surface_create(max(1, sw * ss), max(1, sh * ss)); - surface_set_target(s); - DRAW_CLEAR - draw_surface_ext_safe(surface, 0, 0, ss, ss, 0, c_white, 1); - surface_reset_target(); - return s; -} #endregion - -function surface_size_to(surface, width, height, format = noone, skipCheck = false) { #region - if(!skipCheck && !is_surface(surface)) return surface; - if(!is_numeric(width) || !is_numeric(height)) return surface; - if(width < 1 && height < 1) return surface; - - if(format != noone && format != surface_get_format(surface)) { - surface_free(surface); - return surface_create(width, height, format); - } - - width = surface_valid_size(width); - height = surface_valid_size(height); - - var ww = surface_get_width_safe(surface); - var hh = surface_get_height_safe(surface); - - if(ww == width && hh == height) return surface; - - surface_resize(surface, width, height); - surface_clear(surface); - - return surface; -} #endregion - -function surface_clear(surface) { #region - INLINE - - if(!is_surface(surface)) return; - surface_set_target(surface); - DRAW_CLEAR - surface_reset_target(); -} #endregion - -function surface_copy_from(dst, src, format = noone) { #region - INLINE - - surface_set_target(dst); - DRAW_CLEAR - BLEND_OVERRIDE; - draw_surface_safe(src, 0, 0); - BLEND_NORMAL - surface_reset_target(); -} #endregion - -function surface_clone(surface, destination = noone, format = noone) { #region - INLINE - - if(is_struct(surface) && is_instanceof(surface, dynaSurf)) - return surface.clone(); - if(!is_surface(surface)) return noone; - - destination = surface_verify(destination, surface_get_width_safe(surface), surface_get_height_safe(surface), format == noone? surface_get_format(surface) : format); - - surface_set_target(destination); - DRAW_CLEAR - BLEND_OVERRIDE; - draw_surface_safe(surface, 0, 0); - BLEND_NORMAL - surface_reset_target(); - - return destination; -} #endregion - -//in-place modification -function surface_stretch(surf, _w, _h) { #region - INLINE - - if(!is_surface(surf)) return noone; - - _w = surface_valid_size(_w); - _h = surface_valid_size(_h); - - var _surf = surface_create(_w, _h); - surface_set_target(_surf); - DRAW_CLEAR - draw_surface_stretched(surf, 0, 0, _w, _h); - surface_reset_target(); - - surface_free(surf); - return _surf; -} #endregion - -function surface_mirror(surf, _h, _v) { #region - INLINE - - if(!is_surface(surf)) return noone; - var _surf = surface_create_size(surf); - - surface_set_target(_surf); - DRAW_CLEAR - - var x0 = _h * surface_get_width_safe(_surf); - var y0 = _v * surface_get_height_safe(_surf); - - draw_surface_ext_safe(surf, x0, y0, _h * 2 - 1, _v * 2 - 1, 0, c_white, 1); - surface_reset_target(); - surface_free(surf); - - return _surf; -} #endregion - -//others -function surface_copy_size(dest, source, format = noone) { #region - INLINE - - if(!is_surface(dest)) return; - if(!is_surface(source)) return; - - surface_size_to(dest, surface_get_width_safe(source), surface_get_height_safe(source), format); - surface_set_target(dest); - DRAW_CLEAR - surface_reset_target(); - - surface_copy_from(dest, source); -} #endregion - -function surface_valid_size(s) { #region - INLINE - - if(!is_numeric(s)) return 1; - if(is_infinity(s)) return 1; - return clamp(round(s), 1, 8196); -} #endregion - -function surface_array_free(arr) { #region - INLINE - - if(!is_array(arr)) { - if(is_surface(arr)) surface_free(arr); - return; - } - - for( var i = 0, n = array_length(arr); i < n; i++ ) - surface_array_free(arr[i]); -} #endregion - -function surface_array_clone(arr) { #region - if(!is_array(arr)) { - if(is_surface(arr)) - return surface_clone(arr); - else - return arr; - } - - var _arr = []; - - for( var i = 0, n = array_length(arr); i < n; i++ ) - _arr[i] = surface_array_clone(arr[i]); - - return _arr; -} #endregion - -function surface_array_serialize(arr) { #region - INLINE - - var _arr = __surface_array_serialize(arr); - return json_stringify(_arr); -} #endregion - -function __surface_array_serialize(arr) { #region - if(!is_array(arr)) { - if(is_surface(arr)) { - var buff = buffer_create(surface_get_width_safe(arr) * surface_get_height_safe(arr) * 4, buffer_fixed, 1); - buffer_get_surface(buff, arr, 0); - var comp = buffer_compress(buff, 0, buffer_get_size(buff)); - var enc = buffer_base64_encode(comp, 0, buffer_get_size(comp)); - buffer_delete(buff); - return { width: surface_get_width_safe(arr), height: surface_get_height_safe(arr), buffer: enc }; - } else - return arr; - } - - var _arr = []; - - for( var i = 0, n = array_length(arr); i < n; i++ ) - _arr[i] = __surface_array_serialize(arr[i]); - - return _arr; -} #endregion - -function surface_array_deserialize(arr, index = -1) { #region - INLINE - - var _arr = json_try_parse(arr); - return index == -1? __surface_array_deserialize(_arr) : __surface_array_deserialize(_arr[index]); -} #endregion - -function __surface_array_deserialize(arr) { #region - if(!is_array(arr)) { - if(!is_struct(arr) || !struct_has(arr, "buffer")) - return noone; - - var buff = buffer_base64_decode(arr.buffer); - buff = buffer_decompress(buff); - return surface_create_from_buffer(arr.width, arr.height, buff); - } - - var _arr = []; - - for( var i = 0, n = array_length(arr); i < n; i++ ) - _arr[i] = __surface_array_deserialize(arr[i]); - - return _arr; -} #endregion - -function surface_encode(surface) { #region - if(!is_real(surface)) return ""; - if(!surface_exists(surface)) return ""; - - var buff = buffer_create(surface_get_width_safe(surface) * surface_get_height_safe(surface) * 4, buffer_fixed, 1); - buffer_get_surface(buff, surface, 0); - var comp = buffer_compress(buff, 0, buffer_get_size(buff)); - var enc = buffer_base64_encode(comp, 0, buffer_get_size(comp)); - buffer_delete(buff); - var str = { width: surface_get_width_safe(surface), height: surface_get_height_safe(surface), buffer: enc }; - return json_stringify(str); -} #endregion - -function surface_decode(struct) { #region - var buff = buffer_base64_decode(struct.buffer); - var buff = buffer_decompress(buff); - return surface_create_from_buffer(struct.width, struct.height, buff); -} #endregion - -function surface_format_get_bytes(format) { #region - switch(format) { - case surface_rgba4unorm : return 4 * 0.5; break; - case surface_rgba8unorm : return 4 * 1; break; - case surface_rgba16float : return 4 * 2; break; - case surface_rgba32float : return 4 * 4; break; - - case surface_r8unorm : return 1 * 1; break; - case surface_r16float : return 1 * 2; break; - case surface_r32float : return 1 * 3; break; - } - return 1; -} #endregion - -function surface_get_size(surface) { #region - INLINE - - var sw = surface_get_width_safe(surface); - var sh = surface_get_height_safe(surface); - var sz = sw * sh * surface_format_get_bytes(surface_get_format(surface)); - return sz; -} #endregion - -function surface_texture(surface) { #region - INLINE - - if(!is_surface(surface)) return -1; - return surface_get_texture(surface); -} #endregion - +#endregion =================================== OTHERS =================================== \ No newline at end of file diff --git a/shaders/sh_bend_arc/sh_bend_arc.fsh b/shaders/sh_bend_arc/sh_bend_arc.fsh new file mode 100644 index 000000000..e036ab61e --- /dev/null +++ b/shaders/sh_bend_arc/sh_bend_arc.fsh @@ -0,0 +1,15 @@ +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +#define PI 3.14159265358979323846; + +uniform vec2 position; +uniform float amount; + +void main() { + //vec2 cen = v_vTexcoord - position; + //float angle = (atan(cen.y, cen.x) / PI + 1.) / 2.; + //float dist = length(cen); + + gl_FragColor = texture2D( gm_BaseTexture, v_vTexcoord ); +} diff --git a/shaders/sh_bend_arc/sh_bend_arc.vsh b/shaders/sh_bend_arc/sh_bend_arc.vsh new file mode 100644 index 000000000..3900c20f4 --- /dev/null +++ b/shaders/sh_bend_arc/sh_bend_arc.vsh @@ -0,0 +1,19 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() +{ + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_bend_arc/sh_bend_arc.yy b/shaders/sh_bend_arc/sh_bend_arc.yy new file mode 100644 index 000000000..2a25720f2 --- /dev/null +++ b/shaders/sh_bend_arc/sh_bend_arc.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_bend_arc", + "parent": { + "name": "warp", + "path": "folders/shader/filter/warp.yy", + }, + "type": 1, +} \ No newline at end of file diff --git a/shaders/sh_dither/sh_dither.fsh b/shaders/sh_dither/sh_dither.fsh index 0ee948f30..f89c81c77 100644 --- a/shaders/sh_dither/sh_dither.fsh +++ b/shaders/sh_dither/sh_dither.fsh @@ -18,7 +18,7 @@ uniform vec2 dimension; uniform vec4 palette[32]; uniform int keys; -vec3 rgb2xyz( vec3 c ) { +vec3 rgb2xyz( vec3 c ) { #region vec3 tmp; tmp.x = ( c.r > 0.04045 ) ? pow( ( c.r + 0.055 ) / 1.055, 2.4 ) : c.r / 12.92; tmp.y = ( c.g > 0.04045 ) ? pow( ( c.g + 0.055 ) / 1.055, 2.4 ) : c.g / 12.92, @@ -27,35 +27,35 @@ vec3 rgb2xyz( vec3 c ) { mat3( 0.4124, 0.3576, 0.1805, 0.2126, 0.7152, 0.0722, 0.0193, 0.1192, 0.9505 ); -} +} #endregion -vec3 xyz2lab( vec3 c ) { +vec3 xyz2lab( vec3 c ) { #region vec3 n = c / vec3( 95.047, 100, 108.883 ); vec3 v; v.x = ( n.x > 0.008856 ) ? pow( n.x, 1.0 / 3.0 ) : ( 7.787 * n.x ) + ( 16.0 / 116.0 ); v.y = ( n.y > 0.008856 ) ? pow( n.y, 1.0 / 3.0 ) : ( 7.787 * n.y ) + ( 16.0 / 116.0 ); v.z = ( n.z > 0.008856 ) ? pow( n.z, 1.0 / 3.0 ) : ( 7.787 * n.z ) + ( 16.0 / 116.0 ); return vec3(( 116.0 * v.y ) - 16.0, 500.0 * ( v.x - v.y ), 200.0 * ( v.y - v.z )); -} +} #endregion -vec3 rgb2lab(vec3 c) { +vec3 rgb2lab(vec3 c) { #region vec3 lab = xyz2lab( rgb2xyz( c ) ); return vec3( lab.x / 100.0, 0.5 + 0.5 * ( lab.y / 127.0 ), 0.5 + 0.5 * ( lab.z / 127.0 )); -} +} #endregion -float colorDifferent(in vec4 c1, in vec4 c2) { +float colorDifferent(in vec4 c1, in vec4 c2) { #region vec3 lab1 = rgb2lab(c1.rgb); vec3 lab2 = rgb2lab(c2.rgb); return length(lab1 - lab2); -} +} #endregion -void main() { +void main() { #region vec4 _col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ); - bool exactColor = false; - int closet1_index = 0; - int closet2_index = 0; + bool exactColor = false; + int closet1_index = 0; + int closet2_index = 0; float closet1_value = 99.; float closet2_value = 99.; @@ -124,4 +124,4 @@ void main() { } gl_FragColor.a *= _col.a; -} +} #endregion diff --git a/shaders/sh_gradient_points/sh_gradient_points.fsh b/shaders/sh_gradient_points/sh_gradient_points.fsh index 03ce99941..7c830391e 100644 --- a/shaders/sh_gradient_points/sh_gradient_points.fsh +++ b/shaders/sh_gradient_points/sh_gradient_points.fsh @@ -1,25 +1,24 @@ -// -// Simple passthrough fragment shader -// +#define TAU 6.283185307179586 + varying vec2 v_vTexcoord; varying vec4 v_vColour; -#define TAU 6.283185307179586 - uniform vec2 dimension; uniform vec2 center[4]; uniform vec3 color[4]; uniform vec4 strength; +uniform int blend; + void main() { vec4 distances = vec4(0.); float maxDist = 0.; int i; for( i = 0; i < 4; i++ ) { - float d = distance(v_vTexcoord, center[i] / dimension); + float d = distance(v_vTexcoord, center[i] / dimension); distances[i] = d; - maxDist = max(maxDist, d); + maxDist = max(maxDist, d); } maxDist *= 2.; @@ -27,8 +26,15 @@ void main() { for( i = 0; i < 4; i++ ) distances[i] = pow((maxDist - distances[i]) / maxDist, strength[i]); - vec4 weights = distances / (distances[0] + distances[1] + distances[2] + distances[3]); - vec3 clr = (color[0] * weights[0]) + (color[1] * weights[1]) + (color[2] * weights[2]) + (color[3] * weights[3]); + vec4 weights; + + if(blend == 0) weights = distances / (distances[0] + distances[1] + distances[2] + distances[3]); + else if(blend == 1) weights = normalize(distances); + + vec3 clr = color[0] * weights[0] + + color[1] * weights[1] + + color[2] * weights[2] + + color[3] * weights[3]; gl_FragColor = vec4(clr, 1.); } diff --git a/shaders/sh_level/sh_level.fsh b/shaders/sh_level/sh_level.fsh index bcf23d163..74a2b92a2 100644 --- a/shaders/sh_level/sh_level.fsh +++ b/shaders/sh_level/sh_level.fsh @@ -1,21 +1,27 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; -uniform vec2 lw; -uniform vec2 lr; -uniform vec2 lg; -uniform vec2 lb; -uniform vec2 la; +uniform vec2 lwi; +uniform vec2 lri; +uniform vec2 lgi; +uniform vec2 lbi; +uniform vec2 lai; + +uniform vec2 lwo; +uniform vec2 lro; +uniform vec2 lgo; +uniform vec2 lbo; +uniform vec2 lao; void main() { vec4 col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ); - col.r = (col.r - lr.x) / (lr.y - lr.x); - col.g = (col.g - lg.x) / (lg.y - lg.x); - col.b = (col.b - lb.x) / (lb.y - lb.x); - col.a = (col.a - la.x) / (la.y - la.x); + col.r = (col.r - lri.x) / (lri.y - lri.x) * (lro.y - lro.x) + lro.x; + col.g = (col.g - lgi.x) / (lgi.y - lgi.x) * (lgo.y - lgo.x) + lgo.x; + col.b = (col.b - lbi.x) / (lbi.y - lbi.x) * (lbo.y - lbo.x) + lbo.x; + col.a = (col.a - lai.x) / (lai.y - lai.x) * (lao.y - lao.x) + lao.x; - col.rgb = (col.rgb - lw.x) / (lw.y - lw.x); + col.rgb = (col.rgb - lwi.x) / (lwi.y - lwi.x) * (lwo.y - lwo.x) + lwo.x; gl_FragColor = col; } diff --git a/shaders/sh_outline/sh_outline.fsh b/shaders/sh_outline/sh_outline.fsh index 63c298dcd..596ae62e6 100644 --- a/shaders/sh_outline/sh_outline.fsh +++ b/shaders/sh_outline/sh_outline.fsh @@ -79,7 +79,7 @@ void main() { #region #region filter out filled ot empty pixel bool isBorder = false; - if(side == 0) isBorder = point.a == 1.; + if(side == 0) isBorder = point.a > 0.; else if(side == 1) isBorder = point.a < 1.; if(!isBorder) { @@ -154,7 +154,7 @@ void main() { #region if(is_blend == 0) { if(side == 0) { col = borderColor; - if(is_aa == 1) + if(is_aa == 1) col.a = point.a; } else { float alpha = point.a + outline_alpha * (1. - point.a); diff --git a/shaders/sh_perlin/sh_perlin.fsh b/shaders/sh_perlin/sh_perlin.fsh index 5191f3fea..e88648027 100644 --- a/shaders/sh_perlin/sh_perlin.fsh +++ b/shaders/sh_perlin/sh_perlin.fsh @@ -1,6 +1,3 @@ -// -// Simple passthrough fragment shader -// varying vec2 v_vTexcoord; varying vec4 v_vColour; @@ -12,23 +9,21 @@ uniform int iteration; ///////////////////// PERLIN START ///////////////////// -float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); } +float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); } +vec2 random2 (in vec2 st) { + float a = random(st); + return vec2(cos(a), sin(a)); +} float noise (in vec2 st) { vec2 i = floor(st); vec2 f = fract(st); - - // Four corners in 2D of a tile - float a = random(i); - float b = random(i + vec2(1.0, 0.0)); - float c = random(i + vec2(0.0, 1.0)); - float d = random(i + vec2(1.0, 1.0)); - - // Cubic Hermine Curve. Same as SmoothStep() vec2 u = f * f * (3.0 - 2.0 * f); - // Mix 4 coorners percentages - return mix(mix(a, b, u.x), mix(c, d, u.x), u.y); + float lerp1 = mix(dot(f + vec2(0.0, 0.0), random2(i + vec2(0.0, 0.0))), dot(f + vec2(1.0, 0.0), random2(i + vec2(1.0, 0.0))), u.x); + float lerp2 = mix(dot(f + vec2(0.0, 1.0), random2(i + vec2(0.0, 1.0))), dot(f + vec2(1.0, 1.0), random2(i + vec2(1.0, 1.0))), u.x); + + return mix(lerp1, lerp2, u.y); } float perlin ( vec2 pos, int iteration ) { diff --git a/shaders/sh_perlin_tiled/sh_perlin_tiled.fsh b/shaders/sh_perlin_tiled/sh_perlin_tiled.fsh index 750b429ec..50ca0d5a1 100644 --- a/shaders/sh_perlin_tiled/sh_perlin_tiled.fsh +++ b/shaders/sh_perlin_tiled/sh_perlin_tiled.fsh @@ -25,16 +25,8 @@ vec3 hsv2rgb(vec3 c) { #region return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } #endregion -float random (in vec2 st, float _seed) { return fract(sin(dot(st.xy + vec2(21.456, 46.856), vec2(12.989, 78.233))) * (43758.545 + _seed)); } - -float randomFloat (in vec2 st, float _seed) { #region - float sedSt = floor(_seed); - float sedFr = fract(_seed); - - return mix(random(st, sedSt), random(st, sedSt + 1.), sedFr); -} #endregion - -vec2 random2 (in vec2 st, float _seed) { return vec2(random(st, _seed), random(st, _seed + 1.864)); } +float random (in vec2 st) { return smoothstep(0., 1., abs(fract(sin(dot(st.xy + vec2(21.456, 46.856), vec2(12.989, 78.233))) * (43758.545 + seed)) * 2. - 1.)); } +vec2 random2 (in vec2 st) { float a = random(st) * 6.28319; return vec2(cos(a), sin(a)); } float noise (in vec2 st, in vec2 scale) { #region vec2 cellMin = floor(st); @@ -48,12 +40,33 @@ float noise (in vec2 st, in vec2 scale) { #region vec2 f = fract(st); vec2 u = f * f * (3.0 - 2.0 * f); - float a = randomFloat(vec2(cellMin.x, cellMin.y), seed); - float b = randomFloat(vec2(cellMax.x, cellMin.y), seed); - float c = randomFloat(vec2(cellMin.x, cellMax.y), seed); - float d = randomFloat(vec2(cellMax.x, cellMax.y), seed); + vec2 _a = vec2(cellMin.x, cellMin.y); + vec2 _b = vec2(cellMax.x, cellMin.y); + vec2 _c = vec2(cellMin.x, cellMax.y); + vec2 _d = vec2(cellMax.x, cellMax.y); - return abs(mix(mix(a, b, u.x), mix(c, d, u.x), u.y)); + vec2 ai = f - vec2(0., 0.); + vec2 bi = f - vec2(1., 0.); + vec2 ci = f - vec2(0., 1.); + vec2 di = f - vec2(1., 1.); + + //float a = random(_a); + //float b = random(_b); + //float c = random(_c); + //float d = random(_d); + + vec2 a2 = random2(_a); + vec2 b2 = random2(_b); + vec2 c2 = random2(_c); + vec2 d2 = random2(_d); + + //float l1 = mix(a, b, u.x); + //float l2 = mix(c, d, u.x); + + float l1 = mix(dot(ai, a2), dot(bi, b2), u.x); + float l2 = mix(dot(ci, c2), dot(di, d2), u.x); + + return mix(l1, l2, u.y) + 0.5; } #endregion float perlin(in vec2 st) { #region @@ -65,8 +78,6 @@ float perlin(in vec2 st) { #region for(int i = 0; i < iteration; i++) { n += noise(pos, sc) * amp; - //pos += random2(vec2(float(i), float(i)), seed + 1.57) * sc; //make the result goes random somehow - sc *= 2.; amp *= .5; pos *= 2.; diff --git a/shaders/sh_region_fill_border/sh_region_fill_border.fsh b/shaders/sh_region_fill_border/sh_region_fill_border.fsh new file mode 100644 index 000000000..a64007fad --- /dev/null +++ b/shaders/sh_region_fill_border/sh_region_fill_border.fsh @@ -0,0 +1,64 @@ +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +#define ITERATION 8. + +uniform vec2 dimension; +uniform sampler2D original; + +vec4 sample ( vec2 position ) { + if(position.x < 0. || position.y < 0. || position.x > 1. || position.y > 1.) return vec4(0.); + return texture2D( gm_BaseTexture, position ); +} + +void main() { + vec2 tx = 1. / dimension; + vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); + vec4 o = texture2D( original, v_vTexcoord ); + + gl_FragColor = c; + if(c.a == 1.) return; + if(o.a == 0.) return; + + float minD = ITERATION; + + for( float i = 1.; i < ITERATION; i++ ) { + if(i >= minD) break; + + vec4 s = sample( v_vTexcoord + vec2(tx.x * i, 0.) ); + if(s.a == 0.) continue; + + gl_FragColor = s; + minD = i; + } + + for( float i = 1.; i < ITERATION; i++ ) { + if(i >= minD) break; + + vec4 s = sample( v_vTexcoord - vec2(tx.x * i, 0.) ); + if(s.a == 0.) continue; + + gl_FragColor = s; + minD = i; + } + + for( float i = 1.; i < ITERATION; i++ ) { + if(i >= minD) break; + + vec4 s = sample( v_vTexcoord + vec2(0., tx.y * i) ); + if(s.a == 0.) continue; + + gl_FragColor = s; + minD = i; + } + + for( float i = 1.; i < ITERATION; i++ ) { + if(i >= minD) break; + + vec4 s = sample( v_vTexcoord - vec2(0., tx.y * i) ); + if(s.a == 0.) continue; + + gl_FragColor = s; + minD = i; + } +} diff --git a/shaders/sh_region_fill_border/sh_region_fill_border.vsh b/shaders/sh_region_fill_border/sh_region_fill_border.vsh new file mode 100644 index 000000000..3900c20f4 --- /dev/null +++ b/shaders/sh_region_fill_border/sh_region_fill_border.vsh @@ -0,0 +1,19 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() +{ + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_region_fill_border/sh_region_fill_border.yy b/shaders/sh_region_fill_border/sh_region_fill_border.yy new file mode 100644 index 000000000..cf519cb5b --- /dev/null +++ b/shaders/sh_region_fill_border/sh_region_fill_border.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_region_fill_border", + "parent": { + "name": "region", + "path": "folders/shader/generator/region.yy", + }, + "type": 1, +} \ No newline at end of file diff --git a/shaders/sh_region_fill_coordinate/sh_region_fill_coordinate.fsh b/shaders/sh_region_fill_coordinate/sh_region_fill_coordinate.fsh index 0cf3d6f13..5912e7c89 100644 --- a/shaders/sh_region_fill_coordinate/sh_region_fill_coordinate.fsh +++ b/shaders/sh_region_fill_coordinate/sh_region_fill_coordinate.fsh @@ -19,11 +19,7 @@ vec4 less ( vec4 a, vec4 b ) { } vec4 sample ( vec2 position ) { - if(position.x < 0.) return vec4(1.); - if(position.y < 0.) return vec4(1.); - if(position.x > 1.) return vec4(1.); - if(position.y > 1.) return vec4(1.); - + if(position.x < 0. || position.y < 0. || position.x > 1. || position.y > 1.) return vec4(1.); return texture2D( gm_BaseTexture, position ); } @@ -33,6 +29,10 @@ void main() { gl_FragColor = c; if(c.a == 0.) return; + if(c.b == 1.) { + gl_FragColor = vec4(0.); + return; + } for( float i = 1.; i < ITERATION; i++ ) { vec4 s = sample( v_vTexcoord + vec2(tx.x * i, 0) ); diff --git a/shaders/sh_region_fill_init/sh_region_fill_init.fsh b/shaders/sh_region_fill_init/sh_region_fill_init.fsh index e3f8ae547..6c8d99a58 100644 --- a/shaders/sh_region_fill_init/sh_region_fill_init.fsh +++ b/shaders/sh_region_fill_init/sh_region_fill_init.fsh @@ -1,13 +1,13 @@ -// -// Simple passthrough fragment shader -// varying vec2 v_vTexcoord; varying vec4 v_vColour; +uniform vec4 targetColor; + void main() { - vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); - vec3 _c = c.rgb * c.a; - float _f = _c.r + _c.g + _c.b; + vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); - gl_FragColor = _f == 0.? vec4(0.) : vec4(v_vTexcoord, 0., 1.); + if(targetColor.a == 0.) + gl_FragColor = c.a == 0.? vec4(v_vTexcoord, 0., 1.) : vec4(0.); + else + gl_FragColor = targetColor == c? vec4(v_vTexcoord, 0., 1.) : vec4(0.); } diff --git a/shaders/sh_region_fill_inner/sh_region_fill_inner.fsh b/shaders/sh_region_fill_inner/sh_region_fill_inner.fsh new file mode 100644 index 000000000..38ddebce8 --- /dev/null +++ b/shaders/sh_region_fill_inner/sh_region_fill_inner.fsh @@ -0,0 +1,58 @@ +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +#define ITERATION 8. + +uniform vec2 dimension; + +vec4 sample ( vec2 position ) { + if(position.x < 0. || position.y < 0. || position.x > 1. || position.y > 1.) return vec4(1., 1., 1., 1.); + return texture2D( gm_BaseTexture, position ); +} + +void main() { + vec2 tx = 1. / dimension; + gl_FragColor = texture2D( gm_BaseTexture, v_vTexcoord ); + + if(gl_FragColor.b == 1.) return; + + for( float i = 1.; i < ITERATION; i++ ) { + vec4 s = sample( v_vTexcoord + vec2(tx.x * i, 0) ); + + if(s.a == 0.) break; + if(s.b == 0.) continue; + + gl_FragColor.b = 1.; + return; + } + + for( float i = 1.; i < ITERATION; i++ ) { + vec4 s = sample( v_vTexcoord - vec2(tx.x * i, 0) ); + + if(s.a == 0.) break; + if(s.b == 0.) continue; + + gl_FragColor.b = 1.; + return; + } + + for( float i = 1.; i < ITERATION; i++ ) { + vec4 s = sample( v_vTexcoord + vec2(0, tx.y * i) ); + + if(s.a == 0.) break; + if(s.b == 0.) continue; + + gl_FragColor.b = 1.; + return; + } + + for( float i = 1.; i < ITERATION; i++ ) { + vec4 s = sample( v_vTexcoord - vec2(0, tx.y * i) ); + + if(s.a == 0.) break; + if(s.b == 0.) continue; + + gl_FragColor.b = 1.; + return; + } +} diff --git a/shaders/sh_region_fill_inner/sh_region_fill_inner.vsh b/shaders/sh_region_fill_inner/sh_region_fill_inner.vsh new file mode 100644 index 000000000..3900c20f4 --- /dev/null +++ b/shaders/sh_region_fill_inner/sh_region_fill_inner.vsh @@ -0,0 +1,19 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() +{ + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_region_fill_inner/sh_region_fill_inner.yy b/shaders/sh_region_fill_inner/sh_region_fill_inner.yy new file mode 100644 index 000000000..d6b7dd57b --- /dev/null +++ b/shaders/sh_region_fill_inner/sh_region_fill_inner.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_region_fill_inner", + "parent": { + "name": "region", + "path": "folders/shader/generator/region.yy", + }, + "type": 1, +} \ No newline at end of file diff --git a/shaders/sh_region_fill_map/sh_region_fill_map.fsh b/shaders/sh_region_fill_map/sh_region_fill_map.fsh new file mode 100644 index 000000000..d11690035 --- /dev/null +++ b/shaders/sh_region_fill_map/sh_region_fill_map.fsh @@ -0,0 +1,13 @@ +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +uniform sampler2D colorMap; + +void main() { + vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); + gl_FragColor = c; + + if(c.rgb == vec3(0.)) return; + + gl_FragColor = texture2D( colorMap, c.xy ); +} diff --git a/shaders/sh_region_fill_map/sh_region_fill_map.vsh b/shaders/sh_region_fill_map/sh_region_fill_map.vsh new file mode 100644 index 000000000..3900c20f4 --- /dev/null +++ b/shaders/sh_region_fill_map/sh_region_fill_map.vsh @@ -0,0 +1,19 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() +{ + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_region_fill_map/sh_region_fill_map.yy b/shaders/sh_region_fill_map/sh_region_fill_map.yy new file mode 100644 index 000000000..4c38a9ab8 --- /dev/null +++ b/shaders/sh_region_fill_map/sh_region_fill_map.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_region_fill_map", + "parent": { + "name": "region", + "path": "folders/shader/generator/region.yy", + }, + "type": 1, +} \ No newline at end of file