diff --git a/scripts/node_color_replace/node_color_replace.gml b/scripts/node_color_replace/node_color_replace.gml index 48b50bfb9..63f3bcd3b 100644 --- a/scripts/node_color_replace/node_color_replace.gml +++ b/scripts/node_color_replace/node_color_replace.gml @@ -30,10 +30,15 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr __init_mask_modifier(7); // inputs 11, 12 - input_display_list = [ 9, 10, + inputs[| 13] = nodeValue("Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Closet", "Random" ]); + + inputs[| 14] = nodeValueSeed(self, VALUE_TYPE.float); + + input_display_list = [ 9, 10, 14, ["Surfaces", true], 0, 7, 8, 11, 12, ["Palette", false], 1, 2, - ["Comparison", false], 3, 5, + ["Comparison", false], 13, 3, 5, ["Render", false], 4, 6 ]; @@ -41,18 +46,20 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr attribute_surface_depth(); - static step = function() { #region + static step = function() { __step_mask_modifier(); - } #endregion + } - static processData = function(_outSurf, _data, _output_index, _array_index) { #region - var fr = _data[1]; - var to = _data[2]; - var tr = _data[3]; - var in = _data[4]; - var alp = _data[5]; - var hrd = _data[6]; - var msk = _data[7]; + static processData = function(_outSurf, _data, _output_index, _array_index) { + var fr = _data[ 1]; + var to = _data[ 2]; + var tr = _data[ 3]; + var in = _data[ 4]; + var alp = _data[ 5]; + var hrd = _data[ 6]; + var msk = _data[ 7]; + var mde = _data[13]; + var sed = _data[14]; var _colorFrom = paletteToArray(fr); var _colorTo = paletteToArray(to); @@ -63,6 +70,8 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr shader_set_f("colorTo", _colorTo); shader_set_i("colorTo_amo", array_length(to)); + shader_set_f("seed", sed); + shader_set_i("mode", mde); shader_set_i("alphacmp", alp); shader_set_i("hardReplace", hrd); shader_set_f("treshold", tr); @@ -79,5 +88,5 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr _outSurf = channel_apply(_data[0], _outSurf, _data[10]); return _outSurf; - } #endregion + } } \ No newline at end of file diff --git a/scripts/node_grid/node_grid.gml b/scripts/node_grid/node_grid.gml index 8b7fe3bc3..7827a78e4 100644 --- a/scripts/node_grid/node_grid.gml +++ b/scripts/node_grid/node_grid.gml @@ -133,6 +133,7 @@ function Node_Grid(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons if(_tex_dim) _dim = surface_get_dimension(_sam); _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); + surface_set_shader(_outSurf, sh_grid); shader_set_f("position", _pos[0] / _dim[0], _pos[1] / _dim[1]); shader_set_f("dimension", _dim[0], _dim[1]); diff --git a/scripts/node_repeat/node_repeat.gml b/scripts/node_repeat/node_repeat.gml index 838485f4e..3f10340b7 100644 --- a/scripts/node_repeat/node_repeat.gml +++ b/scripts/node_repeat/node_repeat.gml @@ -116,6 +116,12 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co inputs[| 32] = nodeValue("Start rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0) .setDisplay(VALUE_DISPLAY.rotation); + inputs[| 33] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0) + .setDisplay(VALUE_DISPLAY.rotation); + + inputs[| 34] = nodeValue("Blend Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Additive", "Maximum" ]); + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); input_display_list = [ @@ -123,15 +129,16 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co ["Pattern", false], 3, 9, 32, 2, 18, 7, 8, ["Path", true], 11, 12, 13, ["Position", false], 4, 26, 19, - ["Rotation", false], 5, + ["Rotation", false], 33, 5, ["Scale", false], 6, 10, - ["Render", false], 14, 30, + ["Render", false], 34, 14, 30, ["Animator", true, 29], 20, 21, 25, 22, 23, 24, 27, ]; attribute_surface_depth(); + attribute_interpolation(); - static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region + static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { PROCESSOR_OVERLAY_CHECK var _hov = false; @@ -149,9 +156,9 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co var hv = inputs[| 31].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny, current_data[1]); active &= !hv; _hov |= hv; return _hov; - } #endregion + } - static preGetInputs = function() { #region + static preGetInputs = function() { var _arr = getSingleValue(16); var _pat = getSingleValue(3); @@ -166,9 +173,9 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co inputs[| 32].setVisible( _pat == 2); inputs[| 14].mappableStep(); - } #endregion + } - static processData = function(_outSurf, _data, _output_index, _array_index) { #region + static processData = function(_outSurf, _data, _output_index, _array_index) { var _iSrf = _data[ 0]; var _dim = _data[ 1]; @@ -181,6 +188,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co var _rpos = _data[ 4]; var _rsta = _data[26]; var _rrot = _data[ 5]; + var _rots = _data[33]; var _rsca = _data[ 6]; var _msca = _data[10]; @@ -213,12 +221,17 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co var _an_bld = _data[27]; var _an_alp = _color_get_alpha(_an_bld); + var _bld_md = _data[34]; + var _surf, runx, runy, posx, posy, scax, scay, rot; random_set_seed(_sed); - surface_set_target(_outSurf); - DRAW_CLEAR + surface_set_shader(_outSurf); + if(_bld_md == 0) BLEND_ALPHA_MULP + else if(_bld_md == 1) BLEND_ADD + else if(_bld_md == 2) { BLEND_ALPHA_MULP gpu_set_blendequation(bm_eq_max); } + runx = 0; runy = 0; @@ -254,7 +267,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co scax = eval_curve_x(_msca, i / (_amo - 1)) * _rsca; scay = scax; - rot = _rrot[0] + (_rrot[1] - _rrot[0]) * i / _amo; + rot = _rots + _rrot[0] + (_rrot[1] - _rrot[0]) * i / _amo; var _an_dist = abs(i - _an_mid * (_amo - 1)); var _inf = 0; @@ -306,13 +319,17 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co aa += _an_alp * _inf; } + shader_set_interpolation(_surf); draw_surface_ext_safe(_surf, posx + pos[0], posy + pos[1], scax, scay, rot, cc, aa); if(_rsta == 1) runx += _sw / 2; if(_rsta == 2) runy += _sh / 2; } - surface_reset_target(); + + BLEND_NORMAL + gpu_set_blendequation(bm_eq_add); + surface_reset_shader(); return _outSurf; - } #endregion + } } \ No newline at end of file diff --git a/scripts/node_stripe/node_stripe.gml b/scripts/node_stripe/node_stripe.gml index 80a107fb3..72bafa4aa 100644 --- a/scripts/node_stripe/node_stripe.gml +++ b/scripts/node_stripe/node_stripe.gml @@ -59,9 +59,11 @@ function Node_Stripe(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co inputs[| 18] = nodeValue("Colors", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, [ c_black, c_white ] ) .setDisplay(VALUE_DISPLAY.palette); + inputs[| 19] = nodeValueSeed(self, VALUE_TYPE.float); + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); - input_display_list = [ + input_display_list = [ 19, ["Output", true], 0, ["Pattern", false], 1, 11, 10, 14, 2, 12, 4, 5, 13, 17, ["Render", false], 3, 6, 7, 15, 8, 9, 18, @@ -107,12 +109,14 @@ function Node_Stripe(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co var _clr1 = _data[9]; var _prg = _data[17]; var _pal = _data[18]; + var _seed = _data[19]; var _color = _data[6]; _outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth()); surface_set_shader(_outSurf, sh_stripe); + shader_set_f("seed", _seed); shader_set_f("dimension", _dim[0], _dim[1]); shader_set_f("position", _pos[0] / _dim[0], _pos[1] / _dim[1]); shader_set_i("blend", _bnd); diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 7c867f410..3baefc1e5 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -1,6 +1,14 @@ function nodeValue(_name, _node, _connect, _type, _value, _tooltip = "") { return new NodeValue(_name, _node, _connect, _type, _value, _tooltip); } function nodeValueMap(_name, _node, _junc = noone) { return new NodeValue(_name, _node, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone).setVisible(false, false).setMapped(_junc); } -function nodeValueGradientRange(_name, _node, _junc = noone) { return new NodeValue(_name, _node, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 1, 0 ]).setDisplay(VALUE_DISPLAY.gradient_range).setVisible(false, false).setMapped(_junc); } +function nodeValueGradientRange(_name, _node, _junc = noone) { return new NodeValue(_name, _node, JUNCTION_CONNECT.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, JUNCTION_CONNECT.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; +} function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constructor { static DISPLAY_DATA_KEYS = [ "linked", "angle_display", "bone_id", "unit", "atlas_crop" ]; diff --git a/scripts/shader_functions/shader_functions.gml b/scripts/shader_functions/shader_functions.gml index af9fa6f9e..32d31cf7e 100644 --- a/scripts/shader_functions/shader_functions.gml +++ b/scripts/shader_functions/shader_functions.gml @@ -1,4 +1,4 @@ -function shader_set_i(uniform, value) { #region +function shader_set_i(uniform, value) { INLINE var shader = shader_current(); @@ -19,13 +19,13 @@ function shader_set_i(uniform, value) { #region array[i - 1] = argument[i]; shader_set_i_array(shader, uniform, array) } -} #endregion +} -function shader_set_i_array(shader, uniform, array) { #region +function shader_set_i_array(shader, uniform, array) { INLINE shader_set_uniform_i_array(shader_get_uniform(shader, uniform), array); -} #endregion +} function shader_set_2(uniform, v) { INLINE var shader = shader_current(); shader_set_uniform_f(shader_get_uniform(shader, uniform), aGetF(v, 0), aGetF(v, 1)); } function shader_set_3(uniform, v) { INLINE var shader = shader_current(); shader_set_uniform_f(shader_get_uniform(shader, uniform), aGetF(v, 0), aGetF(v, 1), aGetF(v, 2)); } @@ -39,7 +39,7 @@ function shader_set_f_array(uniform, value, max_length = 128) { shader_set_uniform_f_array_safe(shader_get_uniform(shader, uniform), value, max_length); } -function shader_set_f(uniform, value) { #region +function shader_set_f(uniform, value) { INLINE var shader = shader_current(); @@ -75,9 +75,9 @@ function shader_set_f(uniform, value) { #region array[i - 1] = argument[i]; shader_set_uniform_f_array(shader_get_uniform(shader, uniform), array); } -} #endregion +} -function shader_set_f_map(uniform, value, surface = noone, junc = noone) { #region +function shader_set_f_map(uniform, value, surface = noone, junc = noone) { INLINE shader_set_f(uniform, is_array(value)? value : [ value, value ]); @@ -88,16 +88,16 @@ function shader_set_f_map(uniform, value, surface = noone, junc = noone) { #regi shader_set_i( uniform + "UseSurf", junc.attributes.mapped && is_surface(surface)); shader_set_surface(uniform + "Surf", surface); } -} #endregion +} -function shader_set_f_map_s(uniform, value, surface, junc) { #region +function shader_set_f_map_s(uniform, value, surface, junc) { INLINE shader_set_f(uniform, is_array(value)? value : [ value, value ]); shader_set_i(uniform + "UseSurf", junc.attributes.mapped && is_surface(surface)); -} #endregion +} -function shader_set_uniform_f_array_safe(uniform, array, max_length = 128) { #region +function shader_set_uniform_f_array_safe(uniform, array, max_length = 128) { INLINE if(!is_array(array)) return; @@ -107,9 +107,9 @@ function shader_set_uniform_f_array_safe(uniform, array, max_length = 128) { #re if(_len > max_length) array_resize(array, max_length) shader_set_uniform_f_array(uniform, array); -} #endregion +} -function shader_set_surface(sampler, surface, linear = false, _repeat = false) { #region +function shader_set_surface(sampler, surface, linear = false, _repeat = false) { INLINE var shader = shader_current(); @@ -126,9 +126,9 @@ function shader_set_surface(sampler, surface, linear = false, _repeat = false) { gpu_set_tex_repeat_ext(t, _repeat); return t; -} #endregion +} -function shader_set_surface_dimension(uniform, surface) { #region +function shader_set_surface_dimension(uniform, surface) { INLINE var shader = shader_current(); @@ -143,22 +143,22 @@ function shader_set_surface_dimension(uniform, surface) { #region th = 2048; shader_set_uniform_f(shader_get_uniform(shader, uniform), tw, th); -} #endregion +} -function shader_set_dim(uniform = "dimension", surf = noone) { #region +function shader_set_dim(uniform = "dimension", surf = noone) { INLINE if(!is_surface(surf)) return; shader_set_f(uniform, surface_get_width_safe(surf), surface_get_height_safe(surf)); -} #endregion +} -function shader_set_color(uniform, col, alpha = 1) { #region +function shader_set_color(uniform, col, alpha = 1) { INLINE shader_set_f(uniform, colToVec4(col, alpha)); -} #endregion +} -function shader_set_palette(pal, pal_uni = "palette", amo_uni = "paletteAmount", max_length = 128) { #region +function shader_set_palette(pal, pal_uni = "palette", amo_uni = "paletteAmount", max_length = 128) { INLINE shader_set_i(amo_uni, min(max_length, array_length(pal))); @@ -169,7 +169,7 @@ function shader_set_palette(pal, pal_uni = "palette", amo_uni = "paletteAmount", if(array_length(_pal)) shader_set_f(pal_uni, _pal); -} #endregion +} #region prebuild enum BLEND { diff --git a/shaders/sh_palette_replace/sh_palette_replace.fsh b/shaders/sh_palette_replace/sh_palette_replace.fsh index 270e9b2f4..8cfae4e1b 100644 --- a/shaders/sh_palette_replace/sh_palette_replace.fsh +++ b/shaders/sh_palette_replace/sh_palette_replace.fsh @@ -12,53 +12,61 @@ uniform int colorFrom_amo; uniform vec4 colorTo[32]; uniform int colorTo_amo; +uniform float seed; +uniform int mode; + uniform int inverted; uniform int alphacmp; uniform int hardReplace; uniform float treshold; -vec3 rgb2xyz( vec3 c ) { #region - vec3 tmp; - tmp.x = ( c.r > 0.04045 ) ? pow( ( c.r + 0.055 ) / 1.055, 2.4 ) : c.r / 12.92; - tmp.y = ( c.g > 0.04045 ) ? pow( ( c.g + 0.055 ) / 1.055, 2.4 ) : c.g / 12.92, - tmp.z = ( c.b > 0.04045 ) ? pow( ( c.b + 0.055 ) / 1.055, 2.4 ) : c.b / 12.92; - return 100.0 * tmp * - mat3( 0.4124, 0.3576, 0.1805, - 0.2126, 0.7152, 0.0722, - 0.0193, 0.1192, 0.9505 ); -} #endregion +#region color spaces -vec3 xyz2lab( vec3 c ) { #region - vec3 n = c / vec3( 95.047, 100, 108.883 ); - vec3 v; - v.x = ( n.x > 0.008856 ) ? pow( n.x, 1.0 / 3.0 ) : ( 7.787 * n.x ) + ( 16.0 / 116.0 ); - v.y = ( n.y > 0.008856 ) ? pow( n.y, 1.0 / 3.0 ) : ( 7.787 * n.y ) + ( 16.0 / 116.0 ); - v.z = ( n.z > 0.008856 ) ? pow( n.z, 1.0 / 3.0 ) : ( 7.787 * n.z ) + ( 16.0 / 116.0 ); - return vec3(( 116.0 * v.y ) - 16.0, 500.0 * ( v.x - v.y ), 200.0 * ( v.y - v.z )); -} #endregion + vec3 rgb2xyz( vec3 c ) { + vec3 tmp; + tmp.x = ( c.r > 0.04045 ) ? pow( ( c.r + 0.055 ) / 1.055, 2.4 ) : c.r / 12.92; + tmp.y = ( c.g > 0.04045 ) ? pow( ( c.g + 0.055 ) / 1.055, 2.4 ) : c.g / 12.92, + tmp.z = ( c.b > 0.04045 ) ? pow( ( c.b + 0.055 ) / 1.055, 2.4 ) : c.b / 12.92; + return 100.0 * tmp * + mat3( 0.4124, 0.3576, 0.1805, + 0.2126, 0.7152, 0.0722, + 0.0193, 0.1192, 0.9505 ); + } + + vec3 xyz2lab( vec3 c ) { + vec3 n = c / vec3( 95.047, 100, 108.883 ); + vec3 v; + v.x = ( n.x > 0.008856 ) ? pow( n.x, 1.0 / 3.0 ) : ( 7.787 * n.x ) + ( 16.0 / 116.0 ); + v.y = ( n.y > 0.008856 ) ? pow( n.y, 1.0 / 3.0 ) : ( 7.787 * n.y ) + ( 16.0 / 116.0 ); + v.z = ( n.z > 0.008856 ) ? pow( n.z, 1.0 / 3.0 ) : ( 7.787 * n.z ) + ( 16.0 / 116.0 ); + return vec3(( 116.0 * v.y ) - 16.0, 500.0 * ( v.x - v.y ), 200.0 * ( v.y - v.z )); + } + + vec3 rgb2lab(vec3 c) { + vec3 lab = xyz2lab( rgb2xyz( c ) ); + return vec3( lab.x / 100.0, 0.5 + 0.5 * ( lab.y / 127.0 ), 0.5 + 0.5 * ( lab.z / 127.0 )); + } + + vec3 rgb2hsv(vec3 c) { + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 0.0000000001; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); + } + + vec3 hsv2rgb(vec3 c) { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); + } -vec3 rgb2lab(vec3 c) { #region - vec3 lab = xyz2lab( rgb2xyz( c ) ); - return vec3( lab.x / 100.0, 0.5 + 0.5 * ( lab.y / 127.0 ), 0.5 + 0.5 * ( lab.z / 127.0 )); -} #endregion +#endregion -vec3 rgb2hsv(vec3 c) { #region - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); - vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); - - float d = q.x - min(q.w, q.y); - float e = 0.0000000001; - return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); - } #endregion - -vec3 hsv2rgb(vec3 c) { #region - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} #endregion - -float round(float val) { return fract(val) >= 0.5? ceil(val) : floor(val); } +float random(in float st) { return fract(sin(st * 12.9898) * (seed + 43758.5453123)); } +float round(float val) { return fract(val) >= 0.5? ceil(val) : floor(val); } void main() { vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); @@ -93,7 +101,10 @@ void main() { } } - vec4 clr = colorTo[int(round(float(min_index) / float(colorFrom_amo - 1) * float(colorTo_amo - 1)))]; + vec4 clr = vec4(0.); + + if(mode == 0) clr = colorTo[int(round(float(min_index) / float(colorFrom_amo - 1) * float(colorTo_amo - 1)))]; + else if(mode == 1) clr = colorTo[int(round(random(float(min_index)) * float(colorTo_amo - 1)))]; if(min_df < treshold) { if(hardReplace == 0) { diff --git a/shaders/sh_sample/sh_sample.fsh b/shaders/sh_sample/sh_sample.fsh index fd702c5fc..c0a414f2b 100644 --- a/shaders/sh_sample/sh_sample.fsh +++ b/shaders/sh_sample/sh_sample.fsh @@ -1,79 +1,76 @@ -// -// Simple passthrough fragment shader -// varying vec2 v_vTexcoord; varying vec4 v_vColour; #region /////////////// SAMPLING /////////////// -const float PI = 3.14159265358979323846; -uniform int interpolation; -uniform vec2 sampleDimension; - -const int RSIN_RADIUS = 1; - -float sinc ( float x ) { return x == 0.? 1. : sin(x * PI) / (x * PI); } - -vec4 texture2D_bilinear( sampler2D texture, vec2 uv ) { - uv = uv * sampleDimension - .5; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); + const float PI = 3.14159265358979323846; + uniform int interpolation; + uniform vec2 sampleDimension; - vec4 mixed = mix( - mix( - texture2D( texture, (iuv + vec2(0., 0.)) / sampleDimension ), - texture2D( texture, (iuv + vec2(1., 0.)) / sampleDimension ), - fuv.x - ), - mix( - texture2D( texture, (iuv + vec2(0., 1.)) / sampleDimension ), - texture2D( texture, (iuv + vec2(1., 1.)) / sampleDimension ), - fuv.x - ), - fuv.y - ); + const int RSIN_RADIUS = 1; - mixed.rgb /= mixed.a; + float sinc ( float x ) { return x == 0.? 1. : sin(x * PI) / (x * PI); } - return mixed; -} - -vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { - vec2 tx = 1.0 / sampleDimension; - vec2 p = uv * sampleDimension - vec2(0.5); - - vec4 sum = vec4(0.0); - float weights = 0.; - - for (int x = -RSIN_RADIUS; x <= RSIN_RADIUS; x++) - for (int y = -RSIN_RADIUS; y <= RSIN_RADIUS; y++) { - float a = length(vec2(float(x), float(y))) / float(RSIN_RADIUS); - if(a > 1.) continue; - float w = sinc(a * PI * tx.x) * sinc(a * PI * tx.y); - vec2 offset = vec2(float(x), float(y)) * tx; - vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); - sum += w * sample; - weights += w; - } + vec4 texture2D_bilinear( sampler2D texture, vec2 uv ) { + uv = uv * sampleDimension - .5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + + vec4 mixed = mix( + mix( + texture2D( texture, (iuv + vec2(0., 0.)) / sampleDimension ), + texture2D( texture, (iuv + vec2(1., 0.)) / sampleDimension ), + fuv.x + ), + mix( + texture2D( texture, (iuv + vec2(0., 1.)) / sampleDimension ), + texture2D( texture, (iuv + vec2(1., 1.)) / sampleDimension ), + fuv.x + ), + fuv.y + ); + + mixed.rgb /= mixed.a; + + return mixed; + } - return sum / weights; -} - -vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { - uv = uv * sampleDimension + 0.5; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); - uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); - uv = (uv - 0.5) / sampleDimension; - return texture2D_bilinear( texture, uv ); -} - -vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 1) return texture2D_bilinear( texture, uv ); - else if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, uv ); - return texture2D( texture, uv ); -} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { + vec2 tx = 1.0 / sampleDimension; + vec2 p = uv * sampleDimension - vec2(0.5); + + vec4 sum = vec4(0.0); + float weights = 0.; + + for (int x = -RSIN_RADIUS; x <= RSIN_RADIUS; x++) + for (int y = -RSIN_RADIUS; y <= RSIN_RADIUS; y++) { + float a = length(vec2(float(x), float(y))) / float(RSIN_RADIUS); + if(a > 1.) continue; + float w = sinc(a * PI * tx.x) * sinc(a * PI * tx.y); + vec2 offset = vec2(float(x), float(y)) * tx; + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); + sum += w * sample; + weights += w; + } + + return sum / weights; + } + + vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { + uv = uv * sampleDimension + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); + uv = (uv - 0.5) / sampleDimension; + return texture2D_bilinear( texture, uv ); + } + + vec4 texture2Dintp( sampler2D texture, vec2 uv ) { + if(interpolation == 1) return texture2D_bilinear( texture, uv ); + else if(interpolation == 2) return texture2D_bicubic( texture, uv ); + else if(interpolation == 3) return texture2D_rsin( texture, uv ); + return texture2D( texture, uv ); + } #endregion /////////////// SAMPLING /////////////// diff --git a/shaders/sh_stripe/sh_stripe.fsh b/shaders/sh_stripe/sh_stripe.fsh index a11b8f167..352109314 100644 --- a/shaders/sh_stripe/sh_stripe.fsh +++ b/shaders/sh_stripe/sh_stripe.fsh @@ -4,6 +4,7 @@ varying vec4 v_vColour; #define PI 3.14159265359 #define PALETTE_LIMIT 128 +uniform float seed; uniform vec2 dimension; uniform vec2 position; uniform int blend; @@ -167,7 +168,7 @@ uniform int paletteAmount; #endregion //////////////////////////////////// GRADIENT //////////////////////////////////// -float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); } +float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * (seed + 43758.5453123)); } void main() { #region #region params