From 04ecbe8cbb9a0568460c956557112e9f864c616e Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 19 Dec 2024 14:04:30 +0700 Subject: [PATCH] [Region fill] Add random rotation property for texture mapping. --- scripts/node_region_fill/node_region_fill.gml | 13 +++++++++++-- .../sh_region_fill_rg_coord.fsh | 10 +++++++++- .../sh_region_fill_rg_map/sh_region_fill_rg_map.fsh | 9 ++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/node_region_fill/node_region_fill.gml b/scripts/node_region_fill/node_region_fill.gml index 271ac3f6e..e5f8d32b1 100644 --- a/scripts/node_region_fill/node_region_fill.gml +++ b/scripts/node_region_fill/node_region_fill.gml @@ -25,12 +25,14 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou newInput(11, nodeValue_Bool("Color Filter", self, false)); + newInput(12, nodeValue_Rotation_Range("Random rotation", self, [ 0, 0 ])); + newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone)); input_display_list = [ 4, ["Surfaces", false], 0, 1, ["Region Filter", false, 11], 5, 6, - ["Fill", false], 8, 2, 9, 10, + ["Fill", false], 8, 2, 9, 10, 12, ["Render", false], 7, ]; @@ -43,6 +45,7 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou inputs[ 2].setVisible(_filt == 0); inputs[ 9].setVisible(_filt == 1, _filt == 1); inputs[10].setVisible(_filt == 2, _filt == 2); + inputs[12].setVisible(_filt == 2 || _filt == 3); inputs[ 5].setVisible(_fclr); inputs[ 6].setVisible(_fclr); @@ -63,6 +66,7 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou var _fclr = _data[11]; var _targ = _data[5]; var _innr = _data[6]; + var _trot = _data[12]; var _sw = surface_get_width_safe(_surf); var _sh = surface_get_height_safe(_surf) @@ -163,7 +167,7 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou DRAW_CLEAR if(_rnbg == 2) draw_surface_safe(_surf); // render original - + switch(_filt) { case 0 : // Random colors @@ -186,6 +190,8 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou case 2 : // Texture Map shader_set(sh_region_fill_rg_map); shader_set_surface("textureMap", _tmap); + shader_set_2("rotationRandom", [degtorad(_trot[0]), degtorad(_trot[1])]); + shader_set_f("seed", _seed) draw_surface_safe(cmap); shader_reset(); @@ -193,6 +199,9 @@ function Node_Region_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou case 3 : // Texture Map shader_set(sh_region_fill_rg_coord); + shader_set_2("rotationRandom", [degtorad(_trot[0]), degtorad(_trot[1])]); + shader_set_f("seed", _seed) + draw_surface_safe(cmap); shader_reset(); break; diff --git a/shaders/sh_region_fill_rg_coord/sh_region_fill_rg_coord.fsh b/shaders/sh_region_fill_rg_coord/sh_region_fill_rg_coord.fsh index fd9960f1f..6cfa6fb84 100644 --- a/shaders/sh_region_fill_rg_coord/sh_region_fill_rg_coord.fsh +++ b/shaders/sh_region_fill_rg_coord/sh_region_fill_rg_coord.fsh @@ -1,6 +1,11 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; +uniform vec2 rotationRandom; +uniform float seed; + +float random (in vec2 st, float seed) { return fract(sin(dot(st.xy + seed / 1000., vec2(1892.9898, 78.23453))) * 437.54123); } + void main() { vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); @@ -9,6 +14,9 @@ void main() { return; } - vec2 t = (v_vTexcoord - c.xy) / (c.zw - c.xy); + vec2 t = (v_vTexcoord - c.xy) / (c.zw - c.xy); + float r = mix(rotationRandom.x, rotationRandom.y, random(c.xy, seed)); + t = (t - .5) * mat2(cos(r), -sin(r), sin(r), cos(r)) + .5; + gl_FragColor = vec4( t, 0., 1. ); } diff --git a/shaders/sh_region_fill_rg_map/sh_region_fill_rg_map.fsh b/shaders/sh_region_fill_rg_map/sh_region_fill_rg_map.fsh index fafe119e5..eac104077 100644 --- a/shaders/sh_region_fill_rg_map/sh_region_fill_rg_map.fsh +++ b/shaders/sh_region_fill_rg_map/sh_region_fill_rg_map.fsh @@ -2,6 +2,10 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; uniform sampler2D textureMap; +uniform vec2 rotationRandom; +uniform float seed; + +float random (in vec2 st, float seed) { return fract(sin(dot(st.xy + seed / 1000., vec2(1892.9898, 78.23453))) * 437.54123); } void main() { vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); @@ -11,6 +15,9 @@ void main() { return; } - vec2 t = (v_vTexcoord - c.xy) / (c.zw - c.xy); + vec2 t = (v_vTexcoord - c.xy) / (c.zw - c.xy); + float r = mix(rotationRandom.x, rotationRandom.y, random(c.xy, seed)); + t = (t - .5) * mat2(cos(r), -sin(r), sin(r), cos(r)) + .5; + gl_FragColor = texture2D( textureMap, t ); }