Mappable gradient for cpu nodes

This commit is contained in:
Tanasart 2024-01-22 16:46:04 +07:00
parent 38fb8da6fe
commit 7ffec26331
3 changed files with 91 additions and 28 deletions

View file

@ -34,7 +34,8 @@ function Node_Plot_Linear(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
inputs[| 12] = nodeValue("Value Offset", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
inputs[| 13] = nodeValue("Color Over Sample", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white));
inputs[| 13] = nodeValue("Color Over Sample", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white))
.setMappable(27);
inputs[| 14] = nodeValue("Trim mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Range", "Window" ]);
@ -59,19 +60,32 @@ function Node_Plot_Linear(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
inputs[| 23] = nodeValue("Smooth", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 24] = nodeValue("Color Over Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white));
inputs[| 24] = nodeValue("Color Over Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white))
.setMappable(29);
inputs[| 25] = nodeValue("Value range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ] )
.setDisplay(VALUE_DISPLAY.range);
inputs[| 26] = nodeValue("Absolute", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 27] = nodeValueMap("Sample Gradient map", self);
inputs[| 28] = nodeValueGradientRange("Sample Gradient map range", self, inputs[| 13]);
inputs[| 29] = nodeValueMap("Value Gradient map", self);
inputs[| 30] = nodeValueGradientRange("Value Gradient map range", self, inputs[| 24]);
//////////////////////////////////////////////////////////////////////////////////////////////////
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [ 0,
["Data", true], 1, 12, 21, 14, 2, 3, 15, 16,
["Plot", false], 11, 4, 10, 20, 5, 22, 23,
["Render", false], 6, 13, 24, 25, 26, 7, 17, 18, 19,
["Render", false], 6, 13, 27, 24, 29, 25, 26, 7, 17, 18, 19,
["Background", true, 8], 9,
];
@ -97,13 +111,21 @@ function Node_Plot_Linear(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
inputs[| 4].setVisible(!_use_path);
inputs[| 10].setVisible(!_use_path);
inputs[| 13].mappableStep();
inputs[| 24].mappableStep();
}
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _use_path = getSingleValue(20) != noone;
if(!_use_path)
inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
if(!_use_path) {
var a = inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
active &= !a;
}
var a = inputs[| 28].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, getSingleValue(0)); active &= !a;
var a = inputs[| 30].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, getSingleValue(0)); active &= !a;
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
@ -136,7 +158,11 @@ function Node_Plot_Linear(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
var _lcl = _data[ 6];
var _cls = _data[13];
var _cls_map = _data[27];
var _cls_rng = _data[28];
var _clv = _data[24];
var _clv_map = _data[29];
var _clv_rng = _data[30];
var _clv_r = _data[25];
var _clv_a = _data[26];
@ -199,11 +225,11 @@ function Node_Plot_Linear(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
_ang_nor = _ang + 90;
_val = _smp_data[i] + _off;
_col_sam = _cls.eval(i / amo);
_col_sam = evaluate_gradient_map(i / amo, _cls, _cls_map, _cls_rng, inputs[| 13]);
var _val_p = _clv_a? abs(_val) : _val;
var _val_prog = (_val_p - _clv_r[0]) / (_clv_r[1] - _clv_r[0]);
_col_val = _clv.eval(_val_prog);
_col_val = evaluate_gradient_map(_val_prog, _clv, _clv_map, _clv_rng, inputs[| 24]);
var _c1 = colorMultiply(_lcl, _col_sam);
var _c2 = _col_val;

View file

@ -39,7 +39,8 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
inputs[| 13] = nodeValue("Path shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
inputs[| 14] = nodeValue("Color over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(cola(c_white)) );
inputs[| 14] = nodeValue("Color over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(cola(c_white)) )
.setMappable(30);
inputs[| 15] = nodeValue("Alpha over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11 );
@ -81,6 +82,14 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
inputs[| 29] = nodeValue("Animator", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 30] = nodeValueMap("Gradient map", self);
inputs[| 31] = nodeValueGradientRange("Gradient map range", self, inputs[| 14]);
//////////////////////////////////////////////////////////////////////////////////////////////////
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [
@ -88,7 +97,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
["Pattern", false], 3, 9, 2, 18, 7, 8,
["Path", true], 11, 12, 13,
["Transform", false], 4, 26, 19, 5, 6, 10,
["Render", false], 14,
["Render", false], 14, 30,
["Animator", true, 29], 20, 21, 25, 22, 23, 24, 27,
];
@ -107,8 +116,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
}
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(inputs[| 9].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, THEME.anchor))
active = false;
var a = inputs[| 9].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, THEME.anchor); active &= !a;
var _pat = getInputData(3);
var _spos = getInputData(9);
@ -117,14 +125,22 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var py = _y + _spos[1] * _s;
if(_pat == 0 || _pat == 1) {
if(inputs[| 4].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny))
active = false;
var a = inputs[| 4].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny);
active &= !a;
} else if(_pat == 2) {
if(inputs[| 8].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny))
active = false;
var a = inputs[| 8].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny);
active &= !a;
}
var a = inputs[| 31].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, getInputData(1)); active &= !a;
}
static step = function() { #region
inputs[| 14].mappableStep();
} #endregion
function doRepeat(_outSurf, _inSurf) {
var _dim = getInputData( 1);
var _amo = getInputData( 2);
@ -146,6 +162,8 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _prsh = getInputData(13);
var _grad = getInputData(14);
var _grad_map = getInputData(30);
var _grad_range = getInputData(31);
var _arr = getInputData(16);
var _sed = getInputData(17);
@ -240,7 +258,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
}
var pos = point_rotate(-sw / 2, -sh / 2, 0, 0, rot);
var cc = _grad.eval(i / (_amo - 1));
var cc = evaluate_gradient_map(i / (_amo - 1), _grad, _grad_map, _grad_range, inputs[| 14]);
var aa = _color_get_alpha(cc);
cc = colda(cc);

View file

@ -40,7 +40,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 10] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, irandom(9999999));
inputs[| 11] = nodeValue("Random blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white) );
inputs[| 11] = nodeValue("Random blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white) )
.setMappable(28);
inputs[| 12] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ])
.setDisplay(VALUE_DISPLAY.slider_range);
@ -86,6 +87,14 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 27] = nodeValue("Animated array end", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Loop", "Ping Pong" ]);
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 28] = nodeValueMap("Gradient map", self);
inputs[| 29] = nodeValueGradientRange("Gradient map range", self, inputs[| 11]);
//////////////////////////////////////////////////////////////////////////////////////////////////
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, [])
@ -96,7 +105,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
["Scatter", false], 5, 6, 13, 14, 17, 9, 2,
["Path", false], 19, 20, 21, 22,
["Transform", false], 3, 8, 7, 4,
["Render", false], 18, 11, 12, 16, 23,
["Render", false], 18, 11, 28, 12, 16, 23,
];
attribute_surface_depth();
@ -105,8 +114,13 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var _distType = current_data[6];
if(_distType < 3)
inputs[| 5].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_distType < 3) {
var a = inputs[| 5].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
active &= !a;
}
var a = inputs[| 29].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, getSingleValue(1)); active &= !a;
} #endregion
static onValueUpdate = function(index) { #region
@ -138,6 +152,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 27].setVisible(_arr);
update_on_frame = _arr && (_amn[0] != 0 || _amn[1] != 0);
inputs[| 11].mappableStep();
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
@ -164,6 +180,9 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
var seed = _data[10];
var color = _data[11];
var clr_map = _data[28];
var clr_rng = _data[29];
var alpha = _data[12];
var _arr = _data[15];
var mulpA = _data[16];
@ -340,7 +359,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
if(vCol && _v != noone)
grSamp *= _v;
var clr = color.eval(grSamp);
var clr = evaluate_gradient_map(grSamp, color, clr_map, clr_rng, inputs[| 11]);
var alp = random_range_seed(alpha[0], alpha[1], posS); posS++;
var _atl = array_safe_get(scatter_data, _sct_len);