From 24882f60e59d7dbe1e94dd1c22bc53726763113b Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 3 Jul 2024 17:52:51 +0700 Subject: [PATCH] - [Grid] Add accurate mode. --- objects/o_dialog_splash/Create_0.gml | 4 +- scripts/node_grid/node_grid.gml | 28 ++++++++---- .../steam_ugc_functions.gml | 8 +++- shaders/sh_grid/sh_grid.fsh | 44 +++++++++++++++++-- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/objects/o_dialog_splash/Create_0.gml b/objects/o_dialog_splash/Create_0.gml index 46f5fef84..fed05407a 100644 --- a/objects/o_dialog_splash/Create_0.gml +++ b/objects/o_dialog_splash/Create_0.gml @@ -141,9 +141,9 @@ event_inherited(); var mtx = ui(4); var mty = yy; - for (var i = 0, n = array_length(META_TAGS); i < n; i++) { + for (var i = 0, n = array_length(STEAM_TAGS); i < n; i++) { - var tg = META_TAGS[i]; + var tg = STEAM_TAGS[i]; var _sel = array_exists(meta_filter, tg); draw_set_text(f_p2, fa_left, fa_center, _sel? COLORS._main_text : COLORS._main_text_sub); diff --git a/scripts/node_grid/node_grid.gml b/scripts/node_grid/node_grid.gml index 6f7aaab61..8b7fe3bc3 100644 --- a/scripts/node_grid/node_grid.gml +++ b/scripts/node_grid/node_grid.gml @@ -8,11 +8,11 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons .setDisplay(VALUE_DISPLAY.vector) .setUnitRef(function(index) { return getDimension(index); }); - inputs[| 2] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 2, 2 ]) + inputs[| 2] = nodeValue("Grid Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 8, 8 ]) .setDisplay(VALUE_DISPLAY.vector) .setMappable(13); - inputs[| 3] = nodeValue("Gap", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1) + inputs[| 3] = nodeValue("Gap", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2) .setDisplay(VALUE_DISPLAY.slider, { range: [0, 0.5, 0.001] }) .setMappable(14); @@ -35,7 +35,7 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons .setDisplay(VALUE_DISPLAY.enum_button, ["X", "Y"]); inputs[| 10] = nodeValue("Render type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) - .setDisplay(VALUE_DISPLAY.enum_scroll, ["Colored tile", "Height map", "Texture grid", "Texture sample"]); + .setDisplay(VALUE_DISPLAY.enum_scroll, ["Colored tile", "Colored tile (Accurate)", "Height map", "Texture grid", "Texture sample"]); inputs[| 11] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, seed_random(6)) .setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[| 11].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) }); @@ -72,9 +72,13 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons inputs[| 25] = nodeValue("Use Texture Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + inputs[| 26] = nodeValue("Gap Width", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1); + + inputs[| 27] = nodeValue("Diagonal", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + input_display_list = [ ["Output", false], 0, - ["Pattern", false], 1, 4, 15, 2, 13, 3, 14, 9, 8, 16, + ["Pattern", false], 1, 4, 15, 2, 13, 3, 26, 27, 14, 9, 8, 16, ["Render", false], 10, 11, 5, 20, 6, 7, 25, 12, 24, ["Truchet", true, 17], 18, 19, 22, 23, ]; @@ -110,11 +114,17 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _mode = _data[10]; var _col_gap = _data[6]; - var _tex_mode = _mode == 2 || _mode == 3; + var _tex_mode = _mode == 3 || _mode == 4; - inputs[| 5].setVisible(_mode == 0); - inputs[| 6].setVisible(_mode != 1); - inputs[| 24].setVisible(_mode == 1); + inputs[| 5].setVisible(_mode == 0 || _mode == 1); + inputs[| 3].setVisible(_mode == 0 || _mode == 3 || _mode == 4); + inputs[| 24].setVisible(_mode == 2); + inputs[| 26].setVisible(_mode == 1); + + inputs[| 4].setVisible(_mode != 1); + inputs[| 8].setVisible(_mode != 1); + inputs[| 9].setVisible(_mode != 1); + inputs[| 27].setVisible(_mode == 1); inputs[| 7].setVisible(_tex_mode, _tex_mode); inputs[| 25].setVisible(_tex_mode, _tex_mode); @@ -142,6 +152,8 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons shader_set_f("truchetThresY", _data[22]); shader_set_2("truchetAngle", _data[23]); shader_set_2("level", _data[24]); + shader_set_f("gapAcc", _data[26]); + shader_set_i("diagonal", _data[27]); shader_set_color("gapCol", _col_gap); diff --git a/scripts/steam_ugc_functions/steam_ugc_functions.gml b/scripts/steam_ugc_functions/steam_ugc_functions.gml index cc1a314dd..efba9a1fc 100644 --- a/scripts/steam_ugc_functions/steam_ugc_functions.gml +++ b/scripts/steam_ugc_functions/steam_ugc_functions.gml @@ -1,8 +1,10 @@ function __initSteamUGC() { #region - globalvar STEAM_SUBS, STEAM_COLLECTION, STEAM_PROJECTS; + globalvar STEAM_SUBS, STEAM_COLLECTION, STEAM_PROJECTS, STEAM_TAGS; + STEAM_SUBS = ds_list_create(); STEAM_COLLECTION = ds_list_create(); STEAM_PROJECTS = ds_list_create(); + STEAM_TAGS = []; if(DEMO) return; if(!STEAM_ENABLED) return; @@ -15,6 +17,7 @@ function steamUCGload() { #region ds_list_clear(STEAM_SUBS); ds_list_clear(STEAM_COLLECTION); ds_list_clear(STEAM_PROJECTS); + STEAM_TAGS = []; steam_ugc_get_subscribed_items(STEAM_SUBS); @@ -103,4 +106,7 @@ function __loadSteamUGCProject(file_id, f, path) { #region var meta = file.getMetadata(true); meta.steam = FILE_STEAM_TYPE.steamOpen; meta.file_id = file_id; + + for (var i = 0, n = array_length(meta.tags); i < n; i++) + array_push_unique(STEAM_TAGS, meta.tags[i]); } #endregion \ No newline at end of file diff --git a/shaders/sh_grid/sh_grid.fsh b/shaders/sh_grid/sh_grid.fsh index 2a8340b3b..82596a8c5 100644 --- a/shaders/sh_grid/sh_grid.fsh +++ b/shaders/sh_grid/sh_grid.fsh @@ -24,10 +24,13 @@ uniform vec2 shift; uniform int shiftUseSurf; uniform sampler2D shiftSurf; +uniform float gapAcc; uniform vec4 gapCol; uniform int gradient_use; uniform vec2 level; +uniform int diagonal; + uniform int textureTruchet; uniform float truchetSeed; uniform float truchetThresX; @@ -199,6 +202,41 @@ void main() { #region } #endregion + if(mode == 1) { + vec2 px = floor((v_vTexcoord - position) * dimension); + + sca = floor(sca); + vec2 scaG = sca - (gapAcc + 1.); + + if(diagonal == 0) { + vec2 fl = floor(px / sca) * sca; + vec2 fr = px - fl; + + if(fr.x > scaG.x || fr.y > scaG.y) + gl_FragColor = gapCol; + + else + gl_FragColor = gradientEval(random(fl)); + + } else if(diagonal == 1) { + float _x = px.x + px.y; + float _y = -px.x + px.y; + + float mx = mod(_x, sca.x); + float my = mod(_y, sca.y); + + if(mx > scaG.x || my > scaG.y) + gl_FragColor = gapCol; + + else + gl_FragColor = gradientEval(random(vec2(_x, _y) - vec2(mx, my))); + + } + return; + } + + sca = dimension / sca; + vec2 pos = v_vTexcoord - position, _pos; float ratio = dimension.x / dimension.y; _pos.x = pos.x * ratio * cos(ang) - pos.y * sin(ang); @@ -227,7 +265,7 @@ void main() { #region vec4 colr; - if(mode == 1) { + if(mode == 2) { dist = (dist - level.x) / (level.y - level.x); gl_FragColor = vec4(vec3(dist), 1.); return; @@ -236,7 +274,7 @@ void main() { #region if(mode == 0) { colr = gradientEval(random(sqSt)); - } else if(mode == 2) { + } else if(mode == 3) { vec2 uv = fract(_pos * sca); if(textureTruchet == 1) { @@ -252,7 +290,7 @@ void main() { #region colr = texture2D( gm_BaseTexture, uv ); - } else if(mode == 3) { + } else if(mode == 4) { vec2 uv = fract(sqSt); colr = texture2D( gm_BaseTexture, uv ); }