diff --git a/scripts/node_grid/node_grid.gml b/scripts/node_grid/node_grid.gml index c9360fe64..814f8faaf 100644 --- a/scripts/node_grid/node_grid.gml +++ b/scripts/node_grid/node_grid.gml @@ -68,17 +68,28 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons newInput(27, nodeValue_Bool("Diagonal", self, false)); - newInput(28, nodeValue_Bool("Uniform height", self, true)); + newInput(28, nodeValue_Bool("Uniform gap", self, true)); newInput(29, nodeValue_Float("Secondary Scale", self, 0)); newInput(30, nodeValue_Float("Secondary Shift", self, 0)) .setDisplay(VALUE_DISPLAY.slider); + newInput(31, nodeValue_Float("Random Shift", self, 0)) + .setDisplay(VALUE_DISPLAY.slider); + + newInput(32, nodeValueSeed(self, VALUE_TYPE.float, "Shift Seed")); + + newInput(33, nodeValue_Float("Random Scale", self, 0)) + .setDisplay(VALUE_DISPLAY.slider); + + newInput(34, nodeValueSeed(self, VALUE_TYPE.float, "Scale Seed")); + input_display_list = [ ["Output", false], 0, - ["Pattern", false], 1, 4, 15, 2, 13, 28, 3, 26, 27, 14, 9, 8, 16, - ["Secondary", false], 30, 29, + ["Pattern", false], 1, 4, 15, 2, 13, 28, 3, 26, 27, 14, + ["Shift", false], 9, 8, 16, 31, 32, 30, + ["Scale", false], 29, 33, 34, ["Render", false], 10, 11, 5, 20, 6, 7, 25, 12, 24, ["Truchet", true, 17], 18, 19, 22, 23, ]; @@ -159,6 +170,11 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons shader_set_f("secScale", _data[29]); shader_set_f("secShift", _data[30]); + shader_set_f("randShift", _data[31]); + shader_set_f("randShiftSeed", _data[32]); + shader_set_f("randScale", _data[33]); + shader_set_f("randScaleSeed", _data[34]); + shader_set_color("gapCol", _col_gap); shader_set_gradient(_data[5], _data[20], _data[21], inputs[5]); diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index d8478230e..53158eb75 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -3,8 +3,8 @@ function nodeValueMap(_name, _node, _junc = noone) { return new NodeValue( function nodeValueGradientRange(_name, _node, _junc = noone) { return new NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, [ 0, 0, 1, 0 ]) .setDisplay(VALUE_DISPLAY.gradient_range).setVisible(false, false).setMapped(_junc); } -function nodeValueSeed(_node, _type) { - var _val = new NodeValue("Seed", _node, CONNECT_TYPE.input, _type, seed_random(6), ""); +function nodeValueSeed(_node, _type, _name = "Seed") { + var _val = new NodeValue(_name, _node, CONNECT_TYPE.input, _type, seed_random(6), ""); __node_seed_input_value = _val; _val.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() /*=>*/ { randomize(); __node_seed_input_value.setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) }); return _val; diff --git a/shaders/sh_grid/sh_grid.fsh b/shaders/sh_grid/sh_grid.fsh index 53f582300..2aeb0dd50 100644 --- a/shaders/sh_grid/sh_grid.fsh +++ b/shaders/sh_grid/sh_grid.fsh @@ -40,6 +40,11 @@ uniform float truchetThresX; uniform float truchetThresY; uniform vec2 truchetAngle; +uniform float randShift; +uniform float randShiftSeed; +uniform float randScale; +uniform float randScaleSeed; + float random (in vec2 st) { return fract(sin(dot(st.xy + vec2(85.456034, 64.54065), vec2(12.9898, 78.233))) * (43758.5453123 + seed) ); } #region //////////////////////////////////// GRADIENT //////////////////////////////////// @@ -247,26 +252,22 @@ void main() { _pos.x = pos.x * ratio * cos(ang) - pos.y * sin(ang); _pos.y = pos.x * ratio * sin(ang) + pos.y * cos(ang); - if(shiftAxis == 0) { - shf /= sca.x; - - float cellY = floor(_pos.y * sca.y); - float _sec = mod(cellY, 2.); - float shiftX = _sec * shf; - - _pos.x += shiftX + _sec * secShift; - sca.x *= 1. + _sec * secScale; - } else { - shf /= sca.y; - - float cellX = floor(_pos.x * sca.x); - float _sec = mod(cellX, 2.); - float shiftY = _sec * shf; + shf /= sca[shiftAxis]; + int antiAxis = shiftAxis == 0? 1 : 0; - _pos.y += shiftY + _sec * secShift; - sca.y *= 1. + _sec * secScale; - } + float cell = floor(_pos[antiAxis] * sca[antiAxis]); + float _sec = mod(cell, 2.); + float _shft = (_sec * secShift) + (_sec * shf); + float _rdsh = randShift * (random(randShiftSeed / 1000. + vec2(cell / dimension.x)) * 2. - 1.); + _shft += _rdsh; + float _scas = (_sec * secScale) + (1.); + float _rdsc = randScale * (random(randScaleSeed / 1000. + vec2(cell / dimension.x)) * 2. - 1.); + _scas += _rdsc; + + if(shiftAxis == 0) { _pos.x += _shft; sca.x *= _scas; } + else if(shiftAxis == 1) { _pos.y += _shft; sca.y *= _scas; } + vec2 sqSt = floor(_pos * sca) / sca; vec2 _dist = _pos - sqSt; vec2 nPos = abs(_dist * sca - vec2(0.5)) * 2.; //distance in x, y axis