shader things

This commit is contained in:
Tanasart 2024-01-21 16:21:38 +07:00
parent fd234d81d7
commit 391a2bdc1c
19 changed files with 177 additions and 98 deletions

View file

@ -1234,6 +1234,7 @@
{"name":"string_hexadecimal","order":1,"path":"scripts/string_hexadecimal/string_hexadecimal.yy",},
{"name":"s_node_camera","order":3,"path":"sprites/s_node_camera/s_node_camera.yy",},
{"name":"node_random_tile","order":8,"path":"scripts/node_random_tile/node_random_tile.yy",},
{"name":"line_intersect","order":11,"path":"scripts/line_intersect/line_intersect.yy",},
{"name":"Obj_FirebaseFirestore_Document_Set","order":6,"path":"objects/Obj_FirebaseFirestore_Document_Set/Obj_FirebaseFirestore_Document_Set.yy",},
{"name":"_node_strand_affector","order":10,"path":"scripts/_node_strand_affector/_node_strand_affector.yy",},
{"name":"Steamworks","order":2,"path":"extensions/Steamworks/Steamworks.yy",},

View file

@ -1555,6 +1555,7 @@
{"id":{"name":"string_hexadecimal","path":"scripts/string_hexadecimal/string_hexadecimal.yy",},},
{"id":{"name":"s_node_camera","path":"sprites/s_node_camera/s_node_camera.yy",},},
{"id":{"name":"node_random_tile","path":"scripts/node_random_tile/node_random_tile.yy",},},
{"id":{"name":"line_intersect","path":"scripts/line_intersect/line_intersect.yy",},},
{"id":{"name":"sh_find_boundary","path":"shaders/sh_find_boundary/sh_find_boundary.yy",},},
{"id":{"name":"Obj_FirebaseFirestore_Document_Set","path":"objects/Obj_FirebaseFirestore_Document_Set/Obj_FirebaseFirestore_Document_Set.yy",},},
{"id":{"name":"_node_strand_affector","path":"scripts/_node_strand_affector/_node_strand_affector.yy",},},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -65,7 +65,7 @@ if(!MOUSE_WRAPPING) {
val = _snp_v;
if(slide_da) {
var _val_y = slide_dy - (val - tb.slide_sv);
var _val_y = slide_dy - (val - tb.slide_sv) / _s;
var _sdw = _tw;
var _sdh = 256;
@ -90,7 +90,7 @@ if(!MOUSE_WRAPPING) {
var _sdw = 240;
var _sdh = 48;
var _sdx = _val_x - _sdw / 2;
var _sdx = _val_x - _sdw / 2;
var _sdy = slide_dy - _sdh / 2;
draw_sprite_stretched_ext(THEME.textbox_number_slider, 0, _sdx, _sdy, _sdw, _sdh, COLORS.panel_inspector_group_bg, 1);

View file

@ -352,10 +352,11 @@ function __part(_node) constructor {
draw_point(_xx + 1, _yy + 1);
break;
case 3 :
draw_point(_xx, _yy);
draw_point(_xx - 1, _yy);
draw_point(_xx + 1, _yy);
draw_point(_xx, _yy + 1);
draw_point(_xx, _yy - 1);
draw_point(_xx, _yy + 1);
draw_point(_xx, _yy - 1);
break;
default :
draw_circle(_xx, _yy, (exact? round(ss) : ss) - 2, false);

View file

@ -0,0 +1,9 @@
function line_intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if(d == 0) return false;
var px = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
var py = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
return [ px / d, py / d, d ];
}

View file

@ -0,0 +1,11 @@
{
"resourceType": "GMScript",
"resourceVersion": "1.0",
"name": "line_intersect",
"isCompatibility": false,
"isDnD": false,
"parent": {
"name": "vector",
"path": "folders/functions/vector.yy",
},
}

View file

@ -65,7 +65,7 @@ function Node_Gradient(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
inputs[| 3].setVisible(_typ != 1);
inputs[| 4].setVisible(_typ == 1);
inputs[| 14].setVisible(_typ == 1);
inputs[| 14].setVisible(_typ);
inputs[| 3].mappableStep();
inputs[| 4].mappableStep();

View file

@ -94,28 +94,18 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
var _wmin = min(_data[1][0], _data[1][1]);
var _wmax = max(_data[1][0], _data[1][1]);
var _rmin = min(_data[2][0], _data[2][1]);
var _rmax = max(_data[2][0], _data[2][1]);
var _gmin = min(_data[3][0], _data[3][1]);
var _gmax = max(_data[3][0], _data[3][1]);
var _bmin = min(_data[4][0], _data[4][1]);
var _bmax = max(_data[4][0], _data[4][1]);
var _amin = min(_data[5][0], _data[5][1]);
var _amax = max(_data[5][0], _data[5][1]);
var _w = _data[1];
var _r = _data[2];
var _g = _data[3];
var _b = _data[4];
var _a = _data[5];
surface_set_shader(_outSurf, sh_level);
shader_set_f("wmin", _wmin);
shader_set_f("wmax", _wmax);
shader_set_f("rmin", _rmin);
shader_set_f("rmax", _rmax);
shader_set_f("gmin", _gmin);
shader_set_f("gmax", _gmax);
shader_set_f("bmin", _bmin);
shader_set_f("bmax", _bmax);
shader_set_f("amin", _amin);
shader_set_f("amax", _amax);
shader_set_f("lw", _w);
shader_set_f("lr", _r);
shader_set_f("lg", _g);
shader_set_f("lb", _b);
shader_set_f("la", _a);
draw_surface_safe(_data[0]);
surface_reset_shader();

View file

@ -32,6 +32,8 @@ function Node_Level_Selector(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 11] = nodeValue("Keep Original", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
attribute_surface_depth();
@ -79,6 +81,7 @@ function Node_Level_Selector(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
level_renderer,
["Surfaces", true], 0, 3, 4, 7, 8,
["Level", false], 1, 9, 2, 10,
["Output", false], 11,
];
histogramInit();
@ -107,6 +110,7 @@ function Node_Level_Selector(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
surface_set_shader(_outSurf, sh_level_selector);
shader_set_f_map("middle", _data[1], _data[ 9], inputs[| 1]);
shader_set_f_map("range" , _data[2], _data[10], inputs[| 2]);
shader_set_i("keep", _data[11]);
draw_surface_safe(_data[0], 0, 0);
surface_reset_shader();

View file

@ -135,16 +135,17 @@ function Node_MK_Brownian(_x, _y, _group = noone) : Node(_x, _y, _group) constru
draw_point(_pos[0], _pos[1]);
break;
case 2 :
draw_point(_pos[0], _pos[1]);
draw_point(_pos[0], _pos[1]);
draw_point(_pos[0] + 1, _pos[1]);
draw_point(_pos[0], _pos[1] + 1);
draw_point(_pos[0], _pos[1] + 1);
draw_point(_pos[0] + 1, _pos[1] + 1);
break;
case 3 :
draw_point(_pos[0], _pos[1]);
draw_point(_pos[0] - 1, _pos[1]);
draw_point(_pos[0] + 1, _pos[1]);
draw_point(_pos[0], _pos[1] + 1);
draw_point(_pos[0], _pos[1] - 1);
draw_point(_pos[0], _pos[1] + 1);
draw_point(_pos[0], _pos[1] - 1);
break;
default :
draw_circle(round(_pos[0]), round(_pos[1]), round(_ss) - 2, false);

View file

@ -55,6 +55,10 @@ function Node_MK_Saber(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
var _a = inputs[| 1].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny); active &= _a;
var _a = inputs[| 2].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny); active &= _a;
draw_set_text(f_p1, fa_left, fa_bottom, COLORS._main_accent);
draw_text(_p1x + ui(4), _p1y - ui(4), "1");
draw_text(_p2x + ui(4), _p2y - ui(4), "2");
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) {
@ -117,14 +121,14 @@ function Node_MK_Saber(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
}
} #endregion
_cur = [[ _p1x, _p1y ], [ _p2x, _p2y ], [ _p1x, _p1y ], [ _p2x, _p2y ]];
if(_thck) {
_cur = [
[ _p1x - lengthdir_x(_thck / 2, _dir), _p1y - lengthdir_y(_thck / 2, _dir) ],
[ _p2x + lengthdir_x(_thck / 2, _dir), _p2y + lengthdir_y(_thck / 2, _dir) ],
[ _p1x, _p1y ], [ _p2x, _p2y ]
];
} else
_cur = [[ _p1x, _p1y ], [ _p2x, _p2y ], [ _p1x, _p1y ], [ _p2x, _p2y ]];
}
for( var i = 0; i < array_length(temp_surface); i++ )
temp_surface[i] = surface_verify(temp_surface[i], _dim[0], _dim[1]);
@ -133,50 +137,107 @@ function Node_MK_Saber(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
DRAW_CLEAR
draw_set_color(_colr.eval(1));
if(_trac > 0 && CURRENT_FRAME > 0 && prev_points != noone) { #region
if(_trac > 0 && CURRENT_FRAME > 0 && prev_points != noone) { #region Trace
var _prevArr = prev_points[_array_index];
var _inds = max(0, array_length(_prevArr) - _trac);
var useTex = is_surface(_trcTex);
if(useTex)
draw_primitive_begin_texture(pr_trianglelist, surface_get_texture(_trcTex));
else
draw_primitive_begin(pr_trianglelist);
if(useTex) draw_primitive_begin_texture(pr_trianglelist, surface_get_texture(_trcTex));
else draw_primitive_begin(pr_trianglelist);
for( var i = _inds, n = array_length(_prevArr); i < n; i++ ) {
var _prev = _prevArr[i];
var _curr = i + 1 == n? _cur : _prevArr[i + 1];
var _pr1x = _prev[0][0];
var _pr1y = _prev[0][1];
var _pr2x = _prev[1][0];
var _pr2y = _prev[1][1];
var _pr1x = ceil(_prev[0][0]);
var _pr1y = ceil(_prev[0][1]);
var _pr2x = ceil(_prev[1][0]);
var _pr2y = ceil(_prev[1][1]);
var _pp1x = _curr[0][0];
var _pp1y = _curr[0][1];
var _pp2x = _curr[1][0];
var _pp2y = _curr[1][1];
var _pp1x = ceil(_curr[0][0]);
var _pp1y = ceil(_curr[0][1]);
var _pp2x = ceil(_curr[1][0]);
var _pp2y = ceil(_curr[1][1]);
if(useTex) {
var _v0 = (i - _inds + 0) / (n - _inds);
var _v1 = (i - _inds + 1) / (n - _inds);
var _inx = false;// line_intersect(_pr1x, _pr1y, _pr2x, _pr2y, _pp1x, _pp1y, _pp2x, _pp2y);
if(_inx == false) {
if(useTex) {
var _v0 = (i - _inds + 0) / (n - _inds);
var _v1 = (i - _inds + 1) / (n - _inds);
draw_vertex_texture(ceil(_pr1x), ceil(_pr1y), 0, _v0);
draw_vertex_texture(ceil(_pr2x), ceil(_pr2y), 1, _v0);
draw_vertex_texture(ceil(_pp1x), ceil(_pp1y), 0, _v1);
draw_vertex_texture(_pr1x, _pr1y, 0, _v0);
draw_vertex_texture(_pr2x, _pr2y, 1, _v0);
draw_vertex_texture(_pp1x, _pp1y, 0, _v1);
draw_vertex_texture(ceil(_pr2x), ceil(_pr2y), 1, _v0);
draw_vertex_texture(ceil(_pp1x), ceil(_pp1y), 0, _v1);
draw_vertex_texture(ceil(_pp2x), ceil(_pp2y), 1, _v1);
} else {
draw_vertex(ceil(_pr1x), ceil(_pr1y));
draw_vertex(ceil(_pr2x), ceil(_pr2y));
draw_vertex(ceil(_pp1x), ceil(_pp1y));
draw_vertex_texture(_pr2x, _pr2y, 1, _v0);
draw_vertex_texture(_pp1x, _pp1y, 0, _v1);
draw_vertex_texture(_pp2x, _pp2y, 1, _v1);
} else {
draw_vertex(_pr1x, _pr1y);
draw_vertex(_pr2x, _pr2y);
draw_vertex(_pp1x, _pp1y);
draw_vertex(_pr2x, _pr2y);
draw_vertex(_pp1x, _pp1y);
draw_vertex(_pp2x, _pp2y);
}
} else { #region circular // disabled
var _side = point_distance(_inx[0], _inx[1], _pr1x, _pr1y) < point_distance(_inx[0], _inx[1], _pr2x, _pr2y);
var _stp = 8;
draw_vertex(ceil(_pr2x), ceil(_pr2y));
draw_vertex(ceil(_pp1x), ceil(_pp1y));
draw_vertex(ceil(_pp2x), ceil(_pp2y));
}
if(_side == 1) {
var _d0 = point_distance( _pr1x, _pr1y, _pr2x, _pr2y);
var _d1 = point_distance( _pp1x, _pp1y, _pp2x, _pp2y);
var _a0 = point_direction(_pr1x, _pr1y, _pr2x, _pr2y);
var _a1 = point_direction(_pp1x, _pp1y, _pp2x, _pp2y);
var _i0 = point_distance(_inx[0], _inx[1], _pr1x, _pr1y);
var _i1 = point_distance(_inx[0], _inx[1], _pp1x, _pp1y);
} else {
var _d0 = point_distance( _pr2x, _pr2y, _pr1x, _pr1y);
var _d1 = point_distance( _pp2x, _pp2y, _pp1x, _pp1y);
var _a0 = point_direction(_pr2x, _pr2y, _pr1x, _pr1y);
var _a1 = point_direction(_pp2x, _pp2y, _pp1x, _pp1y);
var _i0 = point_distance(_inx[0], _inx[1], _pr2x, _pr2y);
var _i1 = point_distance(_inx[0], _inx[1], _pp2x, _pp2y);
}
var _od, _oa, _oi;
var _nd, _na, _ni;
var __r1x, __r1y, __r2x, __r2y;
var __p1x, __p1y, __p2x, __p2y;
for( var j = 0; j <= _stp; j++ ) {
_nd = lerp(_d0, _d1, j / _stp);
_na = lerp_float_angle(_a0, _a1, j / _stp);
_ni = lerp(_i0, _i1, j / _stp);
if(j) {
__r1x = _inx[0] + lengthdir_x(_oi, _oa);
__r1y = _inx[1] + lengthdir_y(_oi, _oa);
__r2x = _inx[0] + lengthdir_x(_oi + _od, _oa);
__r2y = _inx[1] + lengthdir_y(_oi + _od, _oa);
__p1x = _inx[0] + lengthdir_x(_ni, _na);
__p1y = _inx[1] + lengthdir_y(_ni, _na);
__p2x = _inx[0] + lengthdir_x(_ni + _nd, _na);
__p2y = _inx[1] + lengthdir_y(_ni + _nd, _na);
draw_vertex(ceil(__r1x), ceil(__r1y));
draw_vertex(ceil(__r2x), ceil(__r2y));
draw_vertex(ceil(__p1x), ceil(__p1y));
draw_vertex(ceil(__r2x), ceil(__r2y));
draw_vertex(ceil(__p1x), ceil(__p1y));
draw_vertex(ceil(__p2x), ceil(__p2y));
}
_od = _nd;
_oa = _na;
_oi = _ni;
}
} #endregion
}
draw_primitive_end();
@ -202,7 +263,7 @@ function Node_MK_Saber(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
temp_surface[2] = surface_apply_gaussian(temp_surface[1], _grad, false, 0, 1);
} #endregion
surface_set_target(_outSurf);
surface_set_target(_outSurf); #region
DRAW_CLEAR
if(_gint > 0) {
@ -218,7 +279,7 @@ function Node_MK_Saber(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
draw_surface(temp_surface[0], 0, 0);
BLEND_NORMAL
surface_reset_target();
surface_reset_target(); #endregion
array_push(prev_points[_array_index], _cur);

View file

@ -68,6 +68,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
static onInspector1Update = function(updateAll = true) { initSurface(true); PROJECT.animator.render(); }
static step = function() { #region
var inpt = getInputData(0);
var grup = getInputData(1);
var pack = getInputData(3);
var user = getInputData(11);
@ -81,9 +82,15 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
inputs[| 6].setVisible(pack != SPRITE_STACK.grid);
inputs[| 9].setVisible(pack == SPRITE_STACK.grid);
inputs[| 8].editWidget.minn = FIRST_FRAME + 1;
inputs[| 8].editWidget.maxx = LAST_FRAME + 1;
if(!user) inputs[| 8].setValueDirect([ FIRST_FRAME + 1, LAST_FRAME + 1], noone, false, 0, false);
if(grup == SPRITE_ANIM_GROUP.animation) {
inputs[| 8].editWidget.minn = FIRST_FRAME + 1;
inputs[| 8].editWidget.maxx = LAST_FRAME + 1;
if(!user) inputs[| 8].setValueDirect([ FIRST_FRAME + 1, LAST_FRAME + 1], noone, false, 0, false);
} else {
inputs[| 8].editWidget.minn = 0;
inputs[| 8].editWidget.maxx = array_length(inpt) - 1;
if(!user) inputs[| 8].setValueDirect([ 0, array_length(inpt) - 1], noone, false, 0, false);
}
update_on_frame = grup == 0;
} #endregion
@ -129,7 +136,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
#region frame
var _st, _ed;
var _ln = array_length(inpt);
var _ln = array_length(inpt) - 1;
if(rang[0] < 0) _st = _ln + rang[0];
else _st = rang[0];
@ -175,7 +182,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
for(var j = 0; j < col; j++) {
var index = _st + i * col + j;
if(index >= _ed) break;
if(index > _ed) break;
row_w += surface_get_width_safe(inpt[index]);
if(j) row_w += spc2[0];
@ -258,11 +265,11 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
for(var j = 0; j < col; j++) {
var index = _st + i * col + j;
if(index >= _ed) break;
if(index > _ed) break;
var _w = surface_get_width_safe(inpt[index]);
var _h = surface_get_height_safe(inpt[index]);
array_push(_atl, new SurfaceAtlas(inpt[index], px, py));
draw_surface_safe(inpt[index], px, py);

View file

@ -141,18 +141,20 @@ void main() {
}
#endregion
vec2 asp = dimension / dimension.y;
float prog = 0.;
if(type == 0) {
prog = .5 + (v_vTexcoord.x - center.x) * cos(ang) - (v_vTexcoord.y - center.y) * sin(ang);
} else if(type == 1) {
vec2 asp = dimension / dimension.y;
if(uniAsp == 0) prog = distance(v_vTexcoord, center) / rad;
else prog = distance(v_vTexcoord * asp, center * asp) / rad;
} else if(type == 2) {
vec2 _p = v_vTexcoord - center;
if(uniAsp == 1) _p *= asp;
float _a = atan(_p.y, _p.x) + ang;
prog = (_a - floor(_a / TAU) * TAU) / TAU;

View file

@ -1,31 +1,21 @@
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float wmin;
uniform float wmax;
uniform float rmin;
uniform float rmax;
uniform float gmin;
uniform float gmax;
uniform float bmin;
uniform float bmax;
uniform float amin;
uniform float amax;
uniform vec2 lw;
uniform vec2 lr;
uniform vec2 lg;
uniform vec2 lb;
uniform vec2 la;
void main() {
vec4 col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
col.r = (col.r - rmin) / (rmax - rmin);
col.g = (col.g - gmin) / (gmax - gmin);
col.b = (col.b - bmin) / (bmax - bmin);
col.a = (col.a - amin) / (amax - amin);
col.r = (col.r - lr.x) / (lr.y - lr.x);
col.g = (col.g - lg.x) / (lg.y - lg.x);
col.b = (col.b - lb.x) / (lb.y - lb.x);
col.a = (col.a - la.x) / (la.y - la.x);
col.r = (col.r - wmin) / (wmax - wmin);
col.g = (col.g - wmin) / (wmax - wmin);
col.b = (col.b - wmin) / (wmax - wmin);
col.rgb = (col.rgb - lw.x) / (lw.y - lw.x);
gl_FragColor = col;
}

View file

@ -1,6 +1,3 @@
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
@ -12,6 +9,8 @@ uniform vec2 range;
uniform int rangeUseSurf;
uniform sampler2D rangeSurf;
uniform int keep;
void main() {
float mid = middle.x;
if(middleUseSurf == 1) {
@ -29,7 +28,9 @@ void main() {
float bright = dot(col.rgb, vec3(0.2126, 0.7152, 0.0722));
if(bright > mid + rng || bright < mid - rng)
gl_FragColor = vec4(0., 0., 0., col.a);
else
gl_FragColor = vec4(1., 1., 1., col.a);
gl_FragColor = vec4(vec3(0.), col.a);
else if(keep == 0)
gl_FragColor = vec4(vec3(1.), col.a);
else
gl_FragColor = vec4(vec3(bright), col.a);
}