- [Separate Shape] Add greyscale, alpha mode selector.

This commit is contained in:
Tanasart 2024-06-02 10:28:43 +07:00
parent 741a77c8a7
commit 70bb9cd261
5 changed files with 31 additions and 36 deletions

View file

@ -291,6 +291,12 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover = false, _foc
var wd_h = jun.express_edit.draw(editBoxX, editBoxY, editBoxW, editBoxH, jun.expression, _m);
widH = wd_h - (TEXTBOX_HEIGHT * !widExtend);
var un = jun.unit;
if(un.reference != noone) {
un.triggerButton.icon_index = un.mode;
un.triggerButton.tooltip.index = un.mode;
}
#endregion
} else if(wid && jun.display_type != VALUE_DISPLAY.none) { #region edit widget

View file

@ -17,12 +17,15 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
inputs[| 4] = nodeValue("Ignore blank", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Skip empty and black shape.")
.rejectArray();
inputs[| 5] = nodeValue("Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
.setDisplay(VALUE_DISPLAY.enum_button, [ "Greyscale", "Alpha" ] )
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Atlas", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
input_display_list = [
["Shape", false], 0, 1, 4,
["Shape", false], 0, 5, 1, 4,
["Override Color", true, 2], 3,
]
@ -45,6 +48,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
var _ovr = getInputData(2);
var _ovrclr = getInputData(3);
var _ignore = getInputData(4);
var _mode = getInputData(5);
var t = current_time;
if(!is_surface(_inSurf)) return;
@ -56,6 +60,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
#region region indexing
surface_set_shader(temp_surface[1], sh_seperate_shape_index);
shader_set_i("mode", _mode);
shader_set_i("ignore", _ignore);
shader_set_f("dimension", ww, hh);
@ -63,6 +68,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
surface_reset_shader();
shader_set(sh_seperate_shape_ite);
shader_set_i("mode", _mode);
shader_set_i("ignore", _ignore);
shader_set_f("dimension", ww, hh);
shader_set_f("threshold", _thres);
@ -110,11 +116,11 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
_val = array_create(px);
var _atlas = array_create(px);
var _reg = ds_map_keys_to_array(reg);
var key = ds_map_keys_to_array(reg);
var _ind = 0;
for(var i = 0; i < px; i++) {
var _k = _reg[i];
var _k = key[i];
var ccx = reg[? _k];
var min_x = round(ccx[0]);

View file

@ -297,6 +297,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
} #endregion
static setUnitRef = function(ref, mode = VALUE_UNIT.constant) { #region
express_edit.side_button = unit.triggerButton;
unit.reference = ref;
unit.mode = mode;
def_unit = mode;
@ -961,8 +963,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
/////============== GET =============
static valueProcess = function(value, nodeFrom, applyUnit = true, arrIndex = 0) { #region
var typeFrom = nodeFrom.type;
static valueProcess = function(value, nodeFrom = undefined, applyUnit = true, arrIndex = 0) { #region
var typeFrom = nodeFrom == undefined? VALUE_TYPE.any : nodeFrom.type;
if(applyUnit && display_type == VALUE_DISPLAY.d3quarternion && display_data.angle_display == QUARTERNION_DISPLAY.euler)
return quarternionFromEuler(value[0], value[1], value[2]);
@ -993,7 +995,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(display_type == VALUE_DISPLAY.area) { #region
if(struct_has(nodeFrom.display_data, "onSurfaceSize")) {
if(!is_undefined(nodeFrom) && struct_has(nodeFrom.display_data, "onSurfaceSize")) {
var surf = nodeFrom.display_data.onSurfaceSize();
var dispType = array_safe_get_fast(value, 5, AREA_MODE.area);
@ -1063,25 +1065,6 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
return value;
} #endregion
static valueExpressionProcess = function(value) { #region
if(is_array(value)) {
for (var i = 0, n = array_length(value); i < n; i++)
value[i] = valueExpressionProcess(value[i]);
return value;
}
switch(type) {
case VALUE_TYPE.float :
case VALUE_TYPE.integer :
return is_numeric(value)? value : toNumber(value);
case VALUE_TYPE.boolean :
return bool(value);
}
return value;
} #endregion
static getStaticValue = function() { INLINE return ds_list_empty(animator.values)? 0 : animator.values[| 0].value; }
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { #region ////Get value
@ -1144,8 +1127,6 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(connect_type == JUNCTION_CONNECT.output)
return val;
if(expUse) return arrayBalance(valueExpressionProcess(val));
if(typ == VALUE_TYPE.surface && (type == VALUE_TYPE.integer || type == VALUE_TYPE.float)) { #region Dimension conversion
if(is_array(val)) {
var eqSize = true;

View file

@ -3,8 +3,9 @@ varying vec4 v_vColour;
uniform vec2 dimension;
uniform int ignore;
uniform int mode;
float sampVal(vec4 col) { return length(col.rgb) * col.a; }
float sampVal(vec4 col) { return mode == 1? col.a : length(col.a); }
void main() {
vec2 px = v_vTexcoord * dimension - .5;

View file

@ -4,14 +4,15 @@ varying vec4 v_vColour;
uniform vec2 dimension;
uniform float threshold;
uniform int ignore;
uniform int mode;
uniform sampler2D map;
vec3 sampVal(vec4 col) { return col.rgb * col.a; }
vec4 sampVal(vec4 col) { return mode == 1? vec4(col.a) : col; }
void main() {
vec3 baseCol = sampVal(texture2D( map, v_vTexcoord ));
vec4 baseCol = sampVal(texture2D( map, v_vTexcoord ));
if(ignore == 1 && baseCol == vec3(0.)) {
if(ignore == 1 && baseCol == vec4(0.)) {
gl_FragColor = vec4(0.);
return;
}
@ -24,9 +25,9 @@ void main() {
for(float i = -1.; i <= 1.; i++)
for(float j = -1.; j <= 1.; j++) {
vec2 pos = clamp(v_vTexcoord + vec2(i, j) * tx, 0., 1.);
vec3 samCl = sampVal(texture2D( map, pos ));
vec4 samCl = sampVal(texture2D( map, pos ));
if(ignore == 1 && samCl == vec3(0.)) continue;
if(ignore == 1 && samCl == vec4(0.)) continue;
if(distance(samCl, baseCol) <= threshold) {
vec4 _col = texture2D( gm_BaseTexture, pos );