diff --git a/scripts/_node_VFX_spawner/_node_VFX_spawner.gml b/scripts/_node_VFX_spawner/_node_VFX_spawner.gml index 4c1bc6c7d..f502b7d02 100644 --- a/scripts/_node_VFX_spawner/_node_VFX_spawner.gml +++ b/scripts/_node_VFX_spawner/_node_VFX_spawner.gml @@ -156,9 +156,13 @@ function Node_VFX_Spawner_Base(_x, _y, _group = noone) : Node(_x, _y, _group) co inputs[| 47] = nodeValue("Path Deviation", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11 ) .rejectArray(); + inputs[| 48] = nodeValue("Reset Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, false ) + .setDisplay(VALUE_DISPLAY.button, { name: "Trigger" }) + .rejectArray(); + input_len = ds_list_size(inputs); - input_display_list = [ 32, + input_display_list = [ 32, 48, ["Sprite", false], 0, 22, 23, 26, ["Spawn", true], 27, 16, 44, 1, 2, 3, 4, 30, 24, 5, ["Movement", true], 29, 6, 18, @@ -176,10 +180,10 @@ function Node_VFX_Spawner_Base(_x, _y, _group = noone) : Node(_x, _y, _group) co array_push(attributeEditors, ["Maximum particles", function() { return attributes.part_amount; }, new textBox(TEXTBOX_INPUT.number, function(val) { attributes.part_amount = val; }) ]); - parts = array_create(attributes.part_amount); + parts = array_create(attributes.part_amount); parts_runner = 0; - seed = 0; + seed = 0; spawn_index = 0; scatter_index = 0; def_surface = -1; @@ -521,6 +525,9 @@ function Node_VFX_Spawner_Base(_x, _y, _group = noone) : Node(_x, _y, _group) co static onDrawOverlay = -1; static update = function(frame = CURRENT_FRAME) { #region + var _resetSeed = getInputData(48); + if(_resetSeed) resetSeed(); + checkPartPool(); onUpdate(frame); } #endregion diff --git a/scripts/node_find_pixel/node_find_pixel.gml b/scripts/node_find_pixel/node_find_pixel.gml index d65a6e460..98185e738 100644 --- a/scripts/node_find_pixel/node_find_pixel.gml +++ b/scripts/node_find_pixel/node_find_pixel.gml @@ -16,6 +16,9 @@ function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group inputs[| 5] = nodeValue("Alpha tolerance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2) .setDisplay(VALUE_DISPLAY.slider); + // inputs[| 6] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1) + // .setDisplay(VALUE_DISPLAY.enum_button, [ "X", "Y" ]); + outputs[| 0] = nodeValue("Position", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, [ 0, 0 ]) .setDisplay(VALUE_DISPLAY.vector); @@ -28,6 +31,12 @@ function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group temp_surface = [ surface_create(1, 1) ]; + static step = function() { #region + // var _all = getInputData(3); + + // inputs[| 6].setVisible(_all); + } #endregion + static processData = function(_output, _data, _output_index, _array_index = 0) { #region var _surf = _data[0]; var _col = _data[1]; @@ -36,6 +45,7 @@ function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group var _alp = _data[4]; var _alpT = _data[5]; + // var _axis = _data[6]; if(!is_surface(_surf)) return [0, 0]; diff --git a/scripts/node_glow/node_glow.gml b/scripts/node_glow/node_glow.gml index a62c35182..077a17c32 100644 --- a/scripts/node_glow/node_glow.gml +++ b/scripts/node_glow/node_glow.gml @@ -28,10 +28,13 @@ function Node_Glow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons .setDisplay(VALUE_DISPLAY.enum_button, [ "Greyscale", "Alpha" ]); inputs[| 11] = nodeValue("Draw original", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + + inputs[| 12] = nodeValue("Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_button, [ "Outer", "Inner" ]); input_display_list = [ 7, ["Surfaces", true], 0, 5, 6, 8, 9, - ["Glow", false], 10, 2, 3, + ["Glow", false], 10, 12, 2, 3, ["Render", false], 4, 11, ] @@ -48,6 +51,7 @@ function Node_Glow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _color = _data[4]; var _mode = _data[10]; var _render = _data[11]; + var _side = _data[12]; surface_set_shader(_outSurf, sh_glow); shader_set_dim("dimension", _data[0]); @@ -57,6 +61,7 @@ function Node_Glow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons shader_set_f("strength", _strength); shader_set_color("color", _color); shader_set_i("render", _render); + shader_set_i("side", _side); draw_surface_safe(_data[0]); surface_reset_shader(); diff --git a/scripts/node_transform/node_transform.gml b/scripts/node_transform/node_transform.gml index e4be5d15e..43c6227f5 100644 --- a/scripts/node_transform/node_transform.gml +++ b/scripts/node_transform/node_transform.gml @@ -180,8 +180,8 @@ function Node_Transform(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) } } #endregion - static processData_prebatch = function() { shader_preset_interpolation(); } - static processData_postbatch = function() { shader_postset_interpolation(); } + // static processData_prebatch = function() { shader_preset_interpolation(); } + // static processData_postbatch = function() { shader_postset_interpolation(); } static processData = function(_outSurf, _data, _output_index, _array_index) { #region var ins = _data[0]; diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index c4926bb17..3d83fb8ed 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -1583,8 +1583,8 @@ function Panel_Preview() : PanelContent() constructor { if(sample_color != noone) { draw_set_color(sample_color); - draw_rectangle(cx, cy, cx + cw, cy + ch, false); draw_set_alpha(1); + draw_rectangle(cx, cy, cx + cw, cy + ch, false); } draw_set_color(COLORS.panel_toolbar_outline); diff --git a/scripts/preferences/preferences.gml b/scripts/preferences/preferences.gml index aa6485f65..866268af3 100644 --- a/scripts/preferences/preferences.gml +++ b/scripts/preferences/preferences.gml @@ -144,13 +144,20 @@ #endregion - #region ///////////////////////////////////////////////////////////////////////// DATA ////////////////////////////////////////////////////////////////////////// - PREFERENCES.attr_palette = [ cola(c_black), cola(c_white) ]; - #endregion - PREFERENCES_DEF = variable_clone(PREFERENCES); #endregion +#region project attributes + globalvar PROJECT_ATTRIBUTES; + + PROJECT_ATTRIBUTES = {} + + PROJECT_ATTRIBUTES.strict = false; + PROJECT_ATTRIBUTES.surface_dimension = [ 32, 32 ]; + PROJECT_ATTRIBUTES.palette = [ cola(c_white), cola(c_black) ]; + PROJECT_ATTRIBUTES.palette_fix = false; +#endregion + #region recent files globalvar RECENT_FILES, RECENT_FILE_DATA; RECENT_FILES = ds_list_create(); @@ -232,10 +239,11 @@ map.preferences = PREFERENCES; - json_save_struct(DIRECTORY + "keys.json", map); - json_save_struct(DIRECTORY + "Nodes/fav.json", global.FAV_NODES); - json_save_struct(DIRECTORY + "Nodes/recent.json", global.RECENT_NODES); - json_save_struct(DIRECTORY + "key_nodes.json", HOTKEYS_CUSTOM); + json_save_struct(DIRECTORY + "keys.json", map); + json_save_struct(DIRECTORY + "Nodes/fav.json", global.FAV_NODES); + json_save_struct(DIRECTORY + "Nodes/recent.json", global.RECENT_NODES); + json_save_struct(DIRECTORY + "key_nodes.json", HOTKEYS_CUSTOM); + json_save_struct(DIRECTORY + "default_project.json", PROJECT_ATTRIBUTES); } #endregion function PREF_LOAD() { #region @@ -257,9 +265,6 @@ struct_override(PREFERENCES, map.preferences); - if(!is_array(PREFERENCES.attr_palette)) - PREFERENCES.attr_palette = PREFERENCES_DEF.attr_palette; - if(!directory_exists($"{DIRECTORY}Themes/{PREFERENCES.theme}")) PREFERENCES.theme = "default"; @@ -273,6 +278,10 @@ directory_verify(filepath_resolve(PREFERENCES.temp_path)); if(PREFERENCES.move_directory) directory_set_current_working(DIRECTORY); + + var f = json_load_struct(DIRECTORY + "default_project.json"); + struct_override(PROJECT_ATTRIBUTES, f); + } #endregion function PREF_APPLY() { #region diff --git a/scripts/project_data/project_data.gml b/scripts/project_data/project_data.gml index ec15e7e6c..bc059ab43 100644 --- a/scripts/project_data/project_data.gml +++ b/scripts/project_data/project_data.gml @@ -59,15 +59,16 @@ }; #endregion #region =================== ATTRIBUTES =================== - attributes = { - strict : false, - surface_dimension : [ 32, 32 ], - palette : array_clone(PREFERENCES.attr_palette), - palette_fix : false, - } + attributes = variable_clone(PROJECT_ATTRIBUTES); attributeEditor = [ - [ "Default Surface", "surface_dimension", new vectorBox(2, function(ind, val) { attributes.surface_dimension[ind] = val; RENDER_ALL return true; }), + [ "Default Surface", "surface_dimension", new vectorBox(2, + function(ind, val) { + attributes.surface_dimension[ind] = val; + PROJECT_ATTRIBUTES.surface_dimension = array_clone(attributes.surface_dimension); + RENDER_ALL + return true; + }), function(junc) { if(!is_struct(junc)) return; if(!is_instanceof(junc, NodeValue)) return; @@ -113,8 +114,13 @@ ]; static setPalette = function(pal = noone) { - if(pal != noone) attributes.palette = pal; - PREFERENCES.attr_palette = array_clone(pal); + if(pal != noone) { + for (var i = 0, n = array_length(pal); i < n; i++) + pal[i] = cola(pal[i], _color_get_alpha(pal[i])); + + attributes.palette = pal; + PROJECT_ATTRIBUTES.palette = array_clone(pal); + } palettes = paletteToArray(attributes.palette); diff --git a/scripts/shader_functions/shader_functions.gml b/scripts/shader_functions/shader_functions.gml index f9b113d0f..0b6c513fe 100644 --- a/scripts/shader_functions/shader_functions.gml +++ b/scripts/shader_functions/shader_functions.gml @@ -191,7 +191,7 @@ function shader_set_palette(pal, pal_uni = "palette", amo_uni = "paletteAmount", var intp = attributes.interpolate; - gpu_set_tex_filter(intp); + // gpu_set_tex_filter(intp); shader_set_i("interpolation", intp); shader_set_f("sampleDimension", _dim == noone? surface_get_dimension(surface) : _dim); shader_set_i("sampleMode", attributes.oversample); diff --git a/shaders/sh_blur_radial/sh_blur_radial.fsh b/shaders/sh_blur_radial/sh_blur_radial.fsh index 1a0f90598..cb6c6a938 100644 --- a/shaders/sh_blur_radial/sh_blur_radial.fsh +++ b/shaders/sh_blur_radial/sh_blur_radial.fsh @@ -24,6 +24,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -37,7 +61,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -51,12 +75,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_blur_slope/sh_blur_slope.fsh b/shaders/sh_blur_slope/sh_blur_slope.fsh index 41d93ff53..dc3e4552c 100644 --- a/shaders/sh_blur_slope/sh_blur_slope.fsh +++ b/shaders/sh_blur_slope/sh_blur_slope.fsh @@ -26,6 +26,30 @@ vec2 txMap; 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 ); + + 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; + } + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -39,7 +63,7 @@ vec2 txMap; 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -53,14 +77,16 @@ vec2 txMap; vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 vec4 sampleTexture(sampler2D texture, vec2 pos) { #region diff --git a/shaders/sh_chromatic_aberration/sh_chromatic_aberration.fsh b/shaders/sh_chromatic_aberration/sh_chromatic_aberration.fsh index 61766ba78..dfb96d515 100644 --- a/shaders/sh_chromatic_aberration/sh_chromatic_aberration.fsh +++ b/shaders/sh_chromatic_aberration/sh_chromatic_aberration.fsh @@ -14,13 +14,37 @@ uniform sampler2D strengthSurf; #region /////////////// SAMPLING /////////////// const float PI = 3.14159265358979323846; -uniform int interpolation; +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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -34,7 +58,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -48,12 +72,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } @@ -75,12 +100,15 @@ void main() { vec2 uvB = v_vTexcoord + texel.xy * precompute; vec4 color; - color.r = texture2Dintp(gm_BaseTexture, uvR).r; - color.g = texture2Dintp(gm_BaseTexture, v_vTexcoord).g; - color.b = texture2Dintp(gm_BaseTexture, uvB).b; - color.a = texture2Dintp(gm_BaseTexture, v_vTexcoord).a + - texture2Dintp(gm_BaseTexture, uvR).a + - texture2Dintp(gm_BaseTexture, uvB).a; + + vec4 cr = texture2Dintp(gm_BaseTexture, uvR); + vec4 cb = texture2Dintp(gm_BaseTexture, uvB); + vec4 cv = texture2Dintp(gm_BaseTexture, v_vTexcoord); + + color.r = cr.r; + color.g = cv.g; + color.b = cb.b; + color.a = cv.a + cr.a + cb.a; gl_FragColor = color; } diff --git a/shaders/sh_dilate/sh_dilate.fsh b/shaders/sh_dilate/sh_dilate.fsh index c9b81a1d4..ae6ae3b78 100644 --- a/shaders/sh_dilate/sh_dilate.fsh +++ b/shaders/sh_dilate/sh_dilate.fsh @@ -26,6 +26,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -39,7 +63,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -53,12 +77,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_displace/sh_displace.fsh b/shaders/sh_displace/sh_displace.fsh index a372a7886..84983d324 100644 --- a/shaders/sh_displace/sh_displace.fsh +++ b/shaders/sh_displace/sh_displace.fsh @@ -29,58 +29,76 @@ float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * 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 ); + + 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; + } + 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + 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( texture, uv ); + return texture2D_bilinear( texture, uv ); } - + vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 sampleTexture(vec2 pos) { if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.) return texture2Dintp(gm_BaseTexture, pos); - if(sampleMode == 0) - return vec4(0.); - - else if(sampleMode == 1) - return texture2Dintp(gm_BaseTexture, clamp(pos, 0., 1.)); - - else if(sampleMode == 2) - return texture2Dintp(gm_BaseTexture, fract(pos)); - - else if(sampleMode == 3) - return vec4(vec3(0.), 1.); + if(sampleMode == 0) return vec4(0.); + else if(sampleMode == 1) return texture2Dintp(gm_BaseTexture, clamp(pos, 0., 1.)); + else if(sampleMode == 2) return texture2Dintp(gm_BaseTexture, fract(pos)); + else if(sampleMode == 3) return vec4(vec3(0.), 1.); return vec4(0.); } diff --git a/shaders/sh_draw_mapping/sh_draw_mapping.fsh b/shaders/sh_draw_mapping/sh_draw_mapping.fsh index 671a72b2d..5685fd2ff 100644 --- a/shaders/sh_draw_mapping/sh_draw_mapping.fsh +++ b/shaders/sh_draw_mapping/sh_draw_mapping.fsh @@ -18,6 +18,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -31,7 +55,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -45,12 +69,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_draw_tile/sh_draw_tile.fsh b/shaders/sh_draw_tile/sh_draw_tile.fsh index 4a7f2d95f..c68c249d7 100644 --- a/shaders/sh_draw_tile/sh_draw_tile.fsh +++ b/shaders/sh_draw_tile/sh_draw_tile.fsh @@ -18,6 +18,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -31,7 +55,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -45,12 +69,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_glow/sh_glow.fsh b/shaders/sh_glow/sh_glow.fsh index 9ce8ff706..1f6835970 100644 --- a/shaders/sh_glow/sh_glow.fsh +++ b/shaders/sh_glow/sh_glow.fsh @@ -10,18 +10,18 @@ uniform float size; uniform float strength; uniform vec4 color; +uniform int side; uniform int render; float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * col.a; } -vec4 sample(vec2 pos) { return texture2D( gm_BaseTexture, pos ); } +vec4 sample(vec2 pos) { return texture2D( gm_BaseTexture, pos ); } float round(float val) { return fract(val) > 0.5? ceil(val) : floor(val); } vec2 round(vec2 val) { return vec2(round(val.x), round(val.y)); } void main() { - vec2 tx = 1. / dimension; - vec2 px = round(v_vTexcoord * dimension); - + vec2 tx = 1. / dimension; + vec2 px = round(v_vTexcoord * dimension); vec4 base = sample(v_vTexcoord); if(render == 1) { @@ -31,25 +31,38 @@ void main() { if(mode == 1) gl_FragColor = vec4(0., 0., 0., 0.); } - if(mode == 0 && base.rgb == vec3(1.)) return; - if(mode == 1 && base.a == 1.) return; + if(side == 0) { + if(mode == 0 && base.rgb == vec3(1.)) return; + if(mode == 1 && base.a == 1.) return; + + } else if(side == 1) { + if(mode == 0 && base.rgb == vec3(0.)) return; + if(mode == 1 && base.a == 0.) return; + + } float dist = 0.; float astp = max(64., size * 4.); for(float i = 1.; i < size; i++) for(float j = 0.; j <= astp; j++) { + float angle = j / astp * TAU; vec2 smPos = v_vTexcoord + vec2(cos(angle), sin(angle)) * i * tx; - //vec2 smPx = round(smPos * dimension); - //if(i < 4. && distance(px, smPx) > i) continue; - vec4 samp = sample(smPos); - if((mode == 0 && bright(samp) > bright(base)) || (mode == 1 && samp.a > base.a)) { - dist = i; - i = size; - break; + if(side == 0) { + if((mode == 0 && bright(samp) > bright(base)) || (mode == 1 && samp.a > base.a)) { + dist = i; + i = size; + break; + } + } else if(side == 1) { + if((mode == 0 && bright(samp) < bright(base)) || (mode == 1 && samp.a < base.a)) { + dist = i; + i = size; + break; + } } } @@ -57,10 +70,12 @@ void main() { vec4 cc = color; float str = (1. - dist / size) * strength; - if(mode == 0) cc.rgb *= str; - if(mode == 1) cc.a *= str; + if(mode == 0) cc.rgb *= str; + else if(side == 0) cc.a *= str; + else if(side == 1) cc.rgb *= str; - if(render == 1) gl_FragColor = base + cc; - else gl_FragColor = cc; + if(render == 1) gl_FragColor = base + cc; + else if(side == 0) gl_FragColor = cc; + else if(side == 1) gl_FragColor = base + cc; } } diff --git a/shaders/sh_morph_surface/sh_morph_surface.fsh b/shaders/sh_morph_surface/sh_morph_surface.fsh index 5991aef8c..6a8cfa6b6 100644 --- a/shaders/sh_morph_surface/sh_morph_surface.fsh +++ b/shaders/sh_morph_surface/sh_morph_surface.fsh @@ -22,6 +22,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -35,7 +59,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -49,12 +73,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_polar/sh_polar.fsh b/shaders/sh_polar/sh_polar.fsh index 10dbd50da..7db13b424 100644 --- a/shaders/sh_polar/sh_polar.fsh +++ b/shaders/sh_polar/sh_polar.fsh @@ -22,6 +22,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -35,7 +59,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -49,12 +73,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_sample/sh_sample.fsh b/shaders/sh_sample/sh_sample.fsh index 953c436d1..fd702c5fc 100644 --- a/shaders/sh_sample/sh_sample.fsh +++ b/shaders/sh_sample/sh_sample.fsh @@ -7,13 +7,37 @@ varying vec4 v_vColour; #region /////////////// SAMPLING /////////////// const float PI = 3.14159265358979323846; -uniform int interpolation; +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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -27,7 +51,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -41,12 +65,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_shape_map_circle/sh_shape_map_circle.fsh b/shaders/sh_shape_map_circle/sh_shape_map_circle.fsh index 2b8566512..3895159d7 100644 --- a/shaders/sh_shape_map_circle/sh_shape_map_circle.fsh +++ b/shaders/sh_shape_map_circle/sh_shape_map_circle.fsh @@ -17,6 +17,30 @@ uniform float angle; 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 ); + + 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; + } + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -30,7 +54,7 @@ uniform float angle; 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -44,12 +68,13 @@ uniform float angle; vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_shape_map_polygon/sh_shape_map_polygon.fsh b/shaders/sh_shape_map_polygon/sh_shape_map_polygon.fsh index 7fc1987fb..ac663f530 100644 --- a/shaders/sh_shape_map_polygon/sh_shape_map_polygon.fsh +++ b/shaders/sh_shape_map_polygon/sh_shape_map_polygon.fsh @@ -18,6 +18,30 @@ uniform float angle; 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 ); + + 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; + } + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -31,7 +55,7 @@ uniform float angle; 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -45,12 +69,13 @@ uniform float angle; vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_skew/sh_skew.fsh b/shaders/sh_skew/sh_skew.fsh index 5c901bc5d..4eefeb444 100644 --- a/shaders/sh_skew/sh_skew.fsh +++ b/shaders/sh_skew/sh_skew.fsh @@ -23,6 +23,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -36,7 +60,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -50,12 +74,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_spherize/sh_spherize.fsh b/shaders/sh_spherize/sh_spherize.fsh index 706cef44a..526efd40e 100644 --- a/shaders/sh_spherize/sh_spherize.fsh +++ b/shaders/sh_spherize/sh_spherize.fsh @@ -28,6 +28,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -41,7 +65,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -55,12 +79,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_texture_remap/sh_texture_remap.fsh b/shaders/sh_texture_remap/sh_texture_remap.fsh index 6e93d98fa..768096958 100644 --- a/shaders/sh_texture_remap/sh_texture_remap.fsh +++ b/shaders/sh_texture_remap/sh_texture_remap.fsh @@ -12,41 +12,67 @@ uniform sampler2D map; 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 ); + + 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; + } + 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + 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 ); } - vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, uv ); - return texture2D( texture, uv ); - } #endregion void main() { diff --git a/shaders/sh_twirl/sh_twirl.fsh b/shaders/sh_twirl/sh_twirl.fsh index 7dcda3297..82b387aff 100644 --- a/shaders/sh_twirl/sh_twirl.fsh +++ b/shaders/sh_twirl/sh_twirl.fsh @@ -26,6 +26,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -39,7 +63,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -53,12 +77,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_warp_4points/sh_warp_4points.fsh b/shaders/sh_warp_4points/sh_warp_4points.fsh index 1952a72f6..107369ba2 100644 --- a/shaders/sh_warp_4points/sh_warp_4points.fsh +++ b/shaders/sh_warp_4points/sh_warp_4points.fsh @@ -16,40 +16,65 @@ uniform vec2 dimension; 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 ); + + 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; + } + 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + 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( texture, uv ); + return texture2D_bilinear( texture, uv ); } - + vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); } diff --git a/shaders/sh_warp_4points_pers/sh_warp_4points_pers.fsh b/shaders/sh_warp_4points_pers/sh_warp_4points_pers.fsh index ba9c53ca2..2be718f75 100644 --- a/shaders/sh_warp_4points_pers/sh_warp_4points_pers.fsh +++ b/shaders/sh_warp_4points_pers/sh_warp_4points_pers.fsh @@ -23,6 +23,30 @@ 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 ); + + 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; +} + vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { vec2 tx = 1.0 / sampleDimension; vec2 p = uv * sampleDimension - vec2(0.5); @@ -36,7 +60,7 @@ vec4 texture2D_rsin( sampler2D texture, vec2 uv ) { 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(texture, (p + offset + vec2(0.5)) / sampleDimension); + vec4 sample = texture2D_bilinear(texture, (p + offset + vec2(0.5)) / sampleDimension); sum += w * sample; weights += w; } @@ -50,12 +74,13 @@ vec4 texture2D_bicubic( sampler2D texture, vec2 uv ) { vec2 fuv = fract( uv ); uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv); uv = (uv - 0.5) / sampleDimension; - return texture2D( texture, uv ); + return texture2D_bilinear( texture, uv ); } vec4 texture2Dintp( sampler2D texture, vec2 uv ) { - if(interpolation == 2) return texture2D_bicubic( texture, uv ); - else if(interpolation == 3) return texture2D_rsin( texture, 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 ); }