From 452e55c9085854cebc0d3cf8adc8ec9835c8b49c Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 16 Mar 2024 12:23:47 +0700 Subject: [PATCH] glow --- fonts/_f_sdf/_f_sdf.old.png | Bin 82361 -> 82361 bytes fonts/_f_sdf/_f_sdf.png | Bin 82361 -> 82361 bytes fonts/_f_sdf_medium/_f_sdf_medium.old.png | Bin 59906 -> 59906 bytes fonts/_f_sdf_medium/_f_sdf_medium.png | Bin 59906 -> 59906 bytes scripts/blurSurface/blurSurface.gml | 5 +- scripts/node_glow/node_glow.gml | 66 +++++++++------------- scripts/node_smear/node_smear.gml | 1 + shaders/sh_glow/sh_glow.fsh | 65 +++++++++++++++++++-- 8 files changed, 92 insertions(+), 45 deletions(-) diff --git a/fonts/_f_sdf/_f_sdf.old.png b/fonts/_f_sdf/_f_sdf.old.png index 80285fea488ec4c618e1c7cfaadf8bcf39cc55ba..574e5e96d8107fef4604f4d4807ab5c7515af23b 100644 GIT binary patch delta 96 zcmdnl%(}CgwP6dRiKB>Vh=HM%p@o&9iMD}(m4SifK6az&9*&H%7&0D@_xDY&bYxUe WK-VMxZC)S)5O})!xvX;(veX? W0bS4U!~e}0fWXt$&t;ucLK6U0n;cvK diff --git a/fonts/_f_sdf/_f_sdf.png b/fonts/_f_sdf/_f_sdf.png index 574e5e96d8107fef4604f4d4807ab5c7515af23b..1e301dc78be03ab694747958e32ff71e78403fe9 100644 GIT binary patch delta 96 zcmdnl%(}CgwP6dRiKB>Fh=Gxnk+GGbxwe6Um4U(Eu!z*@9*&H%7&1NF4{lDcbYxUe WK-Y6y?jRcj5O})!xvXVh=HM%p@o&9iMD}(m4SifK6az&9*&H%7&0D@_xDY&bYxUe WK-VMxZC)S)5O})!xvX5z`O@Ln}iID?<})0|P4q1IvBvMw2JLlnp_b@OZqxkAZjH?_DVF}Hxh$iT=%*T7iU5M7V_w|Rj;Jq(_%elF{r5}E*>IwJc3 delta 119 zcmZp=!rXL)c|+|>5t9%@Ln~ubD5wj2jBP%0gD?@W_0|P4qgTG-BsgozZlnp_b=;3~FlYxOjqr^3$ uBqgyV)v6>jH?_DVF}Hxh$iT=%*T7iU5M9r0xr1y#Jq(_%elF{r5}E+v;UjVY delta 119 zcmZp=!rXL)c|+|>5z`O@Ln}iID?<})0|P4q1IvBvMw2JLlnp_b@OZqxkAZjH?_DVF}Hxh$iT=%*T7iU5M7V_w|Rj;Jq(_%elF{r5}E*>IwJc3 diff --git a/scripts/blurSurface/blurSurface.gml b/scripts/blurSurface/blurSurface.gml index 63552d520..59f0c3bcd 100644 --- a/scripts/blurSurface/blurSurface.gml +++ b/scripts/blurSurface/blurSurface.gml @@ -11,8 +11,9 @@ function __gaussian_get_kernel(size) { if(struct_has(GAUSSIAN_COEFF, size)) return GAUSSIAN_COEFF[$ size]; var gau_array = array_create(size); - var we = 0; - var b = 0.3 * ((size - 1) * 0.5 - 1) + 0.8; + var we = 0; + var b = 0.3 * ((size - 1) * 0.5 - 1) + 0.8; + for(var i = 0; i < size; i++) { var _x = i * .5; diff --git a/scripts/node_glow/node_glow.gml b/scripts/node_glow/node_glow.gml index f15af435f..1947b4a55 100644 --- a/scripts/node_glow/node_glow.gml +++ b/scripts/node_glow/node_glow.gml @@ -9,8 +9,8 @@ function Node_Glow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons inputs[| 2] = nodeValue("Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 3) .setDisplay(VALUE_DISPLAY.slider, { range: [1, 16, 1] }); - inputs[| 3] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.5) - .setDisplay(VALUE_DISPLAY.slider); + inputs[| 3] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1) + .setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 4, 0.01 ]}); inputs[| 4] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white); @@ -24,54 +24,42 @@ function Node_Glow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons __init_mask_modifier(5); // inputs 8, 9, + inputs[| 10] = nodeValue("Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_button, [ "Greyscale", "Alpha" ]); + + inputs[| 11] = nodeValue("Draw original", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + input_display_list = [ 7, ["Surfaces", true], 0, 5, 6, 8, 9, - ["Glow", false], 1, 2, 3, 4, + ["Glow", false], 10, 2, 3, + ["Render", false], 4, 11, ] outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); - surface_blur_init(); attribute_surface_depth(); - static step = function() { #region - __step_mask_modifier(); - } #endregion + static step = function() { __step_mask_modifier(); } static processData = function(_outSurf, _data, _output_index, _array_index) { - var _border = _data[1]; - var _size = _data[2]; - var _stre = _data[3]; - var cl = _data[4]; - var pass1 = surface_create_valid(surface_get_width_safe(_outSurf), surface_get_height_safe(_outSurf), attrDepth()); + var _border = _data[1]; + var _size = _data[2]; + var _strength = _data[3]; + var _color = _data[4]; + var _mode = _data[10]; + var _render = _data[11]; - surface_set_target(pass1); - draw_clear_alpha(c_black, 1); - shader_set(sh_outline_only); - shader_set_f("dimension", [ surface_get_width_safe(_outSurf), surface_get_height_safe(_outSurf) ]); - shader_set_f("borderSize", _size + _border); - shader_set_f("borderColor", [ 1., 1., 1., 1. ]); - - if(is_surface(_data[0])) draw_surface_safe(_data[0], 0, 0); - shader_reset(); - surface_reset_target(); - - var s = surface_apply_gaussian(pass1, _size, false, c_black, 1, noone); - - surface_set_shader(_outSurf, sh_lum2alpha); - shader_set_color("color", cl); - shader_set_f("intensity", _stre); - draw_surface_ext_safe(s, 0, 0, 1, 1, 0, c_white, 1); - shader_reset(); - - BLEND_ALPHA_MULP - draw_surface_safe(_data[0], 0, 0); - BLEND_NORMAL - - surface_reset_target(); - - surface_free(pass1); - surface_free(s); + surface_set_shader(_outSurf, sh_glow); + shader_set_dim("dimension", _data[0]); + shader_set_i("mode", _mode); + shader_set_f("border", _border); + shader_set_f("size", _size); + shader_set_f("strength", _strength); + shader_set_color("color", _color); + shader_set_i("render", _render); + + draw_surface_safe(_data[0]); + surface_reset_shader(); __process_mask_modifier(_data); _outSurf = mask_apply(_data[0], _outSurf, _data[5], _data[6]); diff --git a/scripts/node_smear/node_smear.gml b/scripts/node_smear/node_smear.gml index 27a65776e..4aab09d5a 100644 --- a/scripts/node_smear/node_smear.gml +++ b/scripts/node_smear/node_smear.gml @@ -38,6 +38,7 @@ function Node_Smear(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con inputs[| 12] = nodeValue("Modulate strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false) inputs[| 13] = nodeValue("Spread", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.slider, { range : [ 0, 30, 1 ] }); input_display_list = [ 5, 6, ["Surfaces", true], 0, 3, 4, 7, 8, diff --git a/shaders/sh_glow/sh_glow.fsh b/shaders/sh_glow/sh_glow.fsh index d9f2b8df4..9ce8ff706 100644 --- a/shaders/sh_glow/sh_glow.fsh +++ b/shaders/sh_glow/sh_glow.fsh @@ -1,9 +1,66 @@ -// -// Simple passthrough fragment shader -// +#define TAU 6.283185307179586 + varying vec2 v_vTexcoord; varying vec4 v_vColour; +uniform vec2 dimension; +uniform int mode; +uniform float border; +uniform float size; +uniform float strength; +uniform vec4 color; + +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 ); } + +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() { - gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ); + vec2 tx = 1. / dimension; + vec2 px = round(v_vTexcoord * dimension); + + vec4 base = sample(v_vTexcoord); + + if(render == 1) { + gl_FragColor = base; + } else { + if(mode == 0) gl_FragColor = vec4(0., 0., 0., 1.); + 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; + + 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(dist > 0.) { + vec4 cc = color; + float str = (1. - dist / size) * strength; + + if(mode == 0) cc.rgb *= str; + if(mode == 1) cc.a *= str; + + if(render == 1) gl_FragColor = base + cc; + else gl_FragColor = cc; + } }