[Displace] Iterate mode now accumulate color.

This commit is contained in:
Tanasart 2024-12-23 10:59:30 +07:00
parent 31069d8067
commit 89149e7dec
11 changed files with 199 additions and 196 deletions

Binary file not shown.

View file

@ -14,82 +14,88 @@ event_inherited();
textbox = noone;
prompt = "";
data = [];
font = f_code;
pre_mx = 0;
pre_my = 0;
show_items = 8;
pad_item = 6;
destroy_on_escape = false;
destroy_on_click_out = false;
function activate(textbox) {
INLINE
self.textbox = textbox;
self.selecting = 0;
function activate(_textbox) {
textbox = _textbox;
selecting = 0;
}
function deactivate(textbox) {
INLINE
if(textbox != self.textbox) return;
self.textbox = noone;
function deactivate(_textbox) {
if(textbox != _textbox) return;
textbox = noone;
}
sc_content = new scrollPane(dialog_w, dialog_h, function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hght = line_get_height(f_p0, 8);
draw_clear_alpha(COLORS.panel_bg_clear, 1);
var hght = line_get_height(font, pad_item);
var _dw = sc_content.surface_w;
var _h = 0;
var _ly = _y;
var _mmove = pre_mx != _m[0] || pre_my != _m[1];
for(var i = 0; i < array_length(data); i++) {
gpu_set_tex_filter(true);
for( var i = 0, n = array_length(data); i < n; i++ ) {
var _dat = data[i];
if(sHOVER && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
selecting = i;
if(mouse_press(mb_left)) {
applyAutoComplete(_dat[3]);
MOUSE_BLOCK = true;
}
if(_mmove) selecting = i;
if(mouse_press(mb_left)) { applyAutoComplete(_dat[3]); MOUSE_BLOCK = true; break; }
}
if(selecting == i) {
WIDGET_TAB_BLOCK = true;
draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
if(keyboard_check_pressed(vk_tab) || keyboard_check_pressed(vk_enter))
applyAutoComplete(_dat[3]);
if(keyboard_check_pressed(vk_tab) || keyboard_check_pressed(vk_enter)) { applyAutoComplete(_dat[3]); break; }
}
var icn = _dat[0][0];
var ss = 16 / sprite_get_width(icn);
draw_sprite_ext(icn, _dat[0][1], ui(4 + 12), _ly + hght / 2, ss, ss, 0, c_white, 1);
if(sprite_exists(icn)) {
var ss = (hght - ui(8)) / sprite_get_width(icn);
draw_sprite_ext(icn, _dat[0][1], ui(4 + 12), _ly + hght / 2, ss, ss, 0, c_white, 1);
}
draw_set_text(f_p2, fa_right, fa_center, COLORS._main_text_sub);
draw_text_cut(_dw - ui(8), _ly + hght / 2 - ui(2), _dat[2], _dw);
BLEND_ALPHA_MULP
draw_set_text(font, fa_right, fa_center, COLORS._main_text_sub);
draw_text(round(_dw - ui(8)), round(_ly + hght / 2), _dat[2]);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
draw_text_cut(ui(4 + 24 + 4), _ly + hght / 2 - ui(2), _dat[1], _dw);
draw_set_text(font, fa_left, fa_center, CDEF.main_white);
draw_text(round(ui(4 + 24 + 4)), round(_ly + hght / 2), _dat[1]);
BLEND_NORMAL
_ly += hght;
_h += hght;
}
gpu_set_tex_filter(false);
if(keyboard_check_pressed(vk_up)) {
selecting--;
if(selecting < 0) selecting = array_length(data) - 1;
sc_content.scroll_y_to = -(selecting - 2) * hght;
if(KEYBOARD_PRESSED == vk_up) {
selecting = (selecting - 1 + n) % n;
sc_content.scroll_y_to = max(sc_content.scroll_y_to, -selecting * hght);
if(selecting == n - 1) sc_content.scroll_y_to = -(selecting - show_items + 1) * hght;
}
if(keyboard_check_pressed(vk_down)) {
selecting++
if(selecting >= array_length(data) - 1) selecting = 0;
sc_content.scroll_y_to = -(selecting - 2) * hght;
if(KEYBOARD_PRESSED == vk_down) {
selecting = (selecting + 1) % n;
sc_content.scroll_y_to = min(sc_content.scroll_y_to, -(selecting - show_items + 1) * hght);
if(selecting == 0) sc_content.scroll_y_to = -selecting * hght;
}
pre_mx = _m[0];
pre_my = _m[1];
return _h;
});
sc_content.scroll_inertia = 0;
function applyAutoComplete(rep) {
var _totAmo = string_length(textbox._input_text);
var _prmAmo = string_length(prompt);

View file

@ -5,30 +5,28 @@ if(textbox != WIDGET_CURRENT) exit;
if(array_empty(data)) exit;
if(dialog_x == 0 && dialog_y == 0) exit;
#region
#region dialog
dialog_x = clamp(dialog_x, 0, WIN_W - dialog_w - 1);
dialog_y = clamp(dialog_y, 0, WIN_H - dialog_h - 1);
var _w = 300;
var _h = array_length(data) * line_get_height(f_p0, 8);
var _w = 300;
var _h = min(show_items, array_length(data)) * line_get_height(font, pad_item);
for( var i = 0, n = array_length(data); i < n; i++ ) {
var _dat = data[i];
var __w = ui(40 + 32);
draw_set_font(f_p2);
draw_set_font(font);
__w += string_width(_dat[2]);
draw_set_font(f_p0);
__w += string_width(_dat[1]);
_w = max(_w, __w);
}
dialog_w = _w;
dialog_h = min(_h, 160);
dialog_w = _w + 6;
dialog_h = _h;
sc_content.resize(dialog_w, dialog_h);
sc_content.resize(_w, dialog_h);
#endregion
#region draw
@ -38,6 +36,5 @@ if(dialog_x == 0 && dialog_y == 0) exit;
draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h);
#endregion
if(keyboard_check_pressed(vk_escape))
textbox = noone;

View file

@ -46,6 +46,7 @@
SAVE_VERSION = 1_18_05_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.6.011";
BUILD_NUMBER = 1_18_05_6;
PREF_VERSION = 1_17_1;
var _vsp = string_split(VERSION_STRING, ".");
var _lsp = _vsp[array_length(_vsp) - 1];

View file

@ -987,7 +987,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
targ.setFrom(junctionFrom);
}
static getInputData = function(index, def = 0) { return inputs[index].getValue(); } /// array_safe_get_fast(inputs_data, index, def); }
static getInputDataFull = function(index, def = 0) { return array_safe_get_fast(inputs_data, index, def); }
static getInputDataLite = function(index, def = 0) { return inputs[index].getValue(); }
static getInputDataForce = function(index, def = 0) { return inputs[index].getValue(); }
// static setInputData = function(index, value) {
@ -1027,6 +1028,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
setRenderStatus(true);
if(attributes.update_graph) {
getInputs(frame);
try { update(frame); }
catch(e) { log_warning("RENDER", exception_print(e), self); }
}
@ -1092,7 +1095,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
LOG_BLOCK_END();
}
doUpdate = doUpdateFull;
doUpdate = doUpdateFull;
getInputData = getInputDataFull;
static valueUpdate = function(index) {
onValueUpdate(index);

View file

@ -53,11 +53,15 @@ If set, then strength value control how many times the effect applies on itself.
newInput(17, nodeValue_Surface("Displace map 2", self));
newInput(18, nodeValue_Int("Iteration", self, 32));
newInput(19, nodeValue_Bool("Fade distance", self, false));
input_display_list = [ 10, 12,
["Surfaces", true], 0, 8, 9, 13, 14,
["Strength", false], 1, 17, 3, 15, 4,
["Displacement", false], 5, 16, 2,
["Algorithm", true], 6, 11,
["Algorithm", true], 6, 11, 18, 19,
];
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
@ -121,9 +125,12 @@ If set, then strength value control how many times the effect applies on itself.
shader_set_f_map("strength", _data[ 3], _data[15], inputs[3]);
shader_set_f("middle", _data[ 4]);
shader_set_i("mode", _data[ 5]);
shader_set_i("sepAxis", _data[16]);
shader_set_i("iterate", _data[ 6]);
shader_set_i("blendMode", _data[11]);
shader_set_i("sepAxis", _data[16]);
shader_set_i("fadeDist", _data[19]);
shader_set_f("iteration", _data[18]);
draw_surface_safe(_data[0]);
surface_reset_shader();

View file

@ -207,60 +207,42 @@
if(array_length(strs) == 1) {
var _var = strs[0];
var splt = string_splice(_var, "[");
var inp = PROJECT.globalNode.getInputKey(_var);
if(inp == noone) {
noti_warning($"Variable {_var} not found.");
return 0;
}
var inp = PROJECT.globalNode.getInputKey(_var);
if(inp == noone) { noti_warning($"Variable {_var} not found."); return 0; }
var _arr = [ 0, 0 ];
inp.getValueRecursive(_arr);
return _arr[0];
} else if(struct_has(PROJECT_VARIABLES, strs[0])) {
}
if(struct_has(PROJECT_VARIABLES, strs[0])) {
var _cat = strs[0];
var _fnc = strs[1];
var _str_var = PROJECT_VARIABLES[$ _cat];
if(!struct_has(_str_var, _fnc)) {
noti_warning($"Variable {_fnc} not found.");
return 0;
}
if(!struct_has(_str_var, _fnc)) { noti_warning($"Variable {_fnc} not found."); return 0; }
var val = _str_var[$ _fnc][0];
if(is_callable(val))
return val();
return val;
} else if(array_length(strs) > 2) {
return is_callable(val)? val() : val;
}
if(array_length(strs) > 2) {
var key = strs[0];
if(!ds_map_exists(PROJECT.nodeNameMap, key)) return 0;
var node = PROJECT.nodeNameMap[? key];
var map = noone;
switch(string_lower(strs[1])) {
case "inputs" :
case "input" :
map = node.inputMap;
break;
case "outputs" :
case "output" :
map = node.outputMap;
break;
case2_mf0/* */"inputs" case2_mf1 "input" case2_mf2 : map = node.inputMap; break;
case2_mf0/* */"outputs" case2_mf1 "output" case2_mf2 : map = node.outputMap; break;
default : return 0;
}
var _junc_key = string_lower(strs[2]);
var _junc = ds_map_try_get(map, _junc_key, noone);
var _junc = struct_try_get(map, _junc_key, noone);
if(_junc == noone) { noti_warning($"Junction {_junc_key} not found."); return 0; }
if(_junc == noone) {
noti_warning($"Junction {_junc_key} not found.")
return 0;
}
return _junc.getValue();
}
@ -272,36 +254,30 @@
var strs = string_splice(str, ".");
if(array_length(strs) == 0) return 0;
if(array_length(strs) == 1) return EXPRESS_TREE_ANIM.none;
if(array_length(strs) == 1) {
return EXPRESS_TREE_ANIM.none;
} else if(struct_has(PROJECT_VARIABLES, strs[0])) {
if(struct_has(PROJECT_VARIABLES, strs[0])) {
var _str_var = PROJECT_VARIABLES[$ strs[0]];
if(!struct_has(_str_var, strs[1])) return EXPRESS_TREE_ANIM.none;
var val = _str_var[$ strs[1]][1];
return val;
} else if(array_length(strs) > 2) {
}
if(array_length(strs) > 2) {
var key = strs[0];
if(!ds_map_exists(PROJECT.nodeNameMap, key)) return EXPRESS_TREE_ANIM.none;
var node = PROJECT.nodeNameMap[? key];
var map = noone;
switch(string_lower(strs[1])) {
case "inputs" :
case "input" :
map = node.inputMap;
break;
case "outputs" :
case "output" :
map = node.outputMap;
break;
case2_mf0/* */"inputs" case2_mf1 "input" case2_mf2 : map = node.inputMap; break;
case2_mf0/* */"outputs" case2_mf1 "output" case2_mf2 : map = node.outputMap; break;
default : return EXPRESS_TREE_ANIM.none;
}
var _junc_key = string_lower(strs[2]);
var _junc = ds_map_try_get(map, _junc_key, noone);
var _junc = struct_try_get(map, _junc_key, noone);
if(_junc == noone) return EXPRESS_TREE_ANIM.none;
return _junc.is_anim * 2;

View file

@ -3,8 +3,7 @@ global.PCX_CONSTANT = [ "value", "self" ];
function pxl_document_parser(prompt) {
var params = [];
var lines = string_split(prompt, "\n");
var lines = string_split(prompt, "\n");
for( var i = 0, n = array_length(lines); i < n; i++ ) {
var line = lines[i];
@ -21,6 +20,76 @@ function pxl_document_parser(prompt) {
return params;
}
function pxl_autocomplete_server_node(prompt, pr_list) {
var sp = string_splice(prompt, ".");
if(array_length(sp) <= 1) return;
if(struct_has(PROJECT_VARIABLES, sp[0])) {
var _glo_var = PROJECT_VARIABLES[$ sp[0]];
var _arr = variable_struct_get_names(_glo_var);
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _key = _arr[i];
var match = string_partial_match(string_lower(_key), string_lower(sp[1]));
if(match == -9999 && sp[1] != "")
continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 0], _key, sp[0], $"{sp[0]}.{_key}"], match);
}
}
if(sp[0] == "self" && array_length(sp) == 2) {
var _val = context[$ "node_values"];
var _arr = variable_struct_get_names(_val);
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _key = _arr[i];
var match = string_partial_match(string_lower(_key), string_lower(sp[1]));
if(match == -9999 && sp[1] != "")
continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 2], _key, "self", $"{sp[0]}.{_key}"], match);
}
}
if(ds_map_exists(PROJECT.nodeNameMap, sp[0])) {
if(array_length(sp) == 2) {
for( var i = 0, n = array_length(global.NODE_SUB_CATAG); i < n; i++ ) {
var gl = global.NODE_SUB_CATAG[i];
var match = string_partial_match(string_lower(gl), string_lower(sp[1]));
if(match == -9999 && sp[1] != "") continue;
ds_priority_add(pr_list, [[THEME.ac_node, i], gl, sp[0], $"{sp[0]}.{gl}"], match);
}
} else if(array_length(sp) == 3) {
var node = PROJECT.nodeNameMap[? sp[0]];
var F = noone;
var tag = "";
switch(string_lower(sp[1])) {
case2_mf0/* */"inputs" case2_mf1 "input" case2_mf2 : tag = "input"; F = node.inputMap; break;
case2_mf0/* */"outputs" case2_mf1 "output" case2_mf2 : tag = "output"; F = node.outputMap; break;
}
if(!is_struct(F)) return;
var ks = struct_get_names(F);
for( var i = 0, n = array_length(ks); i < n; i++ ) {
var k = ks[i];
var match = string_partial_match(string_lower(k), string_lower(sp[2]));
if(match == -9999 && sp[2] != "") continue;
var fn = F[$ k];
ds_priority_add(pr_list, [fn.junction_drawing, k, $"{sp[0]}.{tag}", $"{sp[0]}.{sp[1]}.{k}"], match);
}
}
}
}
function pxl_autocomplete_server(prompt, params = [], context = {}) {
if(isNumber(prompt)) return [];
@ -99,77 +168,7 @@ function pxl_autocomplete_server(prompt, params = [], context = {}) {
//////////////////////////////////
ds_priority_clear(pr_list);
var sp = string_splice(prompt, ".");
if(array_length(sp) > 1) {
if(struct_has(PROJECT_VARIABLES, sp[0])) {
var _glo_var = PROJECT_VARIABLES[$ sp[0]];
var _arr = variable_struct_get_names(_glo_var);
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _key = _arr[i];
var match = string_partial_match(string_lower(_key), string_lower(sp[1]));
if(match == -9999 && sp[1] != "")
continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 0], _key, sp[0], $"{sp[0]}.{_key}"], match);
}
} else if(sp[0] == "self" && array_length(sp) == 2) {
var _val = context[$ "node_values"];
var _arr = variable_struct_get_names(_val);
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _key = _arr[i];
var match = string_partial_match(string_lower(_key), string_lower(sp[1]));
if(match == -9999 && sp[1] != "")
continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 2], _key, "self", $"{sp[0]}.{_key}"], match);
}
} else if(ds_map_exists(PROJECT.nodeNameMap, sp[0])) {
if(array_length(sp) == 2) {
for( var i = 0, n = array_length(global.NODE_SUB_CATAG); i < n; i++ ) {
var gl = global.NODE_SUB_CATAG[i];
var match = string_partial_match(string_lower(gl), string_lower(sp[1]));
if(match == -9999 && sp[1] != "") continue;
ds_priority_add(pr_list, [[THEME.ac_node, i], gl, sp[0], $"{sp[0]}.{gl}"], match);
}
} else if(array_length(sp) == 3) {
var node = PROJECT.nodeNameMap[? sp[0]];
var F = noone;
var tag = "";
switch(string_lower(sp[1])) {
case "inputs" :
case "input" :
F = node.inputMap;
tag = "input";
break;
case "outputs" :
case "output" :
F = node.outputMap;
tag = "output";
break;
default : return 0;
}
var k = ds_map_find_first(F);
var a = ds_map_size(F);
repeat(a) {
var match = string_partial_match(string_lower(k), string_lower(sp[2]));
if(match == -9999 && sp[2] != "") {
k = ds_map_find_next(F, k);
continue;
}
var fn = F[? k];
ds_priority_add(pr_list, [fn.junction_drawing, k, sp[0] + "." + tag, $"{sp[0]}.{sp[1]}.{k}"], match);
k = ds_map_find_next(F, k);
}
}
}
}
pxl_autocomplete_server_node(prompt, pr_list);
repeat(ds_priority_size(pr_list))
array_push(res, ds_priority_delete_max(pr_list));

View file

@ -255,7 +255,6 @@
#region save load
globalvar PREF_VERSION, PREF_UPDATES;
PREF_VERSION = 1_17_1;
PREF_UPDATES = [
{
version: 0,

View file

@ -1,8 +1,4 @@
function scrollPane(_w, _h, ondraw) : widget() constructor {
scroll_y = 0;
scroll_y_raw = 0;
scroll_y_to = 0;
whover = false;
wactive = false;
@ -22,11 +18,16 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
show_scroll = true;
scroll_resize = true;
scroll_y = 0;
scroll_y_raw = 0;
scroll_y_to = 0;
scroll_step = 64;
scroll_lock = false;
is_scrolling = false;
scroll_ms = 0;
is_scrolling = false;
scroll_ms = 0;
scroll_inertia = 5;
pen_scrolling = false;
pen_scroll_my = 0;
@ -80,7 +81,7 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
/// Scrolling
scroll_y_to = clamp(scroll_y_to, -content_h, 0);
scroll_y_raw = lerp_float(scroll_y_raw, scroll_y_to, 4);
scroll_y_raw = scroll_inertia > 0? lerp_float(scroll_y_raw, scroll_y_to, scroll_inertia) : scroll_y_to;
scroll_y = round(scroll_y_raw);
draw_surface_safe(surface, x, y);

View file

@ -99,18 +99,21 @@ uniform vec2 dimension;
uniform vec2 map_dimension;
uniform vec2 displace;
uniform float middle;
uniform int iterate;
uniform int mode;
uniform int blendMode;
uniform int sepAxis;
uniform int iterate;
uniform float iteration;
uniform int blendMode;
uniform int fadeDist;
uniform vec2 strength;
uniform int strengthUseSurf;
uniform sampler2D strengthSurf;
float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * col.a; }
vec2 shiftMap(in vec2 pos, in float str) { #region
vec2 shiftMap(in vec2 pos, in float str) {
vec2 tx = 1. / dimension;
vec4 disP = texture2Dintp( map, pos );
vec2 raw_displace = displace * tx;
@ -161,26 +164,30 @@ vec2 shiftMap(in vec2 pos, in float str) { #region
}
return sam_pos;
} #endregion
}
vec4 blend(in vec4 c0, in vec4 c1) { #region
if(blendMode == 0) return c1;
else if(blendMode == 1) {
vec4 blend(in vec4 c0, in vec4 c1) {
if(blendMode == 0) return c1;
if(blendMode == 1) {
float b0 = bright(c0);
float b1 = bright(c1);
return b0 < b1? c0 : c1;
} else if(blendMode == 2) {
}
if(blendMode == 2) {
float b0 = bright(c0);
float b1 = bright(c1);
return b0 > b1? c0 : c1;
}
return c1;
} #endregion
}
void main() { #region
void main() {
vec2 samPos = v_vTexcoord;
vec4 ccol = sampleTexture( gm_BaseTexture, v_vTexcoord ), ncol;
vec4 ccol = sampleTexture( gm_BaseTexture, v_vTexcoord );
vec4 ncol = ccol;
float stren = strength.x;
float stMax = strength.x;
@ -191,11 +198,17 @@ void main() { #region
}
if(iterate == 1) {
for(float i = 0.; i < stMax; i++) {
if(i >= stren) break;
float _t = 1. / (iteration - 1.);
float str;
vec4 c;
for(float i = 0.; i < iteration; i++) {
str = stren * (i * _t);
samPos = shiftMap(v_vTexcoord, str);
c = sampleTexture( gm_BaseTexture, samPos );
if(fadeDist == 1) c.rgb *= 1. - i * _t;
samPos = shiftMap(samPos, min(1., stren - i));
ncol = blend(ccol, sampleTexture( gm_BaseTexture, samPos ));
ncol = blend(ncol, c);
}
} else {
samPos = shiftMap(samPos, stren);
@ -203,4 +216,4 @@ void main() { #region
}
gl_FragColor = blend(ccol, ncol);
} #endregion
}