From bb2bbd2fb44125e5f3ea8c753041cf5771b0d330 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Tue, 21 Nov 2023 17:54:45 +0700 Subject: [PATCH] 3D shadow mapping fix and several other things. --- objects/o_dialog_add_node/Create_0.gml | 17 +++- objects/o_dialog_textbox_slider/Draw_64.gml | 5 +- objects/o_main/Other_2.gml | 2 + scripts/BBMOD_Quaternion/BBMOD_Quaternion.gml | 12 +-- scripts/color_function/color_function.gml | 41 +++++---- .../d3d_camera_object/d3d_camera_object.gml | 4 +- scripts/d3d_scene/d3d_scene.gml | 12 ++- scripts/node_3d_camera/node_3d_camera.gml | 3 +- .../node_3d_light_directional.gml | 27 +++++- .../node_3d_light_point.gml | 9 +- scripts/node_cache_base/node_cache_base.gml | 2 + scripts/node_camera/node_camera.gml | 21 +++-- scripts/node_data/node_data.gml | 13 ++- scripts/node_export/node_export.gml | 4 + .../node_palette_extract.gml | 86 +++++++++++-------- scripts/shader_functions/shader_functions.gml | 2 + .../string_hexadecimal/string_hexadecimal.gml | 2 +- .../surface_functions/surface_functions.gml | 5 +- scripts/textBox/textBox.gml | 9 ++ shaders/sh_d3d_default/sh_d3d_default.fsh | 33 ++++--- 20 files changed, 199 insertions(+), 110 deletions(-) diff --git a/objects/o_dialog_add_node/Create_0.gml b/objects/o_dialog_add_node/Create_0.gml index bcef1a981..42dcdfefa 100644 --- a/objects/o_dialog_add_node/Create_0.gml +++ b/objects/o_dialog_add_node/Create_0.gml @@ -296,8 +296,21 @@ event_inherited(); } BLEND_NORMAL + var cc = COLORS._main_text_inner; + + switch(name) { + case "All" : + case "New" : + case "Favourites" : + case "Action" : + case "Custom" : + case "Extra" : + cc = COLORS._main_text_sub; + break; + } + if(i == ADD_NODE_PAGE) draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_text_accent); - else draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner); + else draw_set_text(f_p0, fa_left, fa_center, cc); var _is_extra = name == "Extra"; name = __txt(name); @@ -314,7 +327,7 @@ event_inherited(); draw_sprite_ext(s_patreon_supporter, 0, _cx, _cy, 1, 1, 0, _hov? COLORS._main_icon_dark : COLORS.panel_bg_clear, 1); gpu_set_colorwriteenable(1, 1, 1, 1); - draw_sprite_ext(s_patreon_supporter, 1, _cx, _cy, 1, 1, 0, i == ADD_NODE_PAGE? COLORS._main_text_accent : COLORS._main_text_inner, 1); + draw_sprite_ext(s_patreon_supporter, 1, _cx, _cy, 1, 1, 0, i == ADD_NODE_PAGE? COLORS._main_text_accent : cc, 1); } hh += hg; diff --git a/objects/o_dialog_textbox_slider/Draw_64.gml b/objects/o_dialog_textbox_slider/Draw_64.gml index 5df554ab6..3a5ffcf30 100644 --- a/objects/o_dialog_textbox_slider/Draw_64.gml +++ b/objects/o_dialog_textbox_slider/Draw_64.gml @@ -22,8 +22,9 @@ if(!MOUSE_WRAPPING) { var _ady = slide_dy - mouse_my; var _s = tb.slide_speed; - if(key_mod_press(CTRL)) _s *= 10; - if(key_mod_press(ALT)) _s /= 10; + var sc = 10; + if(key_mod_press(CTRL)) _s *= sc; + if(key_mod_press(ALT)) _s /= sc; var spd = (slide_da? _ady : _adx) * _s; var _val = value_snap(tb.slide_sv + spd, _s); diff --git a/objects/o_main/Other_2.gml b/objects/o_main/Other_2.gml index 152261acb..f67289de1 100644 --- a/objects/o_main/Other_2.gml +++ b/objects/o_main/Other_2.gml @@ -46,6 +46,8 @@ METADATA = __getdefaultMetaData(); APP_LOCATION = program_directory; + if(string_pos("GameMakerStudio2\\Cache\\runtimes", APP_LOCATION)) + APP_LOCATION = working_directory; //print($"===================== WORKING DIRECTORIES =====================\n\t{working_directory}\n\t{DIRECTORY}"); #endregion diff --git a/scripts/BBMOD_Quaternion/BBMOD_Quaternion.gml b/scripts/BBMOD_Quaternion/BBMOD_Quaternion.gml index 0d1deb3dc..83c92645b 100644 --- a/scripts/BBMOD_Quaternion/BBMOD_Quaternion.gml +++ b/scripts/BBMOD_Quaternion/BBMOD_Quaternion.gml @@ -246,8 +246,7 @@ function BBMOD_Quaternion(_x=0.0, _y=0.0, _z=0.0, _w=1.0) constructor _forward = new BBMOD_Vec3(_forward); _up = new BBMOD_Vec3(_up); - if (!_forward.Orthonormalize(_up)) - { + if (!_forward.Orthonormalize(_up)) { X = 0.0; Y = 0.0; Z = 0.0; @@ -257,8 +256,8 @@ function BBMOD_Quaternion(_x=0.0, _y=0.0, _z=0.0, _w=1.0) constructor var _right = _up.Cross(_forward); var _w = sqrt(abs(1.0 + _right.X + _up.Y + _forward.Z)) * 0.5; - var _w4Recip = 1.0 / (4.0 * _w); - + var _w4Recip = _w == 0? 0 : 1.0 / (4.0 * _w); + X = (_up.Z - _forward.Y) * _w4Recip; Y = (_forward.X - _right.Z) * _w4Recip; Z = (_right.Y - _up.X) * _w4Recip; @@ -309,7 +308,7 @@ function BBMOD_Quaternion(_x=0.0, _y=0.0, _z=0.0, _w=1.0) constructor /// @return {Struct.BBMOD_Quaternion} The created quaternion. static Inverse = function () { INLINE - return Conjugate().Scale(1.0 / Length()); + return Length() == 0? new BBMOD_Quaternion() : Conjugate().Scale(1.0 / Length()); }; /// @func Length() @@ -412,6 +411,7 @@ function BBMOD_Quaternion(_x=0.0, _y=0.0, _z=0.0, _w=1.0) constructor static Normalize = function () { INLINE var _lengthSqr = LengthSqr(); + if(_lengthSqr == 0) return new BBMOD_Quaternion(); @@ -628,6 +628,8 @@ function BBMOD_Quaternion(_x=0.0, _y=0.0, _z=0.0, _w=1.0) constructor _dest ??= matrix_build_identity(); + if(is_nan(X)) return _dest; + var _norm = Normalize(); var _temp0, _temp1, _temp2; diff --git a/scripts/color_function/color_function.gml b/scripts/color_function/color_function.gml index c3cfbaabb..52ed5f8ab 100644 --- a/scripts/color_function/color_function.gml +++ b/scripts/color_function/color_function.gml @@ -1,26 +1,29 @@ -function colorFromRGBArray(arr) { +function colorFromRGBArray(arr) { #region var r = round(real(arr[0]) * 255); var g = round(real(arr[1]) * 255); var b = round(real(arr[2]) * 255); return make_color_rgb(r, g, b); -} +} #endregion -function color_get_alpha(color) { +function color_get_alpha(color) { #region + INLINE return (color & (0xFF << 24)) >> 24; -} +} #endregion -function colorArrayFromReal(clr) { +function colorArrayFromReal(clr) { #region + INLINE return [color_get_red(clr) / 255, color_get_green(clr) / 255, color_get_blue(clr) / 255 ]; -} +} #endregion -function colorBrightness(clr, normalize = true) { +function colorBrightness(clr, normalize = true) { #region + INLINE var r2 = color_get_red(clr) / (normalize? 255 : 1); var g2 = color_get_green(clr) / (normalize? 255 : 1); var b2 = color_get_blue(clr) / (normalize? 255 : 1); return 0.299 * r2 + 0.587 * g2 + 0.224 * b2; -} +} #endregion -function colorMultiply(c1, c2) { +function colorMultiply(c1, c2) { #region if(c1 * c2 == 0) return 0; if(c1 == c_white) return c2; if(c2 == c_white) return c1; @@ -34,9 +37,9 @@ function colorMultiply(c1, c2) { var b2 = color_get_blue(c2); return make_color_rgb((r1 * r2) / 255, (g1 * g2) / 255, (b1 * b2) / 255); -} +} #endregion -function colorAdd(c1, c2) { +function colorAdd(c1, c2) { #region if(c1 == 0) return c2; if(c2 == 0) return c1; @@ -49,9 +52,9 @@ function colorAdd(c1, c2) { var b2 = color_get_blue(c2); return make_color_rgb(min(r1 + r2, 255), min(g1 + g2, 255), min(b1 + b2, 255)); -} +} #endregion -function color_diff(c1, c2, fast = false, alpha = false) { +function color_diff(c1, c2, fast = false, alpha = false) { #region var _c1_r = color_get_red(c1); var _c1_g = color_get_green(c1); var _c1_b = color_get_blue(c1); @@ -74,13 +77,17 @@ function color_diff(c1, c2, fast = false, alpha = false) { if(fast) return abs(_c1_r - _c2_r) + abs(_c1_g - _c2_g) + abs(_c1_b - _c2_b) + abs(_c1_a - _c2_a); return sqrt(sqr(_c1_r - _c2_r) + sqr(_c1_g - _c2_g) + sqr(_c1_b - _c2_b) + sqr(_c1_a - _c2_a)); -} +} #endregion -function color_get_brightness(col) { +function color_get_brightness(col) { #region INLINE - return (0.299 * color_get_red(col) + 0.587 * color_get_green(col) + 0.114 * color_get_blue(col)) / 255; -} +} #endregion + +function color_rgb(col) { #region + INLINE + return [ color_get_red(col) / 255, color_get_green(col) / 255, color_get_blue(col) / 255 ]; +} #endregion #region sorting functions function __valHSV(c, h, s, v) { return color_get_hue(c) * h + color_get_saturation(c) * s + color_get_value(c) * v; } diff --git a/scripts/d3d_camera_object/d3d_camera_object.gml b/scripts/d3d_camera_object/d3d_camera_object.gml index 3d0efecd2..022120999 100644 --- a/scripts/d3d_camera_object/d3d_camera_object.gml +++ b/scripts/d3d_camera_object/d3d_camera_object.gml @@ -45,7 +45,9 @@ function __3dCamera_object() : __3dObject() constructor { function d3d_PolarToCart(camFx, camFy, camFz, camAx, camAy, camDist) { var pos = new __vec3(); - if(camAy % 90 == 0) camAy += 0.01; + if(camAy % 90 == 0) camAy += 0.1; + if(camAx % 90 == 0) camAx += 0.1; + var radAx = degtorad(camAx); var radAy = degtorad(camAy); diff --git a/scripts/d3d_scene/d3d_scene.gml b/scripts/d3d_scene/d3d_scene.gml index d879cc356..f822de4c9 100644 --- a/scripts/d3d_scene/d3d_scene.gml +++ b/scripts/d3d_scene/d3d_scene.gml @@ -216,8 +216,10 @@ function __3dScene(camera, name = "New scene") constructor { shader_set_f("light_dir_color", lightDir_color); shader_set_f("light_dir_intensity", lightDir_intensity); shader_set_i("light_dir_shadow_active", lightDir_shadow); - for( var i = 0, n = array_length(lightDir_shadowMap); i < n; i++ ) - shader_set_surface($"light_dir_shadowmap_{i}", lightDir_shadowMap[i], true); + for( var i = 0, n = array_length(lightDir_shadowMap); i < n; i++ ) { + var _sid = shader_set_surface($"light_dir_shadowmap_{i}", lightDir_shadowMap[i], true); + gpu_set_tex_repeat_ext(_sid, false); + } shader_set_f("light_dir_view", lightDir_viewMat); shader_set_f("light_dir_proj", lightDir_projMat); shader_set_f("light_dir_shadow_bias", lightDir_shadowBias); @@ -230,8 +232,10 @@ function __3dScene(camera, name = "New scene") constructor { shader_set_f("light_pnt_intensity", lightPnt_intensity); shader_set_f("light_pnt_radius", lightPnt_radius); shader_set_i("light_pnt_shadow_active", lightPnt_shadow); - for( var i = 0, n = array_length(lightPnt_shadowMap); i < n; i++ ) - shader_set_surface($"light_pnt_shadowmap_{i}", lightPnt_shadowMap[i], true, true); + for( var i = 0, n = array_length(lightPnt_shadowMap); i < n; i++ ) { + var _sid = shader_set_surface($"light_pnt_shadowmap_{i}", lightPnt_shadowMap[i], true, true); + gpu_set_tex_repeat_ext(_sid, false); + } shader_set_f("light_pnt_view", lightPnt_viewMat); shader_set_f("light_pnt_proj", lightPnt_projMat); shader_set_f("light_pnt_shadow_bias", lightPnt_shadowBias); diff --git a/scripts/node_3d_camera/node_3d_camera.gml b/scripts/node_3d_camera/node_3d_camera.gml index ddd39494d..4e0bb9941 100644 --- a/scripts/node_3d_camera/node_3d_camera.gml +++ b/scripts/node_3d_camera/node_3d_camera.gml @@ -261,8 +261,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) camera.up = camera.getUp()._multiply(-1); var _for = camera.focus.subtract(camera.position); - if(!_for.isZero()) - camera.rotation = new BBMOD_Quaternion().FromLookRotation(_for, camera.up.multiply(-1)).Mul(_qi1).Mul(_qi3); + if(!_for.isZero()) camera.rotation = new BBMOD_Quaternion().FromLookRotation(_for, camera.up.multiply(-1)).Mul(_qi1).Mul(_qi3); lookat.transform.position.set(_look); lookLine = new __3dGizmoLineDashed(camera.position, camera.focus, 0.25, c_gray, 1); diff --git a/scripts/node_3d_light_directional/node_3d_light_directional.gml b/scripts/node_3d_light_directional/node_3d_light_directional.gml index 0461bb378..76cda6117 100644 --- a/scripts/node_3d_light_directional/node_3d_light_directional.gml +++ b/scripts/node_3d_light_directional/node_3d_light_directional.gml @@ -21,7 +21,30 @@ function Node_3D_Light_Directional(_x, _y, _group = noone) : Node_3D_Light(_x, _ tool_settings = []; tool_attribute.context = 1; - static processData = function(_output, _data, _output_index, _array_index = 0) { + //static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) { #region + // var object = getObject(0); + // var _outSurf = object.shadow_map; + + // if(!is_surface(_outSurf)) return; + + // var _w = _panel.w; + // var _h = _panel.h - _panel.toolbar_height; + // var _pw = surface_get_width_safe(_outSurf); + // var _ph = surface_get_height_safe(_outSurf); + // var _ps = min(128 / _ph, 160 / _pw); + + // var _pws = _pw * _ps; + // var _phs = _ph * _ps; + + // var _px = _w - 16 - _pws; + // var _py = _h - 16 - _phs; + + // draw_surface_ext_safe(_outSurf, _px, _py, _ps, _ps); + // draw_set_color(COLORS._main_icon); + // draw_rectangle(_px, _py, _px + _pws, _py + _phs, true); + //} #endregion + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region var _active = _data[in_d3d + 0]; if(!_active) return noone; @@ -41,5 +64,5 @@ function Node_3D_Light_Directional(_x, _y, _group = noone) : Node_3D_Light(_x, _ object.transform.rotation.FromEuler(_rot.x, _rot.y, _rot.z); return object; - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_3d_light_point/node_3d_light_point.gml b/scripts/node_3d_light_point/node_3d_light_point.gml index c000b15e1..b45a22d5c 100644 --- a/scripts/node_3d_light_point/node_3d_light_point.gml +++ b/scripts/node_3d_light_point/node_3d_light_point.gml @@ -21,7 +21,7 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr tool_settings = []; tool_attribute.context = 1; - static processData = function(_output, _data, _output_index, _array_index = 0) { + static processData = function(_output, _data, _output_index, _array_index = 0) { #region var _active = _data[in_d3d + 0]; if(!_active) return noone; @@ -39,10 +39,5 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr object.shadow_bias = _shadow_bias; return object; - } - - //static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - // var object = getObject(0); - // draw_surface_stretched_safe(object.shadow_map, xx, yy, 96, 96); - //} + } #endregion } \ No newline at end of file diff --git a/scripts/node_cache_base/node_cache_base.gml b/scripts/node_cache_base/node_cache_base.gml index 00c0dc1f3..a81810b2c 100644 --- a/scripts/node_cache_base/node_cache_base.gml +++ b/scripts/node_cache_base/node_cache_base.gml @@ -244,4 +244,6 @@ function __Node_Cache(_x, _y, _group = noone) : Node(_x, _y, _group) constructor draw_set_alpha(1); } #endregion + + static onDestroy = function() { enableNodeGroup(); } } \ No newline at end of file diff --git a/scripts/node_camera/node_camera.gml b/scripts/node_camera/node_camera.gml index 734acc6ab..ca861768e 100644 --- a/scripts/node_camera/node_camera.gml +++ b/scripts/node_camera/node_camera.gml @@ -38,7 +38,7 @@ function Node_Camera(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co temp_surface = [ noone, noone ]; - static createNewInput = function() { + static createNewInput = function() { #region var index = ds_list_size(inputs); var _s = floor((index - input_fix_len) / data_length); @@ -52,10 +52,9 @@ function Node_Camera(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Empty", "Repeat", "Repeat X", "Repeat Y" ]); array_append(input_display_list, [ index + 0, index + 1, index + 2 ]); - } - if(!LOADING && !APPENDING) createNewInput(); + } if(!LOADING && !APPENDING) createNewInput(); #endregion - static refreshDynamicInput = function() { + static refreshDynamicInput = function() { #region var _in = ds_list_create(); for( var i = 0; i < input_fix_len; i++ ) @@ -86,18 +85,18 @@ function Node_Camera(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co inputs = _in; createNewInput(); - } + } #endregion - static onValueFromUpdate = function(index) { + static onValueFromUpdate = function(index) { #region if(index < input_fix_len) return; if(LOADING || APPENDING) return; refreshDynamicInput(); - } + } #endregion static getPreviewValues = function() { return getInputData(0); } - static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { + static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { #region if(array_length(current_data) == 0) return; var _out = outputs[| 0].getValue(); @@ -117,9 +116,9 @@ function Node_Camera(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co var y1 = y0 + _area[3] * 2 * _zoom * _s; draw_rectangle_dashed(x0, y0, x1, y1); - } + } #endregion - static processData = function(_outSurf, _data, _output_index, _array_index) { + static processData = function(_outSurf, _data, _output_index, _array_index) { #region if(!is_surface(_data[0])) return; var _area = _data[1]; var _zoom = _data[2]; @@ -223,5 +222,5 @@ function Node_Camera(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co surface_reset_target(); return _outSurf; - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index 7403b7680..90089f7f6 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -595,19 +595,28 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x LOG_BLOCK_END(); } #endregion + static cacheCheck = function() { #region + INLINE + + if(cache_group) cache_group.enableNodeGroup(); + if(group != noone) group.cacheCheck(); + } #endregion + static valueUpdate = function(index) { #region if(error_update_enabled && error_noti_update == noone) error_noti_update = noti_error(getFullName() + " node require manual execution.",, self); onValueUpdate(index); - if(cache_group) cache_group.enableNodeGroup(); + if(is_dynamic_input) will_setHeight = true; + cacheCheck(); } #endregion static valueFromUpdate = function(index) { #region onValueFromUpdate(index); - if(cache_group) cache_group.enableNodeGroup(); + if(is_dynamic_input) will_setHeight = true; + cacheCheck(); } #endregion static onValueUpdate = function(index = 0) {} diff --git a/scripts/node_export/node_export.gml b/scripts/node_export/node_export.gml index 69222caba..1d4715e6f 100644 --- a/scripts/node_export/node_export.gml +++ b/scripts/node_export/node_export.gml @@ -741,6 +741,7 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor if(render_process_id != 0) { var res = ProcIdExists(render_process_id); + if(res == 0) { var noti = log_message("EXPORT", $"Export {render_type} as {render_target}", THEME.noti_icon_tick, COLORS._main_value_positive, false); noti.path = filename_dir(render_target); @@ -749,6 +750,9 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor render_process_id = 0; array_remove(RENDERING, node_id); + } else { + //var stdOut = ExecutedProcessReadFromStandardOutput(render_process_id); + //print(stdOut); } } } #endregion diff --git a/scripts/node_palette_extract/node_palette_extract.gml b/scripts/node_palette_extract/node_palette_extract.gml index 0ba8157a0..8a18cb319 100644 --- a/scripts/node_palette_extract/node_palette_extract.gml +++ b/scripts/node_palette_extract/node_palette_extract.gml @@ -14,6 +14,10 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con .setDisplay(VALUE_DISPLAY.enum_scroll, { data: [ "K-mean", "Frequency", "All colors" ], update_hover: false }) .rejectArray(); + inputs[| 4] = nodeValue("Color Space", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1) + .setDisplay(VALUE_DISPLAY.enum_scroll, { data: [ "RGB", "HSV" ], update_hover: false }) + .rejectArray(); + outputs[| 0] = nodeValue("Palette", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, [ ]) .setDisplay(VALUE_DISPLAY.palette); @@ -21,7 +25,7 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con input_display_list = [ ["Surfaces", true], 0, - ["Palette", false], 3, 1, 2, + ["Palette", false], 3, 4, 1, 2, ] current_palette = []; @@ -29,7 +33,7 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con attribute_surface_depth(); - function sortPalette(pal) { + function sortPalette(pal) { #region array_sort(pal, function(c0, c1) { var r0 = color_get_red(c0) / 255; var r1 = color_get_red(c1) / 255; @@ -56,23 +60,19 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con return s0 * v0 > s1 * v1; }) - } + } #endregion - function extractKmean(_surfFull, _size, _seed) { - var _surf = surface_create_valid(min(32, surface_get_width_safe(_surfFull)), min(32, surface_get_height_safe(_surfFull)), attrDepth()); + function extractKmean(_surfFull, _size, _seed) { #region + var _space = getInputData(4); + var _surf = surface_create_valid(min(32, surface_get_width_safe(_surfFull)), min(32, surface_get_height_safe(_surfFull)), attrDepth()); _size = max(1, _size); var ww = surface_get_width_safe(_surf); var hh = surface_get_height_safe(_surf); - surface_set_target(_surf); - DRAW_CLEAR - BLEND_OVERRIDE; - gpu_set_texfilter(true); - draw_surface_stretched_safe(_surfFull, 0, 0, ww, hh); - gpu_set_texfilter(false); - BLEND_NORMAL; - surface_reset_target(); + surface_set_shader(_surf, noone); + draw_surface_stretched_safe(_surfFull, 0, 0, ww, hh); + surface_reset_shader(); var c_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2); var colors = []; @@ -82,14 +82,20 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con var _min = [ 1, 1, 1 ]; var _max = [ 0, 0, 0 ]; + var a, b, c, col; for( var i = 0; i < ww * hh; i++ ) { - var b = buffer_read(c_buffer, buffer_u32); - var c = b & ~(0b11111111 << 24); - var a = b & (0b11111111 << 24); + b = buffer_read(c_buffer, buffer_u32); + c = b & ~(0b11111111 << 24); + a = b & (0b11111111 << 24); if(a == 0) continue; - var col = [ color_get_hue(c) / 255, color_get_saturation(c) / 255, color_get_value(c) / 255, 0 ]; + switch(_space) { + case 0 : col = [ color_get_red(c) / 255, color_get_green(c) / 255, color_get_blue(c) / 255, 0 ]; break; + case 1 : col = [ color_get_hue(c) / 255, color_get_saturation(c) / 255, color_get_value(c) / 255, 0 ]; break; + case 2 : col = [ color_get_hue(c) / 255, color_get_saturation(c) / 255, color_get_value(c) / 255, 0 ]; break; + } + array_push(colors, col); for( var j = 0; j < 3; j++ ) { _min[j] = min(_min[j], col[j]); @@ -155,6 +161,7 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con } var palette = []; + var clr; for( var i = 0; i < _size; i++ ) { var closet = 0; @@ -171,18 +178,22 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con } } - var clr = make_color_hsv(colors[closet][0] * 255, colors[closet][1] * 255, colors[closet][2] * 255); - if(!array_exists(palette, clr)) - array_push(palette, clr); + switch(_space) { + case 0 : clr = make_color_rgb(colors[closet][0] * 255, colors[closet][1] * 255, colors[closet][2] * 255); break; + case 1 : clr = make_color_hsv(colors[closet][0] * 255, colors[closet][1] * 255, colors[closet][2] * 255); break; + case 2 : clr = make_color_hsv(colors[closet][0] * 255, colors[closet][1] * 255, colors[closet][2] * 255); break; + } + + array_push_unique(palette, clr); } surface_free(_surf); sortPalette(palette); return palette; - } + } #endregion - function extractAll(_surfFull) { + function extractAll(_surfFull) { #region var ww = surface_get_width_safe(_surfFull); var hh = surface_get_height_safe(_surfFull); @@ -205,9 +216,9 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con buffer_delete(c_buffer); return palette; - } + } #endregion - function extractFrequence(_surfFull, _size) { + function extractFrequence(_surfFull, _size) { #region var msize = 128; var _surf = surface_create_valid(min(msize, surface_get_width_safe(_surfFull)), min(msize, surface_get_height_safe(_surfFull))); _size = max(1, _size); @@ -262,16 +273,17 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con ds_priority_destroy(pr); ds_map_destroy(clrs); return palette; - } + } #endregion - static step = function() { + static step = function() { #region var _algo = getInputData(3); inputs[| 1].setVisible(_algo != 2); inputs[| 2].setVisible(_algo == 0); - } + inputs[| 4].setVisible(_algo == 0); + } #endregion - static extractPalette = function(_surf, _algo, _size, _seed) { + static extractPalette = function(_surf, _algo, _size, _seed) { #region if(!is_surface(_surf)) return []; switch(_algo) { @@ -281,9 +293,9 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con } return []; - } + } #endregion - static extractPalettes = function() { + static extractPalettes = function() { #region var _surf = getInputData(0); var _size = getInputData(1); var _seed = getInputData(2); @@ -299,20 +311,18 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node(_x, _y, _group) con } outputs[| 0].setValue(res); - } + } #endregion static onInspector1Update = function() { extractPalettes(); triggerRender(); } - static onValueUpdate = function() { extractPalettes(); } - static onValueFromUpdate = function() { extractPalettes(); } + static onValueUpdate = function() { extractPalettes(); } + static onValueFromUpdate = function() { extractPalettes(); } - static update = function() { - extractPalettes(); - } + static update = function() { extractPalettes(); } - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region var bbox = drawGetBbox(xx, yy, _s); if(bbox.h < 1) return; drawPalette(outputs[| 0].getValue(), bbox.x0, bbox.y0, bbox.w, bbox.h); - } + } #endregion } \ No newline at end of file diff --git a/scripts/shader_functions/shader_functions.gml b/scripts/shader_functions/shader_functions.gml index 04263ff39..8063c7850 100644 --- a/scripts/shader_functions/shader_functions.gml +++ b/scripts/shader_functions/shader_functions.gml @@ -92,6 +92,8 @@ function shader_set_surface(sampler, surface, linear = false, _repeat = false) { texture_set_stage(t, surface_get_texture(surface)); gpu_set_tex_filter_ext(t, linear); gpu_set_tex_repeat_ext(t, _repeat); + + return t; } //function shader_set_surface_ext(sampler, surface, linear = false, _repeat = false) { diff --git a/scripts/string_hexadecimal/string_hexadecimal.gml b/scripts/string_hexadecimal/string_hexadecimal.gml index 188ac5f18..e5cfdd825 100644 --- a/scripts/string_hexadecimal/string_hexadecimal.gml +++ b/scripts/string_hexadecimal/string_hexadecimal.gml @@ -1,4 +1,4 @@ -function string_hexadecimal(str){ +function string_hexadecimal(str) { static HEX = "0123456789ABCDEF"; var i = string_length(str); diff --git a/scripts/surface_functions/surface_functions.gml b/scripts/surface_functions/surface_functions.gml index 33422e9ec..d331c73a7 100644 --- a/scripts/surface_functions/surface_functions.gml +++ b/scripts/surface_functions/surface_functions.gml @@ -307,8 +307,9 @@ function surface_size_lim(surface, width, height) { } function surface_size_to(surface, width, height, format = noone, skipCheck = false) { - if(!skipCheck && !is_surface(surface)) return surface; - if(width < 1 && height < 1) return surface; + 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); diff --git a/scripts/textBox/textBox.gml b/scripts/textBox/textBox.gml index 26d2399de..96d55ed54 100644 --- a/scripts/textBox/textBox.gml +++ b/scripts/textBox/textBox.gml @@ -223,7 +223,16 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor { if(keyboard_check_pressed(vk_left)) onKey(vk_left); if(keyboard_check_pressed(vk_right)) onKey(vk_right); + + if(input == TEXTBOX_INPUT.number) { + var _inc = 1; + if(key_mod_press(CTRL)) _inc *= 10; + if(key_mod_press(ALT)) _inc /= 10; + if(KEYBOARD_PRESSED == vk_up || keyboard_check_pressed(vk_up)) { _input_text = string(toNumber(_input_text) + _inc); apply(); } + if(KEYBOARD_PRESSED == vk_down || keyboard_check_pressed(vk_down)) { _input_text = string(toNumber(_input_text) - _inc); apply(); } + } + if(keyboard_check_pressed(vk_home)) { if(key_mod_press(SHIFT)) { if(cursor_select == -1) diff --git a/shaders/sh_d3d_default/sh_d3d_default.fsh b/shaders/sh_d3d_default/sh_d3d_default.fsh index f5e328659..ec3ba1af4 100644 --- a/shaders/sh_d3d_default/sh_d3d_default.fsh +++ b/shaders/sh_d3d_default/sh_d3d_default.fsh @@ -220,15 +220,18 @@ void main() { float v_lightDistance = screenSpace.z / screenSpace.w; vec2 lightMapPosition = (screenSpace.xy / screenSpace.w * 0.5) + 0.5; - - light_map_depth = sampleDirShadowMap(shadow_map_index, lightMapPosition); - shadow_map_index++; - lightDistance = v_lightDistance; - float shadowFactor = dot(normal, lightVector); - float bias = mix(light_dir_shadow_bias[i], 0., shadowFactor); - if(lightDistance > light_map_depth + bias) - continue; + if(lightMapPosition.x >= 0. && lightMapPosition.x <= 1. && lightMapPosition.y >= 0. && lightMapPosition.y <= 1.) { + light_map_depth = sampleDirShadowMap(shadow_map_index, lightMapPosition); + + shadow_map_index++; + lightDistance = v_lightDistance; + float shadowFactor = dot(normal, lightVector); + float bias = mix(light_dir_shadow_bias[i], 0., shadowFactor); + + if(lightDistance > light_map_depth + bias) + continue; + } } vec3 light_phong = phongLight(normal, lightVector, viewDirection, light_dir_color[i].rgb); @@ -264,14 +267,16 @@ void main() { float v_lightDistance = screenSpace.z / screenSpace.w; vec2 lightMapPosition = (screenSpace.xy / screenSpace.w * 0.5) + 0.5; - float shadowFactor = dot(normal, lightVector); - float bias = mix(light_pnt_shadow_bias[i], 0., shadowFactor); + if(lightMapPosition.x >= 0. && lightMapPosition.x <= 1. && lightMapPosition.y >= 0. && lightMapPosition.y <= 1.) { + float shadowFactor = dot(normal, lightVector); + float bias = mix(light_pnt_shadow_bias[i], 0., shadowFactor); - light_map_depth = samplePntShadowMap(shadow_map_index, lightMapPosition, side); - shadow_map_index++; + light_map_depth = samplePntShadowMap(shadow_map_index, lightMapPosition, side); + shadow_map_index++; - if(v_lightDistance > light_map_depth + bias) - continue; + if(v_lightDistance > light_map_depth + bias) + continue; + } } light_attenuation = 1. - pow(light_distance / light_pnt_radius[i], 2.);