Fix palette quick select not showing up but still receive data.

This commit is contained in:
Tanasart 2024-12-14 10:55:49 +07:00
parent 70c9a6f61c
commit 64390ed315
5 changed files with 40 additions and 25 deletions

View file

@ -1,5 +1,5 @@
/// @description
depth = -19999;
depth = -9999;
selecting = noone;
onApply = noone;
onApply = noone;

View file

@ -2,14 +2,14 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
name = "Replace Palette";
newInput(0, nodeValue_Surface("Surface in", self));
newInput(1, nodeValue_Palette("Palette from", self, array_clone(DEF_PALETTE), "Color to be replaced."));
newInput(1, nodeValue_Palette("From", self, array_clone(DEF_PALETTE)));
newInput(2, nodeValue_Palette("Palette to", self, array_clone(DEF_PALETTE), "Palette to be replaced to."));
newInput(2, nodeValue_Palette("To", self, array_clone(DEF_PALETTE)));
newInput(3, nodeValue_Float("Threshold", self, 0.1))
.setDisplay(VALUE_DISPLAY.slider);
newInput(4, nodeValue_Bool("Set others to black", self, false, "Set pixel that doesn't match any color in 'palette from' to black."));
newInput(4, nodeValue_Bool("Replace Other Colors", self, false));
newInput(5, nodeValue_Bool("Multiply alpha", self, true));
@ -31,11 +31,14 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
newInput(14, nodeValueSeed(self));
input_display_list = [ 9, 10, 14,
newInput(15, nodeValue_Color("Target Color", self, cola(c_black)));
input_display_list = [ 9, 10,
["Surfaces", true], 0, 7, 8, 11, 12,
["Palette", false], 1, 2,
["Comparison", false], 13, 3, 5,
["Render", false], 4, 6
["Palettes", false], 1, 2,
["Comparison", false], 13, 14, 3, 5,
["Replace Others", false, 4], 15,
["Render", false], 6
];
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
@ -50,16 +53,20 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
var fr = _data[ 1];
var to = _data[ 2];
var tr = _data[ 3];
var in = _data[ 4];
var alp = _data[ 5];
var hrd = _data[ 6];
var msk = _data[ 7];
var mde = _data[13];
var sed = _data[14];
var repo = _data[ 4];
var oclr = _data[15];
var _colorFrom = paletteToArray(fr);
var _colorTo = paletteToArray(to);
inputs[14].setVisible(mde == 1);
surface_set_shader(_outSurf, sh_palette_replace);
shader_set_f("colorFrom", _colorFrom);
shader_set_i("colorFrom_amo", array_length(fr));
@ -71,7 +78,9 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
shader_set_i("alphacmp", alp);
shader_set_i("hardReplace", hrd);
shader_set_f("treshold", tr);
shader_set_i("inverted", in);
shader_set_i("replaceOthers", repo);
shader_set_color("replaceColor", oclr);
shader_set_i("useMask", is_surface(msk));
shader_set_surface("mask", msk);
@ -80,7 +89,7 @@ function Node_Color_replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
surface_reset_shader();
__process_mask_modifier(_data);
if(!in) _outSurf = mask_apply(_data[0], _outSurf, _data[7], _data[8]);
_outSurf = mask_apply(_data[0], _outSurf, _data[7], _data[8]);
_outSurf = channel_apply(_data[0], _outSurf, _data[10]);
return _outSurf;

View file

@ -237,6 +237,7 @@ function Node_Colors_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
_surf = [ _surf ];
var _pall = ds_map_create();
var _amsk = 0b11111111 << 24;
for( var i = 0, n = array_length(_surf); i < n; i++ ) {
var _s = _surf[i];
@ -244,18 +245,17 @@ function Node_Colors_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
var ww = surface_get_width_safe(_s);
var hh = surface_get_height_safe(_s);
var c_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2);
var aa = ww * hh;
var c_buffer = buffer_create(aa * 4, buffer_fixed, 2);
buffer_get_surface(c_buffer, _s, 0);
buffer_seek(c_buffer, buffer_seek_start, 0);
for( var i = 0; i < ww * hh; i++ ) {
repeat(aa) {
var b = buffer_read(c_buffer, buffer_u32);
var c = b & ~(0b11111111 << 24);
var a = b & (0b11111111 << 24);
if(a == 0) continue;
c = make_color_rgb(color_get_red(c), color_get_green(c), color_get_blue(c));
if((b & _amsk) == 0) continue;
var c = b | _amsk;
_pall[? c] = 1;
}
@ -265,6 +265,8 @@ function Node_Colors_Replace(_x, _y, _group = noone) : Node_Processor(_x, _y, _g
var palette = ds_map_keys_to_array(_pall);
ds_map_destroy(_pall);
if(array_length(palette) <= 128) array_sort(palette, __sortHue);
inputs[1].setValue(palette);
inputs[2].setValue(palette);
}

View file

@ -21,7 +21,7 @@ uniform sampler2D mask;
void main() {
vec4 p = texture2D( gm_BaseTexture, v_vTexcoord );
int index = 0;
int index = 0;
float minDist = 999.;
for(int i = 0; i < colorFromAmount; i++ ) {

View file

@ -20,11 +20,13 @@ uniform int colorTo_amo;
uniform float seed;
uniform int mode;
uniform int inverted;
uniform int alphacmp;
uniform int hardReplace;
uniform float treshold;
uniform int replaceOthers;
uniform vec4 replaceColor;
#region color spaces
vec3 rgb2xyz( vec3 c ) {
@ -76,10 +78,12 @@ float round(float val) { return fract(val) >= 0.5? ceil(val) : floor(val); }
void main() {
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 baseColor;
if(inverted == 0)
if(replaceOthers == 0)
baseColor = col;
else if(inverted == 1) {
baseColor = vec4(vec3(0.), 1.);
else if(replaceOthers == 1) {
baseColor = replaceColor;
if(useMask == 1) {
vec4 m = texture2D( mask, v_vTexcoord );
@ -120,6 +124,6 @@ void main() {
} else
gl_FragColor = baseColor;
if(inverted == 0)
if(replaceOthers == 0)
gl_FragColor.a = col.a;
}