From 2ff855332c18dfde021f79900c9044b120d01166 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 22 Jun 2024 12:29:05 +0700 Subject: [PATCH] - [Square, Tri, Pen, Hex Grid] Add option to use texture dimension. --- scripts/node_grid/node_grid.gml | 14 +++++++++++--- scripts/node_grid_hex/node_grid_hex.gml | 14 +++++++++++--- .../node_grid_pentagonal/node_grid_pentagonal.gml | 14 +++++++++++--- scripts/node_grid_tri/node_grid_tri.gml | 14 +++++++++++--- shaders/sh_grid_hex/sh_grid_hex.fsh | 5 +++-- shaders/sh_grid_tri/sh_grid_tri.fsh | 9 +++++---- 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/scripts/node_grid/node_grid.gml b/scripts/node_grid/node_grid.gml index 01512b6de..311753565 100644 --- a/scripts/node_grid/node_grid.gml +++ b/scripts/node_grid/node_grid.gml @@ -70,10 +70,12 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons inputs[| 24] = nodeValue("Level", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ]) .setDisplay(VALUE_DISPLAY.slider_range); + inputs[| 25] = nodeValue("Use Texture Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + input_display_list = [ ["Output", false], 0, ["Pattern", false], 1, 4, 15, 2, 13, 3, 14, 9, 8, 16, - ["Render", false], 10, 11, 5, 20, 6, 7, 12, 24, + ["Render", false], 10, 11, 5, 20, 6, 7, 25, 12, 24, ["Truchet", true, 17], 18, 19, 22, 23, ]; @@ -100,12 +102,18 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _sam = _data[ 7]; var _mode = _data[10]; - var _col_gap = _data[6]; + var _col_gap = _data[6]; + var _tex_mode = _mode == 2 || _mode == 3; inputs[| 5].setVisible(_mode == 0); inputs[| 6].setVisible(_mode != 1); inputs[| 24].setVisible(_mode == 1); - inputs[| 7].setVisible(_mode == 2 || _mode == 3); + + inputs[| 7].setVisible(_tex_mode, _tex_mode); + inputs[| 25].setVisible(_tex_mode, _tex_mode); + + var _tex_dim = is_surface(_sam) && _tex_mode && _data[25]; + if(_tex_dim) _dim = surface_get_dimension(_sam); _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); surface_set_shader(_outSurf, sh_grid); diff --git a/scripts/node_grid_hex/node_grid_hex.gml b/scripts/node_grid_hex/node_grid_hex.gml index 090f2685b..c43176b98 100644 --- a/scripts/node_grid_hex/node_grid_hex.gml +++ b/scripts/node_grid_hex/node_grid_hex.gml @@ -66,10 +66,12 @@ function Node_Grid_Hex(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) inputs[| 20] = nodeValue("Level", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ]) .setDisplay(VALUE_DISPLAY.slider_range); + inputs[| 21] = nodeValue("Use Texture Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + input_display_list = [ ["Output", false], 0, ["Pattern", false], 1, 3, 12, 2, 11, 4, 13, - ["Render", false], 7, 8, 5, 17, 6, 9, 10, 20, + ["Render", false], 7, 8, 5, 17, 6, 9, 21, 10, 20, ["Truchet", true, 14], 15, 16, 19, ]; @@ -95,12 +97,18 @@ function Node_Grid_Hex(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) var _sam = _data[9]; var _mode = _data[7]; - var _col_gap = _data[6]; + var _col_gap = _data[6]; + var _tex_mode = _mode == 2 || _mode == 3; inputs[| 5].setVisible(_mode == 0); inputs[| 6].setVisible(_mode != 1); inputs[| 20].setVisible(_mode == 1); - inputs[| 9].setVisible(_mode == 2 || _mode == 3); + + inputs[| 9].setVisible(_tex_mode, _tex_mode); + inputs[| 21].setVisible(_tex_mode, _tex_mode); + + var _tex_dim = is_surface(_sam) && _tex_mode && _data[21]; + if(_tex_dim) _dim = surface_get_dimension(_sam); _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); diff --git a/scripts/node_grid_pentagonal/node_grid_pentagonal.gml b/scripts/node_grid_pentagonal/node_grid_pentagonal.gml index ac408f415..0c91d7bc8 100644 --- a/scripts/node_grid_pentagonal/node_grid_pentagonal.gml +++ b/scripts/node_grid_pentagonal/node_grid_pentagonal.gml @@ -52,10 +52,12 @@ function Node_Grid_Pentagonal(_x, _y, _group = noone) : Node_Processor(_x, _y, _ inputs[| 16] = nodeValue("Level", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ]) .setDisplay(VALUE_DISPLAY.slider_range); + inputs[| 17] = nodeValue("Use Texture Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + input_display_list = [ ["Output", false], 0, ["Pattern", false], 1, 4, 13, 2, 11, 3, 12, - ["Render", false], 8, 9, 5, 14, 6, 7, 10, 16, + ["Render", false], 8, 9, 5, 14, 6, 7, 17, 10, 16, ]; outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); @@ -80,12 +82,18 @@ function Node_Grid_Pentagonal(_x, _y, _group = noone) : Node_Processor(_x, _y, _ var _sam = _data[7]; var _mode = _data[8]; - var _col_gap = _data[6]; + var _col_gap = _data[6]; + var _tex_mode = _mode == 2 || _mode == 3; inputs[| 5].setVisible(_mode == 0); inputs[| 6].setVisible(_mode != 1); inputs[| 16].setVisible(_mode == 1); - inputs[| 7].setVisible(_mode == 2 || _mode == 3); + + inputs[| 7].setVisible(_tex_mode, _tex_mode); + inputs[| 17].setVisible(_tex_mode, _tex_mode); + + var _tex_dim = is_surface(_sam) && _tex_mode && _data[17]; + if(_tex_dim) _dim = surface_get_dimension(_sam); _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); surface_set_shader(_outSurf, sh_grid_pentagonal); diff --git a/scripts/node_grid_tri/node_grid_tri.gml b/scripts/node_grid_tri/node_grid_tri.gml index 89c5a62d0..8db66cb42 100644 --- a/scripts/node_grid_tri/node_grid_tri.gml +++ b/scripts/node_grid_tri/node_grid_tri.gml @@ -66,10 +66,12 @@ function Node_Grid_Tri(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) inputs[| 20] = nodeValue("Level", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ]) .setDisplay(VALUE_DISPLAY.slider_range); + inputs[| 21] = nodeValue("Use Texture Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + input_display_list = [ ["Output", false], 0, ["Pattern", false], 1, 4, 13, 2, 11, 3, 12, - ["Render", false], 8, 9, 5, 17, 6, 7, 10, 20, + ["Render", false], 8, 9, 5, 17, 6, 7, 21, 10, 20, ["Truchet", true, 14], 15, 16, 19, ]; @@ -97,12 +99,18 @@ function Node_Grid_Tri(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) var _sed = _data[9]; var _aa = _data[10]; - var _col_gap = _data[6]; + var _col_gap = _data[6]; + var _tex_mode = _mode == 2 || _mode == 3; inputs[| 5].setVisible(_mode == 0); inputs[| 6].setVisible(_mode != 1); inputs[| 20].setVisible(_mode == 1); - inputs[| 7].setVisible(_mode == 2 || _mode == 3); + + inputs[| 7].setVisible(_tex_mode, _tex_mode); + inputs[| 21].setVisible(_tex_mode, _tex_mode); + + var _tex_dim = is_surface(_sam) && _tex_mode && _data[21]; + if(_tex_dim) _dim = surface_get_dimension(_sam); _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); diff --git a/shaders/sh_grid_hex/sh_grid_hex.fsh b/shaders/sh_grid_hex/sh_grid_hex.fsh index cdeea04e6..856d2a09b 100644 --- a/shaders/sh_grid_hex/sh_grid_hex.fsh +++ b/shaders/sh_grid_hex/sh_grid_hex.fsh @@ -265,9 +265,10 @@ void main() { #region } colr = texture2D( gm_BaseTexture, uv ); + } else if(mode == 3) { - vec2 uv = clamp(abs(hc.zw) / sca, 0., 1.); - colr = texture2D( gm_BaseTexture, uv ); + vec2 uv = clamp(abs(hc.zw) / sca / vec2(dimension.x / dimension.y, 1.), 0., 1.); + colr = texture2D( gm_BaseTexture, uv ); } float _aa = 3. / max(dimension.x, dimension.y); diff --git a/shaders/sh_grid_tri/sh_grid_tri.fsh b/shaders/sh_grid_tri/sh_grid_tri.fsh index f2d7d2d48..7343be7ce 100644 --- a/shaders/sh_grid_tri/sh_grid_tri.fsh +++ b/shaders/sh_grid_tri/sh_grid_tri.fsh @@ -207,7 +207,7 @@ void main() { #region } #endregion - vec2 pos = (v_vTexcoord - position) * sca, _pos; + vec2 pos = (v_vTexcoord - position) * sca, _pos; float ratio = dimension.x / dimension.y; _pos.x = pos.x * ratio * cos(ang) - pos.y * sin(ang); _pos.y = pos.x * ratio * sin(ang) + pos.y * cos(ang); @@ -226,7 +226,7 @@ void main() { #region vec2 uv = fract(tri.xy / sca); colr = gradientEval(random(uv)); } else if(mode == 2) { - vec2 uv = fract((_pos * vec2(1., c30) - tri.xy) + vec2(0.5, 0.)); + vec2 uv = fract((_pos * vec2(1., c30) - tri.xy) + vec2(0.5, 0.)); if(textureTruchet == 1) { float rx = random(floor(tri.xy) + truchetSeed / 100.); @@ -243,9 +243,10 @@ void main() { #region } colr = texture2D( gm_BaseTexture, uv ); + } else if(mode == 3) { - vec2 uv = clamp(tri.xy / sca, 0., 1.); - colr = texture2D( gm_BaseTexture, uv ); + vec2 uv = clamp(tri.xy / sca / vec2(dimension.x / dimension.y, c30), 0., 1.); + colr = texture2D( gm_BaseTexture, uv ); } float _aa = 3. / max(dimension.x, dimension.y);