[Blur] Add fractional unit to strength.

This commit is contained in:
Tanasart 2024-10-21 10:35:29 +07:00
parent 31e13b15f4
commit 39e002eae3
5 changed files with 32 additions and 14 deletions

View file

@ -2,8 +2,10 @@ function Node_Blur(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
name = "Blur"; name = "Blur";
newInput(0, nodeValue_Surface("Surface in", self)); newInput(0, nodeValue_Surface("Surface in", self));
newInput(1, nodeValue_Int("Size", self, 3)) newInput(1, nodeValue_Int("Size", self, 3))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 1, 32, 0.1 ] }); .setValidator(VV_min(0))
.setUnitRef(function(index) /*=>*/ {return getDimension(index)});
newInput(2, nodeValue_Enum_Scroll("Oversample mode", self, 0, [ "Empty", "Clamp", "Repeat" ])) newInput(2, nodeValue_Enum_Scroll("Oversample mode", self, 0, [ "Empty", "Clamp", "Repeat" ]))
.setTooltip("How to deal with pixel outside the surface.\n - Empty: Use empty pixel\n - Clamp: Repeat edge pixel\n - Repeat: Repeat texture."); .setTooltip("How to deal with pixel outside the surface.\n - Empty: Use empty pixel\n - Clamp: Repeat edge pixel\n - Repeat: Repeat texture.");
@ -45,11 +47,11 @@ function Node_Blur(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
attribute_oversample(); attribute_oversample();
surface_blur_init(); surface_blur_init();
static step = function() { #region static step = function() {
__step_mask_modifier(); __step_mask_modifier();
} #endregion }
static processData = function(_outSurf, _data, _output_index, _array_index) { #region static processData = function(_outSurf, _data, _output_index, _array_index) {
var _surf = _data[0]; var _surf = _data[0];
var _size = min(128, _data[1]); var _size = min(128, _data[1]);
var _clamp = struct_try_get(attributes, "oversample"); var _clamp = struct_try_get(attributes, "oversample");
@ -121,5 +123,5 @@ function Node_Blur(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
_outSurf = channel_apply(_data[0], _outSurf, _data[8]); _outSurf = channel_apply(_data[0], _outSurf, _data[8]);
return _outSurf; return _outSurf;
} #endregion }
} }

View file

@ -334,9 +334,6 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(editWidget) { if(editWidget) {
editWidget.unit = unit; editWidget.unit = unit;
editWidget.onSurfaceSize = ref; editWidget.onSurfaceSize = ref;
if(is_instanceof(editWidget, textBox))
editWidget.side_button = unit.triggerButton;
} }
unit.reference = ref; unit.reference = ref;

View file

@ -4,6 +4,12 @@ function __NodeValue_Int(_name, _node, _value, _tooltip = "") : NodeValue(_name,
/////============== GET ============= /////============== GET =============
static valueProcess = function(value, nodeFrom = undefined, applyUnit = true, arrIndex = 0) {
if(validator != noone) value = validator.validate(value);
value = applyUnit? unit.apply(value, arrIndex) : value;
return round(value);
}
static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value
getValueRecursive(self.__curr_get_val, _time); getValueRecursive(self.__curr_get_val, _time);
var val = __curr_get_val[0]; var val = __curr_get_val[0];
@ -14,9 +20,7 @@ function __NodeValue_Int(_name, _node, _value, _tooltip = "") : NodeValue(_name,
if(typ != VALUE_TYPE.surface) { if(typ != VALUE_TYPE.surface) {
if(typ == VALUE_TYPE.text) val = toNumber(val); if(typ == VALUE_TYPE.text) val = toNumber(val);
if(validator != noone) val = validator.validate(val); return valueProcess(val, nod, applyUnit);
return val;
} }
// Dimension conversion // Dimension conversion
@ -39,8 +43,10 @@ function __NodeValue_Int(_name, _node, _value, _tooltip = "") : NodeValue(_name,
if(eqSize) return _osZ; if(eqSize) return _osZ;
return sArr; return sArr;
} else if (is_surface(val)) } else if (is_surface(val))
return [ surface_get_width_safe(val), surface_get_height_safe(val) ]; return [ surface_get_width_safe(val), surface_get_height_safe(val) ];
return [ 1, 1 ]; return [ 1, 1 ];
} }

View file

@ -503,6 +503,7 @@ function nodeValueUnit(_nodeValue) constructor {
_nodeValue.unitConvert(mode); _nodeValue.unitConvert(mode);
_nodeValue.node.doUpdate(); _nodeValue.node.doUpdate();
}); });
triggerButton.icon_blend = COLORS._main_icon_light; triggerButton.icon_blend = COLORS._main_icon_light;
triggerButton.icon = THEME.unit_ref; triggerButton.icon = THEME.unit_ref;
triggerButton.tooltip = new tooltipSelector("Unit", ["Pixel", "Fraction"]); triggerButton.tooltip = new tooltipSelector("Unit", ["Pixel", "Fraction"]);
@ -520,7 +521,6 @@ function nodeValueUnit(_nodeValue) constructor {
static draw = function(_x, _y, _w, _h, _m) { static draw = function(_x, _y, _w, _h, _m) {
triggerButton.icon_index = mode; triggerButton.icon_index = mode;
triggerButton.tooltip.index = mode; triggerButton.tooltip.index = mode;
triggerButton.draw(_x, _y, _w, _h, _m, THEME.button_hide); triggerButton.draw(_x, _y, _w, _h, _m, THEME.button_hide);
} }
@ -555,8 +555,9 @@ function nodeValueUnit(_nodeValue) constructor {
for( var i = 0, n = array_length(value); i < n; i++ ) for( var i = 0, n = array_length(value); i < n; i++ )
_val[i] = value[i] * base; _val[i] = value[i] * base;
return _val; return _val;
}
} else if(is_array(value)) {
if(is_array(value)) {
if(inv) { if(inv) {
base = [ base = [
base[0] == 0? 0 : 1 / array_safe_get(base, 0), base[0] == 0? 0 : 1 / array_safe_get(base, 0),
@ -598,6 +599,11 @@ function nodeValueUnit(_nodeValue) constructor {
return _val; return _val;
} }
} else {
base = array_safe_get(base, 0, 1);
if(inv) base = base == 0? 0 : 1 / base;
return value * base;
} }
return value; return value;

View file

@ -13,6 +13,7 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor {
precision = 5; precision = 5;
padding = ui(8); padding = ui(8);
unit = noone;
suffix = ""; suffix = "";
no_empty = true; no_empty = true;
@ -473,6 +474,12 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor {
_w -= _bs + ui(4); _w -= _bs + ui(4);
} }
if(unit != noone && unit.reference != noone) {
unit.triggerButton.setFocusHover(iactive, ihover);
unit.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m);
_w -= _bs + ui(4);
}
if(_w - _bs > ui(100) && side_button) { if(_w - _bs > ui(100) && side_button) {
side_button.setFocusHover(active, hover); side_button.setFocusHover(active, hover);
side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide); side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);