From 46d2787b98c3ff85cae8a102ba11044ca306a45a Mon Sep 17 00:00:00 2001 From: Tanasart Date: Fri, 31 May 2024 17:51:14 +0700 Subject: [PATCH] fn math --- PixelComposer.resource_order | 4 ++ PixelComposer.yyp | 4 ++ scripts/node_fn/node_fn.gml | 24 +++++--- scripts/node_fn_constant/node_fn_constant.gml | 25 +++++++++ scripts/node_fn_constant/node_fn_constant.yy | 13 +++++ scripts/node_fn_ease/node_fn_ease.gml | 56 +++++++++++++++++++ scripts/node_fn_ease/node_fn_ease.yy | 13 +++++ scripts/node_fn_math/node_fn_math.gml | 56 +++++++++++++++++++ scripts/node_fn_math/node_fn_math.yy | 13 +++++ .../node_fn_smoothstep/node_fn_smoothstep.gml | 46 +++++++++++++++ .../node_fn_smoothstep/node_fn_smoothstep.yy | 13 +++++ scripts/node_registry/node_registry.gml | 9 ++- 12 files changed, 265 insertions(+), 11 deletions(-) create mode 100644 scripts/node_fn_constant/node_fn_constant.gml create mode 100644 scripts/node_fn_constant/node_fn_constant.yy create mode 100644 scripts/node_fn_ease/node_fn_ease.gml create mode 100644 scripts/node_fn_ease/node_fn_ease.yy create mode 100644 scripts/node_fn_math/node_fn_math.gml create mode 100644 scripts/node_fn_math/node_fn_math.yy create mode 100644 scripts/node_fn_smoothstep/node_fn_smoothstep.gml create mode 100644 scripts/node_fn_smoothstep/node_fn_smoothstep.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 8bfcd5511..81aac6f6c 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -754,6 +754,10 @@ {"name":"node_flip","order":13,"path":"scripts/node_flip/node_flip.yy",}, {"name":"node_flood_fill","order":3,"path":"scripts/node_flood_fill/node_flood_fill.yy",}, {"name":"node_flow_noise","order":18,"path":"scripts/node_flow_noise/node_flow_noise.yy",}, + {"name":"node_fn_constant","order":3,"path":"scripts/node_fn_constant/node_fn_constant.yy",}, + {"name":"node_fn_ease","order":5,"path":"scripts/node_fn_ease/node_fn_ease.yy",}, + {"name":"node_fn_math","order":6,"path":"scripts/node_fn_math/node_fn_math.yy",}, + {"name":"node_fn_smoothstep","order":4,"path":"scripts/node_fn_smoothstep/node_fn_smoothstep.yy",}, {"name":"node_fn_wave_table","order":1,"path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",}, {"name":"node_fn","order":2,"path":"scripts/node_fn/node_fn.yy",}, {"name":"node_fold_noise","order":14,"path":"scripts/node_fold_noise/node_fold_noise.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index b47fd7c6f..eefbe556a 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -1172,6 +1172,10 @@ {"id":{"name":"node_flip","path":"scripts/node_flip/node_flip.yy",},}, {"id":{"name":"node_flood_fill","path":"scripts/node_flood_fill/node_flood_fill.yy",},}, {"id":{"name":"node_flow_noise","path":"scripts/node_flow_noise/node_flow_noise.yy",},}, + {"id":{"name":"node_fn_constant","path":"scripts/node_fn_constant/node_fn_constant.yy",},}, + {"id":{"name":"node_fn_ease","path":"scripts/node_fn_ease/node_fn_ease.yy",},}, + {"id":{"name":"node_fn_math","path":"scripts/node_fn_math/node_fn_math.yy",},}, + {"id":{"name":"node_fn_smoothstep","path":"scripts/node_fn_smoothstep/node_fn_smoothstep.yy",},}, {"id":{"name":"node_fn_wave_table","path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",},}, {"id":{"name":"node_fn_wiggler","path":"scripts/node_fn_wiggler/node_fn_wiggler.yy",},}, {"id":{"name":"node_fn","path":"scripts/node_fn/node_fn.yy",},}, diff --git a/scripts/node_fn/node_fn.gml b/scripts/node_fn/node_fn.gml index 6256c070d..573be3a7d 100644 --- a/scripts/node_fn/node_fn.gml +++ b/scripts/node_fn/node_fn.gml @@ -1,5 +1,6 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { name = "Fn"; + time_based = true; update_on_frame = true; setDimension(96, 96); @@ -15,7 +16,8 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr ]; text_display = 0; - graph_display = array_create(64, 0); + graph_res = 64; + graph_display = array_create(graph_res, 0); graph_display_min = 0; graph_display_max = 0; @@ -25,14 +27,17 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr graph_display_min = undefined; graph_display_max = undefined; - for( var i = 0; i < 64; i++ ) { - var _c = __fnEval(i / 64); + for( var i = 0; i < graph_res; i++ ) { + var _c = __fnEval(refreshDisplayX(i)); graph_display[i] = _c; graph_display_min = graph_display_min == undefined? _c : min(graph_display_min, _c); graph_display_max = graph_display_max == undefined? _c : max(graph_display_max, _c); } } + static refreshDisplayX = function(i) { return i / graph_res; } + static getDisplayX = function(i) { return graph_display[i]; } + static postPostProcess = function() { if(!IS_PLAYING) refreshDisplay(); } static processData = function(_output, _data, _output_index, _array_index = 0) { } @@ -72,10 +77,10 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr draw_set_text(f_sdf, fa_right, fa_bottom, COLORS._main_text_sub); draw_text_transformed(x1 - 2 * _s, y1, text_display, 0.3 * _s, 0.3 * _s, 0); - var lw = ww / (64 - 1); + var lw = ww / (graph_res - 1); var ox, oy; draw_set_color(c_white); - for( var i = 0; i < 64; i++ ) { + for( var i = 0; i < graph_res; i++ ) { var _x = x0 + i * lw; var _y = yc - (graph_display[i] - val) / _ran * hh; if(i) draw_line(ox, oy, _x, _y); @@ -83,9 +88,12 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr ox = _x; oy = _y; } - draw_set_color(COLORS._main_accent); - var _fx = x0 + (time / total_time * ww); - draw_line(_fx, y0, _fx, y1); + + if(time_based) { + draw_set_color(COLORS._main_accent); + var _fx = x0 + (time / total_time * ww); + draw_line(_fx, y0, _fx, y1); + } draw_set_color(COLORS.node_wiggler_frame); draw_rectangle(x0, y0, x1, y1, true); diff --git a/scripts/node_fn_constant/node_fn_constant.gml b/scripts/node_fn_constant/node_fn_constant.gml new file mode 100644 index 000000000..1e2010e45 --- /dev/null +++ b/scripts/node_fn_constant/node_fn_constant.gml @@ -0,0 +1,25 @@ +function Node_Fn_Constant(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor { + name = "Constant"; + + inputs[| inl + 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ); + + array_append(input_display_list, [ + ["Value", false], inl + 0 + ]); + + value = 0; + + static __fnEval = function(_x = 0) { + return value; + } + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + value = _data[inl + 0]; + + var val = __fnEval(CURRENT_FRAME / TOTAL_FRAMES); + text_display = val; + + return val; + } #endregion + +} \ No newline at end of file diff --git a/scripts/node_fn_constant/node_fn_constant.yy b/scripts/node_fn_constant/node_fn_constant.yy new file mode 100644 index 000000000..12cddc177 --- /dev/null +++ b/scripts/node_fn_constant/node_fn_constant.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"node_fn_constant", + "isCompatibility":false, + "isDnD":false, + "name":"node_fn_constant", + "parent":{ + "name":"fn", + "path":"folders/nodes/data/animation/fn.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/node_fn_ease/node_fn_ease.gml b/scripts/node_fn_ease/node_fn_ease.gml new file mode 100644 index 000000000..44aaedd4f --- /dev/null +++ b/scripts/node_fn_ease/node_fn_ease.gml @@ -0,0 +1,56 @@ +function Node_Fn_Ease(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor { + name = "Ease"; + + inputs[| inl + 0] = nodeValue("Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ] ) + .setDisplay(VALUE_DISPLAY.slider_range ); + + inputs[| inl + 1] = nodeValue("Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0.1, 0.9 ] ) + .setDisplay(VALUE_DISPLAY.slider_range ); + + inputs[| inl + 2] = nodeValue("Smooth", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 ) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Cubic poly", "Quadratic rat", "Cubic rat", "Cosine" ] ); + + array_append(input_display_list, [ + ["Value", false], inl + 0, inl + 1, inl + 2, + ]); + + rang = [ 0, 1 ]; + ease = [ 0, 1 ]; + type = 0; + + static __smooth = function(_x = 0) { + switch(type) { + case 0 : return _x * _x * (3.0 - 2.0 * _x); + case 1 : return _x * _x / (2.0 * _x * _x - 2.0 * _x + 1.0); + case 2 : return _x * _x * _x / (3.0 * _x * _x - 3.0 * _x + 1.0); + case 3 : return 0.5 - 0.5 * cos(pi * _x); + } + + return _x; + } + + static __fnEval = function(_x = 0) { + if(_x < rang[0] || _x > rang[1]) return 0; + + var _eo = 1 - ease[1]; + + var _v = clamp(min( + ease[0] == 0? 1 : (_x - rang[0]) / ease[0], + _eo == 0? 1 : 1 - (_x - (rang[1] - _eo)) / _eo, + ), 0, 1); + + return __smooth(_v); + } + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + rang = _data[inl + 0]; + ease = _data[inl + 1]; + type = _data[inl + 2]; + + var val = __fnEval(CURRENT_FRAME / TOTAL_FRAMES); + text_display = val; + + return val; + } #endregion + +} \ No newline at end of file diff --git a/scripts/node_fn_ease/node_fn_ease.yy b/scripts/node_fn_ease/node_fn_ease.yy new file mode 100644 index 000000000..8456ba8af --- /dev/null +++ b/scripts/node_fn_ease/node_fn_ease.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"node_fn_ease", + "isCompatibility":false, + "isDnD":false, + "name":"node_fn_ease", + "parent":{ + "name":"fn", + "path":"folders/nodes/data/animation/fn.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/node_fn_math/node_fn_math.gml b/scripts/node_fn_math/node_fn_math.gml new file mode 100644 index 000000000..70295df91 --- /dev/null +++ b/scripts/node_fn_math/node_fn_math.gml @@ -0,0 +1,56 @@ +function Node_Fn_Math(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor { + name = "Math"; + time_based = false; + + inputs[| inl + 0] = nodeValue("Operation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 ) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Add", "Minus", "Multiply" ] ); + + inputs[| inl + 1] = nodeValue("Value 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) + .setVisible(true, true); + + inputs[| inl + 2] = nodeValue("Value 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) + .setVisible(true, true); + + array_append(input_display_list, [ + ["Value", false], inl + 0, inl + 1, inl + 2, + ]); + + type = 0; + + static __fnEval = function(_x) { + switch(type) { + case 0 : return _x[0] + _x[1]; + case 1 : return _x[0] - _x[1]; + case 2 : return _x[0] * _x[1]; + } + + return 0; + } + + static refreshDisplayX = function(i) { + var _v0 = getSingleValue(inl + 1); + var _v1 = getSingleValue(inl + 2); + + var _f0 = inputs[| inl + 1].value_from; + if(_f0 != noone && is_instanceof(_f0.node, Node_Fn)) + _v0 = _f0.node.getDisplayX(i); + + var _f1 = inputs[| inl + 2].value_from; + if(_f1 != noone && is_instanceof(_f1.node, Node_Fn)) + _v1 = _f1.node.getDisplayX(i); + + return [ _v0, _v1 ]; + } + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + type = _data[inl + 0]; + var v0 = _data[inl + 1]; + var v1 = _data[inl + 2]; + + var val = __fnEval([ v0, v1 ]); + + text_display = val; + return val; + } #endregion + +} \ No newline at end of file diff --git a/scripts/node_fn_math/node_fn_math.yy b/scripts/node_fn_math/node_fn_math.yy new file mode 100644 index 000000000..1bf676731 --- /dev/null +++ b/scripts/node_fn_math/node_fn_math.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"node_fn_math", + "isCompatibility":false, + "isDnD":false, + "name":"node_fn_math", + "parent":{ + "name":"fn", + "path":"folders/nodes/data/animation/fn.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/node_fn_smoothstep/node_fn_smoothstep.gml b/scripts/node_fn_smoothstep/node_fn_smoothstep.gml new file mode 100644 index 000000000..1179fa1ee --- /dev/null +++ b/scripts/node_fn_smoothstep/node_fn_smoothstep.gml @@ -0,0 +1,46 @@ +function Node_Fn_SmoothStep(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor { + name = "SmoothStep"; + time_based = false; + + inputs[| inl + 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) + .setVisible(true, true); + + inputs[| inl + 1] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 ) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Cubic poly", "Quadratic rat", "Cubic rat", "Cosine" ] ); + + array_append(input_display_list, [ + ["Value", false], inl + 1, inl + 0, + ]); + + type = 0; + value = 0; + + static __fnEval = function(_x = 0) { + switch(type) { + case 0 : return _x * _x * (3.0 - 2.0 * _x); + case 1 : return _x * _x / (2.0 * _x * _x - 2.0 * _x + 1.0); + case 2 : return _x * _x * _x / (3.0 * _x * _x - 3.0 * _x + 1.0); + case 3 : return 0.5 - 0.5 * cos(pi * _x); + } + + return _x; + } + + static refreshDisplayX = function(i) { + var _fr = inputs[| inl + 0].value_from; + if(_fr != noone && is_instanceof(_fr.node, Node_Fn)) + return _fr.node.getDisplayX(i); + return i / graph_res; + } + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + value = _data[inl + 0]; + type = _data[inl + 1]; + + var val = __fnEval(value); + + text_display = val; + return val; + } #endregion + +} \ No newline at end of file diff --git a/scripts/node_fn_smoothstep/node_fn_smoothstep.yy b/scripts/node_fn_smoothstep/node_fn_smoothstep.yy new file mode 100644 index 000000000..7a86f2341 --- /dev/null +++ b/scripts/node_fn_smoothstep/node_fn_smoothstep.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"node_fn_smoothstep", + "isCompatibility":false, + "isDnD":false, + "name":"node_fn_smoothstep", + "parent":{ + "name":"fn", + "path":"folders/nodes/data/animation/fn.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/node_registry/node_registry.gml b/scripts/node_registry/node_registry.gml index ff5c3bb13..b3ea22ea2 100644 --- a/scripts/node_registry/node_registry.gml +++ b/scripts/node_registry/node_registry.gml @@ -953,9 +953,12 @@ function __initNodes() { addNodeObject(animation, "Stagger", s_node_stagger, "Node_Stagger", [1, Node_Stagger]).setVersion(11640); ds_list_add(animation, "Value"); - addNodeObject(animation, "WaveTable", s_node_wave, "Node_Fn_WaveTable", [1, Node_Fn_WaveTable],, "Create value changing overtime in wave pattern."); - addNodeObject(animation, "Wiggler", s_node_wiggler, "Node_Wiggler", [1, Node_Wiggler],, "Create random value smoothly changing over time."); - + addNodeObject(animation, "WaveTable", s_node_wave, "Node_Fn_WaveTable", [1, Node_Fn_WaveTable],, "Create value changing overtime in wave pattern."); + addNodeObject(animation, "Wiggler", s_node_wiggler, "Node_Wiggler", [1, Node_Wiggler],, "Create random value smoothly changing over time."); + addNodeObject(animation, "Ease", s_node_ease, "Node_Fn_Ease", [1, Node_Fn_Ease],, ""); + addNodeObject(animation, "Math", s_node_fx_math, "Node_Fn_Math", [1, Node_Fn_Math],, ""); + addNodeObject(animation, "SmoothStep", s_node_fx_smoothstep, "Node_Fn_SmoothStep", [1, Node_Fn_SmoothStep],, ""); + ds_list_add(animation, "Audio"); addNodeObject(animation, "WAV File In", s_node_wav_file_read, "Node_WAV_File_Read", [0, Node_create_WAV_File_Read],, "Load wav audio file.").setVersion(1144); addNodeObject(animation, "WAV File Out", s_node_wav_file_write, "Node_WAV_File_Write", [1, Node_WAV_File_Write],, "Save wav audio file.").setVersion(1145);