mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
- [Separate Shape] Add greyscale, alpha mode selector.
This commit is contained in:
parent
741a77c8a7
commit
70bb9cd261
5 changed files with 31 additions and 36 deletions
|
@ -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);
|
var wd_h = jun.express_edit.draw(editBoxX, editBoxY, editBoxW, editBoxH, jun.expression, _m);
|
||||||
widH = wd_h - (TEXTBOX_HEIGHT * !widExtend);
|
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
|
#endregion
|
||||||
|
|
||||||
} else if(wid && jun.display_type != VALUE_DISPLAY.none) { #region edit widget
|
} else if(wid && jun.display_type != VALUE_DISPLAY.none) { #region edit widget
|
||||||
|
|
|
@ -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.")
|
inputs[| 4] = nodeValue("Ignore blank", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Skip empty and black shape.")
|
||||||
.rejectArray();
|
.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[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
||||||
|
|
||||||
outputs[| 1] = nodeValue("Atlas", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
|
outputs[| 1] = nodeValue("Atlas", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
|
||||||
|
|
||||||
input_display_list = [
|
input_display_list = [
|
||||||
["Shape", false], 0, 1, 4,
|
["Shape", false], 0, 5, 1, 4,
|
||||||
["Override Color", true, 2], 3,
|
["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 _ovr = getInputData(2);
|
||||||
var _ovrclr = getInputData(3);
|
var _ovrclr = getInputData(3);
|
||||||
var _ignore = getInputData(4);
|
var _ignore = getInputData(4);
|
||||||
|
var _mode = getInputData(5);
|
||||||
var t = current_time;
|
var t = current_time;
|
||||||
|
|
||||||
if(!is_surface(_inSurf)) return;
|
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
|
#region region indexing
|
||||||
surface_set_shader(temp_surface[1], sh_seperate_shape_index);
|
surface_set_shader(temp_surface[1], sh_seperate_shape_index);
|
||||||
|
shader_set_i("mode", _mode);
|
||||||
shader_set_i("ignore", _ignore);
|
shader_set_i("ignore", _ignore);
|
||||||
shader_set_f("dimension", ww, hh);
|
shader_set_f("dimension", ww, hh);
|
||||||
|
|
||||||
|
@ -63,7 +68,8 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
surface_reset_shader();
|
surface_reset_shader();
|
||||||
|
|
||||||
shader_set(sh_seperate_shape_ite);
|
shader_set(sh_seperate_shape_ite);
|
||||||
shader_set_i("ignore", _ignore);
|
shader_set_i("mode", _mode);
|
||||||
|
shader_set_i("ignore", _ignore);
|
||||||
shader_set_f("dimension", ww, hh);
|
shader_set_f("dimension", ww, hh);
|
||||||
shader_set_f("threshold", _thres);
|
shader_set_f("threshold", _thres);
|
||||||
shader_set_surface("map", _inSurf);
|
shader_set_surface("map", _inSurf);
|
||||||
|
@ -110,11 +116,11 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
_val = array_create(px);
|
_val = array_create(px);
|
||||||
|
|
||||||
var _atlas = 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;
|
var _ind = 0;
|
||||||
|
|
||||||
for(var i = 0; i < px; i++) {
|
for(var i = 0; i < px; i++) {
|
||||||
var _k = _reg[i];
|
var _k = key[i];
|
||||||
var ccx = reg[? _k];
|
var ccx = reg[? _k];
|
||||||
|
|
||||||
var min_x = round(ccx[0]);
|
var min_x = round(ccx[0]);
|
||||||
|
|
|
@ -297,6 +297,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
|
||||||
} #endregion
|
} #endregion
|
||||||
|
|
||||||
static setUnitRef = function(ref, mode = VALUE_UNIT.constant) { #region
|
static setUnitRef = function(ref, mode = VALUE_UNIT.constant) { #region
|
||||||
|
express_edit.side_button = unit.triggerButton;
|
||||||
|
|
||||||
unit.reference = ref;
|
unit.reference = ref;
|
||||||
unit.mode = mode;
|
unit.mode = mode;
|
||||||
def_unit = mode;
|
def_unit = mode;
|
||||||
|
@ -961,8 +963,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
|
||||||
|
|
||||||
/////============== GET =============
|
/////============== GET =============
|
||||||
|
|
||||||
static valueProcess = function(value, nodeFrom, applyUnit = true, arrIndex = 0) { #region
|
static valueProcess = function(value, nodeFrom = undefined, applyUnit = true, arrIndex = 0) { #region
|
||||||
var typeFrom = nodeFrom.type;
|
var typeFrom = nodeFrom == undefined? VALUE_TYPE.any : nodeFrom.type;
|
||||||
|
|
||||||
if(applyUnit && display_type == VALUE_DISPLAY.d3quarternion && display_data.angle_display == QUARTERNION_DISPLAY.euler)
|
if(applyUnit && display_type == VALUE_DISPLAY.d3quarternion && display_data.angle_display == QUARTERNION_DISPLAY.euler)
|
||||||
return quarternionFromEuler(value[0], value[1], value[2]);
|
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(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 surf = nodeFrom.display_data.onSurfaceSize();
|
||||||
var dispType = array_safe_get_fast(value, 5, AREA_MODE.area);
|
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;
|
return value;
|
||||||
} #endregion
|
} #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 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
|
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)
|
if(connect_type == JUNCTION_CONNECT.output)
|
||||||
return val;
|
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(typ == VALUE_TYPE.surface && (type == VALUE_TYPE.integer || type == VALUE_TYPE.float)) { #region Dimension conversion
|
||||||
if(is_array(val)) {
|
if(is_array(val)) {
|
||||||
var eqSize = true;
|
var eqSize = true;
|
||||||
|
|
|
@ -3,8 +3,9 @@ varying vec4 v_vColour;
|
||||||
|
|
||||||
uniform vec2 dimension;
|
uniform vec2 dimension;
|
||||||
uniform int ignore;
|
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() {
|
void main() {
|
||||||
vec2 px = v_vTexcoord * dimension - .5;
|
vec2 px = v_vTexcoord * dimension - .5;
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
varying vec2 v_vTexcoord;
|
varying vec2 v_vTexcoord;
|
||||||
varying vec4 v_vColour;
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
uniform vec2 dimension;
|
uniform vec2 dimension;
|
||||||
uniform float threshold;
|
uniform float threshold;
|
||||||
uniform int ignore;
|
uniform int ignore;
|
||||||
|
uniform int mode;
|
||||||
uniform sampler2D map;
|
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() {
|
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.);
|
gl_FragColor = vec4(0.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,9 +25,9 @@ void main() {
|
||||||
for(float i = -1.; i <= 1.; i++)
|
for(float i = -1.; i <= 1.; i++)
|
||||||
for(float j = -1.; j <= 1.; j++) {
|
for(float j = -1.; j <= 1.; j++) {
|
||||||
vec2 pos = clamp(v_vTexcoord + vec2(i, j) * tx, 0., 1.);
|
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) {
|
if(distance(samCl, baseCol) <= threshold) {
|
||||||
vec4 _col = texture2D( gm_BaseTexture, pos );
|
vec4 _col = texture2D( gm_BaseTexture, pos );
|
||||||
|
|
Loading…
Reference in a new issue