1.15 stable

This commit is contained in:
Tanasart 2023-08-12 12:35:35 +02:00
parent 3fc5ab2b75
commit efcbe23074
10 changed files with 98 additions and 100 deletions

View file

@ -42,10 +42,10 @@ function Node_Blur(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
inputs[| 4].setVisible(_isovr); inputs[| 4].setVisible(_isovr);
surface_set_target(_outSurf); surface_set_target(_outSurf);
draw_clear_alpha(_isovr? _overc : 0, 0); draw_clear_alpha(_isovr? _overc : 0, 0);
BLEND_OVERRIDE; BLEND_OVERRIDE;
draw_surface_safe(surface_apply_gaussian(_data[0], _size, false, c_white, _clamp, _overc), 0, 0); draw_surface_safe(surface_apply_gaussian(_data[0], _size, false, c_white, _clamp, _overc), 0, 0);
BLEND_NORMAL; BLEND_NORMAL;
surface_reset_target(); surface_reset_target();
_outSurf = mask_apply(_data[0], _outSurf, _mask, _mix); _outSurf = mask_apply(_data[0], _outSurf, _mask, _mix);

View file

@ -1,11 +1,6 @@
function Node_Blur_Directional(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { function Node_Blur_Directional(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Directional Blur"; name = "Directional Blur";
shader = sh_blur_directional;
uniform_dim = shader_get_uniform(shader, "size");
uniform_str = shader_get_uniform(shader, "strength");
uniform_dir = shader_get_uniform(shader, "direction");
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
inputs[| 1] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2) inputs[| 1] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2)
@ -30,6 +25,7 @@ function Node_Blur_Directional(_x, _y, _group = noone) : Node_Processor(_x, _y,
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
attribute_surface_depth(); attribute_surface_depth();
attribute_oversample();
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _surf = outputs[| 0].getValue(); var _surf = outputs[| 0].getValue();
@ -45,23 +41,18 @@ function Node_Blur_Directional(_x, _y, _group = noone) : Node_Processor(_x, _y,
} }
static process_data = function(_outSurf, _data, _output_index, _array_index) { static process_data = function(_outSurf, _data, _output_index, _array_index) {
var _str = _data[1]; var _str = _data[1];
var _dir = _data[2]; var _dir = _data[2];
var _mask = _data[3]; var _mask = _data[3];
var _mix = _data[4]; var _mix = _data[4];
surface_set_target(_outSurf);
DRAW_CLEAR
BLEND_OVERRIDE;
shader_set(shader); surface_set_shader(_outSurf, sh_blur_directional);
shader_set_uniform_f(uniform_dim, max(surface_get_width(_data[0]), surface_get_height( _data[1]))); shader_set_f("size", max(surface_get_width(_data[0]), surface_get_height( _data[1])));
shader_set_uniform_f(uniform_str, _str); shader_set_f("strength", _str);
shader_set_uniform_f(uniform_dir, _dir + 90); shader_set_f("direction", _dir + 90);
shader_set_i("sampleMode", struct_try_get(attributes, "oversample"));
draw_surface_safe(_data[0], 0, 0); draw_surface_safe(_data[0], 0, 0);
shader_reset(); surface_reset_shader();
BLEND_NORMAL;
surface_reset_target();
_outSurf = mask_apply(_data[0], _outSurf, _mask, _mix); _outSurf = mask_apply(_data[0], _outSurf, _mask, _mix);

View file

@ -44,18 +44,16 @@ function Node_Blur_Radial(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
static process_data = function(_outSurf, _data, _output_index, _array_index) { static process_data = function(_outSurf, _data, _output_index, _array_index) {
var _str = _data[1]; var _str = _data[1];
var _cen = _data[2]; var _cen = _data[2];
var _sam = struct_try_get(attributes, "oversample");
var _mask = _data[4]; var _mask = _data[4];
var _mix = _data[5]; var _mix = _data[5];
_cen[0] /= surface_get_width(_outSurf); _cen[0] /= surface_get_width(_outSurf);
_cen[1] /= surface_get_height(_outSurf); _cen[1] /= surface_get_height(_outSurf);
surface_set_shader(_outSurf, sh_blur_radial); surface_set_shader(_outSurf, sh_blur_radial);
shader_set_interpolation(_data[0]); shader_set_interpolation(_data[0]);
shader_set_f("dimension", surface_get_width(_outSurf), surface_get_height(_outSurf)); shader_set_f("dimension", surface_get_width(_outSurf), surface_get_height(_outSurf));
shader_set_f("strength", abs(_str)); shader_set_f("strength", abs(_str));
shader_set_f("center", _cen); shader_set_f("center", _cen);
shader_set_i("sampleMode", _sam);
draw_surface_safe(_data[0], 0, 0); draw_surface_safe(_data[0], 0, 0);
surface_reset_shader(); surface_reset_shader();

View file

@ -1,15 +1,6 @@
function Node_Blur_Zoom(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { function Node_Blur_Zoom(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Zoom Blur"; name = "Zoom Blur";
shader = sh_blur_zoom;
uniform_str = shader_get_uniform(shader, "strength");
uniform_cen = shader_get_uniform(shader, "center");
uniform_blr = shader_get_uniform(shader, "blurMode");
uniform_sam = shader_get_uniform(shader, "sampleMode");
uniform_umk = shader_get_uniform(shader, "useMask");
uniform_msk = shader_get_sampler_index(shader, "mask");
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
inputs[| 1] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2); inputs[| 1] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2);
@ -64,25 +55,17 @@ function Node_Blur_Zoom(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
_cen[0] /= surface_get_width(_outSurf); _cen[0] /= surface_get_width(_outSurf);
_cen[1] /= surface_get_height(_outSurf); _cen[1] /= surface_get_height(_outSurf);
surface_set_target(_outSurf); surface_set_shader(_outSurf, sh_blur_zoom);
DRAW_CLEAR shader_set_f("strength", _str);
BLEND_OVERRIDE; shader_set_f("center", _cen);
shader_set_i("blurMode", _blr);
shader_set_i("sampleMode", _sam);
shader_set(shader); shader_set_i("useMask", is_surface(_msk));
shader_set_uniform_f(uniform_str, _str); shader_set_surface("mask", _msk);
shader_set_uniform_f_array_safe(uniform_cen, _cen);
shader_set_uniform_i(uniform_blr, _blr);
shader_set_uniform_i(uniform_sam, _sam);
shader_set_uniform_i(uniform_umk, is_surface(_msk));
if(is_surface(_msk))
texture_set_stage(uniform_msk, surface_get_texture(_msk));
draw_surface_safe(_data[0], 0, 0); draw_surface_safe(_data[0], 0, 0);
shader_reset(); surface_reset_shader();
BLEND_NORMAL;
surface_reset_target();
_outSurf = mask_apply(_data[0], _outSurf, _mask, _mix); _outSurf = mask_apply(_data[0], _outSurf, _mask, _mix);

View file

@ -58,6 +58,11 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 20] = nodeValue("Rotate along path", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); inputs[| 20] = nodeValue("Rotate along path", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 21] = nodeValue("Path Shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]);
inputs[| 22] = nodeValue("Scatter Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.atlas, []) outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.atlas, [])
@ -65,7 +70,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
input_display_list = [ input_display_list = [
["Output", true], 0, 1, 15, 10, ["Output", true], 0, 1, 15, 10,
["Scatter", false], 5, 6, 13, 14, 19, 20, 17, 9, 2, ["Scatter", false], 5, 6, 13, 14, 17, 9, 2,
["Path", false], 19, 20, 21, 22,
["Transform", false], 3, 8, 7, 4, ["Transform", false], 3, 8, 7, 4,
["Render", false], 18, 11, 12, 16, ["Render", false], 18, 11, 12, 16,
]; ];
@ -102,6 +108,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 9].setVisible(_dis != 2); inputs[| 9].setVisible(_dis != 2);
inputs[| 19].setVisible(_dis == 4, _dis == 4); inputs[| 19].setVisible(_dis == 4, _dis == 4);
inputs[| 20].setVisible(_dis == 4); inputs[| 20].setVisible(_dis == 4);
inputs[| 21].setVisible(_dis == 4);
inputs[| 22].setVisible(_dis == 4);
} }
static process_data = function(_outSurf, _data, _output_index, _array_index) { static process_data = function(_outSurf, _data, _output_index, _array_index) {
@ -137,6 +145,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
var path = _data[19]; var path = _data[19];
var pathRot = _data[20]; var pathRot = _data[20];
var pathShf = _data[21];
var pathDis = _data[22];
var _in_w, _in_h; var _in_w, _in_h;
@ -160,8 +170,10 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
break; break;
} }
var _pathProgress = 0;
var _sed = seed; var _sed = seed;
var res_index = 0, bg = 0; var res_index = 0, bg = 0;
for(var i = 0; i < _amount; i++) { for(var i = 0; i < _amount; i++) {
var sp = noone, _x = 0, _y = 0; var sp = noone, _x = 0, _y = 0;
var _v = noone; var _v = noone;
@ -185,9 +197,12 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
_v = array_safe_get(sp, 2, noone); _v = array_safe_get(sp, 2, noone);
} else if(_dist == 4) { } else if(_dist == 4) {
if(path != noone && struct_has(path, "getPointRatio")) { if(path != noone && struct_has(path, "getPointRatio")) {
var pp = path.getPointRatio(i / max(1, _amount - 1) * 0.9999); _pathProgress = _scat? random_seed(1, _sed) : i / max(1, _amount); _sed++;
_x = pp.x; _pathProgress = frac((_pathProgress + pathShf) * 0.9999);
_y = pp.y;
var pp = path.getPointRatio(_pathProgress);
_x = pp.x + random_range_seed(-pathDis, pathDis, _sed); _sed++;
_y = pp.y + random_range_seed(-pathDis, pathDis, _sed); _sed++;
} }
} else if(_dist == 5) { } else if(_dist == 5) {
_x = random_range_seed(0, _dim[0], _sed); _sed++; _x = random_range_seed(0, _dim[0], _sed); _sed++;
@ -212,9 +227,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
_r *= _v; _r *= _v;
if(_dist == 4 && path != noone && pathRot) { if(_dist == 4 && path != noone && pathRot) {
var rat = i / max(1, _amount - 1) * 0.9999; var p0 = path.getPointRatio(clamp(_pathProgress - 0.001, 0, 0.9999));
var p0 = path.getPointRatio(clamp(rat - 0.001, 0, 0.9999)); var p1 = path.getPointRatio(clamp(_pathProgress + 0.001, 0, 0.9999));
var p1 = path.getPointRatio(clamp(rat + 0.001, 0, 0.9999));
var dirr = point_direction(p0.x, p0.y, p1.x, p1.y); var dirr = point_direction(p0.x, p0.y, p1.x, p1.y);
_r += dirr; _r += dirr;

View file

@ -1,13 +1,6 @@
function Node_Skew(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { function Node_Skew(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Skew"; name = "Skew";
shader = sh_skew;
uniform_dim = shader_get_uniform(shader, "dimension");
uniform_cen = shader_get_uniform(shader, "center");
uniform_axs = shader_get_uniform(shader, "axis");
uniform_amo = shader_get_uniform(shader, "amount");
uniform_sam = shader_get_uniform(shader, "sampleMode");
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0); inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
inputs[| 1] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) inputs[| 1] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, ["x", "y"]); .setDisplay(VALUE_DISPLAY.enum_button, ["x", "y"]);
@ -59,17 +52,17 @@ function Node_Skew(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
static process_data = function(_outSurf, _data, _output_index, _array_index) { static process_data = function(_outSurf, _data, _output_index, _array_index) {
var _axis = _data[1]; var _axis = _data[1];
var _amou = _data[2]; var _amou = _data[2];
//var _wrap = _data[3]; var _wrap = _data[3];
var _cent = _data[4]; var _cent = _data[4];
var _samp = struct_try_get(attributes, "oversample"); var _samp = struct_try_get(attributes, "oversample");
surface_set_shader(_outSurf, shader); surface_set_shader(_outSurf, sh_skew);
shader_set_interpolation(_data[0]); shader_set_interpolation(_data[0]);
shader_set_uniform_f(uniform_dim, surface_get_width(_data[0]), surface_get_height(_data[0])); shader_set_dim("dimension", _data[0]);
shader_set_uniform_f(uniform_cen, _cent[0], _cent[1]); shader_set_f("center", _cent);
shader_set_uniform_i(uniform_axs, _axis); shader_set_i("axis", _axis);
shader_set_uniform_f(uniform_amo, _amou); shader_set_f("amount", _amou);
shader_set_uniform_i(uniform_sam, _samp); shader_set_i("sampleMode", _samp);
draw_surface_safe(_data[0], 0, 0); draw_surface_safe(_data[0], 0, 0);
surface_reset_shader(); surface_reset_shader();

View file

@ -107,8 +107,9 @@ function shader_set_palette(pal, pal_uni = "palette", amo_uni = "paletteAmount",
var intp = attributes.interpolation; var intp = attributes.interpolation;
gpu_set_tex_filter(intp); gpu_set_tex_filter(intp);
shader_set_i("interpolation", intp); shader_set_i("interpolation", intp);
shader_set_f("sampleDimension", surface_get_width(surface), surface_get_height(surface)); shader_set_f("sampleDimension", surface_get_width(surface), surface_get_height(surface));
shader_set_i("sampleMode", struct_try_get(attributes, "oversample"));
} }
function surface_set_shader(surface, shader = sh_sample, clear = true, blend = BLEND.alpha) { function surface_set_shader(surface, shader = sh_sample, clear = true, blend = BLEND.alpha) {

View file

@ -7,18 +7,36 @@ varying vec4 v_vColour;
uniform float size; uniform float size;
uniform float strength; uniform float strength;
uniform float direction; uniform float direction;
uniform int sampleMode;
vec4 sampleTexture(vec2 pos) {
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
return texture2D(gm_BaseTexture, pos);
if(sampleMode == 0)
return vec4(0.);
if(sampleMode == 1)
return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
if(sampleMode == 2)
return texture2D(gm_BaseTexture, fract(pos));
return vec4(0.);
}
vec4 dirBlur(vec2 angle) { vec4 dirBlur(vec2 angle) {
vec4 acc = vec4(0.); vec4 acc = vec4(0.);
float delta = 1. / size; float delta = 1. / size;
float weight = 0.;
for(float i = -1.0; i <= 1.0; i += delta) { for(float i = -1.0; i <= 1.0; i += delta) {
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord - vec2(angle.x * i, angle.y * i)); vec4 col = sampleTexture( v_vTexcoord - angle * i);
acc += col; acc += col;
weight += col.a;
} }
acc.rgb *= 0.5; acc.rgb /= weight;
return acc * delta; acc.a /= size * 2.;
return acc;
} }
void main() { void main() {

View file

@ -5,13 +5,13 @@ varying vec2 v_vTexcoord;
varying vec4 v_vColour; varying vec4 v_vColour;
uniform vec2 dimension; uniform vec2 dimension;
uniform int horizontal; uniform int horizontal;
uniform float weight[32]; uniform float weight[32];
uniform int size; uniform int size;
uniform int sampleMode; uniform int sampleMode;
uniform int overrideColor; uniform int overrideColor;
uniform vec4 overColor; uniform vec4 overColor;
vec4 sampleTexture(vec2 pos) { vec4 sampleTexture(vec2 pos) {
@ -28,38 +28,38 @@ vec4 sampleTexture(vec2 pos) {
return vec4(0.); return vec4(0.);
} }
float wgh = 0.;
vec4 sample(in vec2 pos, in int index) { vec4 sample(in vec2 pos, in int index) {
vec4 col = sampleTexture( pos ); vec4 col = sampleTexture( pos );
return vec4(col.rgb, col.a) * weight[index]; col.rgb *= weight[index] * col.a;
wgh += weight[index] * col.a;
return col;
} }
void main() { void main() {
vec2 tex_offset = 1.0 / dimension, pos; vec2 tex_offset = 1.0 / dimension, pos;
vec4 result = sample( v_vTexcoord, 0 ); vec4 result = sample( v_vTexcoord, 0 );
vec4 samp;
if(horizontal == 1) { if(horizontal == 1) {
for(int i = 1; i < size; i++) { for(int i = 1; i < size; i++) {
pos = vec2(tex_offset.x * float(i), 0.0); pos = vec2(tex_offset.x * float(i), 0.0);
samp = sample( v_vTexcoord + pos, i ); result += sample( v_vTexcoord + pos, i );
result += samp; result += sample( v_vTexcoord - pos, i );
samp = sample( v_vTexcoord - pos, i );
result += samp;
} }
} else { } else {
for(int i = 1; i < size; i++) { for(int i = 1; i < size; i++) {
pos = vec2(0.0, tex_offset.y * float(i)); pos = vec2(0.0, tex_offset.y * float(i));
samp = sample( v_vTexcoord + pos, i ); result += sample( v_vTexcoord + pos, i );
result += samp; result += sample( v_vTexcoord - pos, i );
samp = sample( v_vTexcoord - pos, i );
result += samp;
} }
} }
result.rgb /= wgh;
result.a = wgh;
gl_FragColor = result; gl_FragColor = result;
if(overrideColor == 1) if(overrideColor == 1)
gl_FragColor.rgb = overColor.rgb; gl_FragColor.rgb = overColor.rgb;

View file

@ -8,13 +8,13 @@ uniform vec2 dimension;
uniform vec2 center; uniform vec2 center;
uniform int axis; uniform int axis;
uniform float amount; uniform float amount;
uniform int sampleMode;
/////////////// SAMPLING /////////////// /////////////// SAMPLING ///////////////
const float PI = 3.14159265358979323846; const float PI = 3.14159265358979323846;
uniform int interpolation; uniform int interpolation;
uniform vec2 sampleDimension; uniform vec2 sampleDimension;
uniform int sampleMode;
const int RSIN_RADIUS = 1; const int RSIN_RADIUS = 1;