[Level] Fix alpha multiplication.

This commit is contained in:
Tanasart 2024-09-05 10:50:10 +07:00
parent c457dc0dd9
commit e26b141841
5 changed files with 44 additions and 37 deletions

View File

@ -6,7 +6,7 @@ function Node_Colorize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
newInput(1, nodeValue_Gradient("Gradient", self, new gradientObject([ cola(c_black), cola(c_white) ])))
.setMappable(11);
newInput(2, nodeValue_Float("Gradient shift", self, 0))
newInput(2, nodeValue_Float("Gradient Shift", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [ -1, 1, .01 ] })
.setMappable(10);
@ -18,7 +18,7 @@ function Node_Colorize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
newInput(5, nodeValue_Bool("Active", self, true));
active_index = 5;
newInput(6, nodeValue_Bool("Multiply alpha", self, true));
newInput(6, nodeValue_Bool("Multiply Alpha", self, true));
newInput(7, nodeValue_Toggle("Channel", self, 0b1111, { data: array_create(4, THEME.inspector_channel) }));
@ -34,9 +34,11 @@ function Node_Colorize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
//////////////////////////////////////////////////////////////////////////////////////////////////
newInput(13, nodeValue_Bool("Keep Alpha", self, true));
input_display_list = [ 5, 7,
["Surfaces", true], 0, 3, 4, 8, 9,
["Colorize", false], 1, 11, 2, 10, 6,
["Colorize", false], 1, 11, 2, 10, 6, 13,
];
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
@ -58,11 +60,15 @@ function Node_Colorize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _mlAlp = _data[ 6];
var _kpAlp = _data[13];
surface_set_shader(_outSurf, sh_colorize);
shader_set_gradient(_data[1], _data[11], _data[12], inputs[1]);
shader_set_f_map("gradient_shift", _data[2], _data[10], inputs[2]);
shader_set_i("multiply_alpha", _data[6]);
shader_set_i("multiply_alpha", _mlAlp);
shader_set_i("keep_alpha", _kpAlp);
draw_surface_safe(_data[0]);
surface_reset_shader();

View File

@ -39,7 +39,7 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
attribute_surface_depth();
level_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
level_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
var _h = 128;
var x0 = _x;
var x1 = _x + _w;
@ -70,7 +70,7 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
draw_rectangle(x0, y0, x1, y1, true);
return _h;
}); #endregion
});
input_display_list = [ 8, 9,
level_renderer,
@ -88,19 +88,19 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
histogramUpdate(current_data[0]);
}
static onValueFromUpdate = function(index) { #region
static onValueFromUpdate = function(index) {
if(index == 0) {
doUpdate();
if(array_length(current_data) > 0)
histogramUpdate(current_data[0]);
}
} #endregion
}
static step = function() { #region
static step = function() {
__step_mask_modifier();
} #endregion
}
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _wi = _data[1];
var _ri = _data[2];
var _gi = _data[3];
@ -113,7 +113,7 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
var _bo = _data[15];
var _ao = _data[16];
surface_set_shader(_outSurf, sh_level);
surface_set_shader(_outSurf, sh_level, true, BLEND.over);
shader_set_2("lwi", _wi);
shader_set_2("lri", _ri);
shader_set_2("lgi", _gi);
@ -134,5 +134,5 @@ function Node_Level(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
_outSurf = channel_apply(_data[0], _outSurf, _data[9]);
return _outSurf;
} #endregion
}
}

View File

@ -767,12 +767,12 @@ function __initNodes() {
addNodeObject(generator, "Stripe", s_node_stripe, "Node_Stripe", [1, Node_Stripe],, "Generate stripe pattern.");
addNodeObject(generator, "Zigzag", s_node_zigzag, "Node_Zigzag", [1, Node_Zigzag],, "Generate zigzag pattern.");
addNodeObject(generator, "Checker", s_node_checker, "Node_Checker", [1, Node_Checker],, "Generate checkerboard pattern.");
addNodeObject(generator, "Grid", s_node_grid, "Node_Grid", [1, Node_Grid], ["tile"], "Generate grid pattern.");
addNodeObject(generator, "Grid", s_node_grid, "Node_Grid", [1, Node_Grid], ["tile", "mosaic"], "Generate grid pattern.");
addNodeObject(generator, "Triangular Grid", s_node_grid_tri, "Node_Grid_Tri", [1, Node_Grid_Tri],, "Generate triangular grid pattern.");
addNodeObject(generator, "Hexagonal Grid", s_node_grid_hex, "Node_Grid_Hex", [1, Node_Grid_Hex],, "Generate hexagonal grid pattern.");
addNodeObject(generator, "Pentagonal Grid", s_node_grid_pentagonal, "Node_Grid_Pentagonal", [1, Node_Grid_Pentagonal],, "Generate Pentagonal grid pattern.").patreonExtra();
addNodeObject(generator, "Pytagorean Tile", s_node_pytagorean_tile, "Node_Pytagorean_Tile", [1, Node_Pytagorean_Tile],, "Generate Pytagorean tile pattern.").patreonExtra();
addNodeObject(generator, "Herringbone Tile", s_node_herringbone_tile, "Node_Herringbone_Tile", [1, Node_Herringbone_Tile],, "Generate Herringbone tile pattern.").patreonExtra();
addNodeObject(generator, "Herringbone Tile", s_node_herringbone_tile, "Node_Herringbone_Tile", [1, Node_Herringbone_Tile], "Generate Herringbone tile pattern.").patreonExtra();
addNodeObject(generator, "Random Tile", s_node_random_tile, "Node_Random_Tile", [1, Node_Random_Tile],, "Generate Random tile pattern.").patreonExtra();
addNodeObject(generator, "Box Pattern", s_node_box_pattern, "Node_Box_Pattern", [1, Node_Box_Pattern],, "Generate square-based patterns..").setVersion(11750);
addNodeObject(generator, "Quasicrystal", s_node_quasicircle, "Node_Quasicrystal", [1, Node_Quasicrystal],, "Generate Quasicrystal pattern.").setVersion(11660);

View File

@ -2,6 +2,7 @@ varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform int multiply_alpha;
uniform int keep_alpha;
uniform vec2 gradient_shift;
uniform int gradient_shiftUseSurf;
@ -142,25 +143,25 @@ uniform sampler2D gradient_shiftSurf;
#endregion //////////////////////////////////// GRADIENT ////////////////////////////////////
void main() { #region
void main() {
float shf = gradient_shift.x;
if(gradient_shiftUseSurf == 1) {
vec4 _vMap = texture2D( gradient_shiftSurf, v_vTexcoord );
shf = mix(gradient_shift.x, gradient_shift.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
vec4 _col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
vec4 _col = texture2D( gm_BaseTexture, v_vTexcoord );
float prog = abs(dot(_col.rgb, vec3(0.2126, 0.7152, 0.0722)) + shf);
if(multiply_alpha == 1)
prog *= _col.a;
if(prog > 1.) {
if(prog == floor(prog))
prog = 1.;
else
prog = fract(prog);
}
if(prog > 1.)
prog = prog == floor(prog)? 1. : fract(prog);
vec4 col = gradientEval(prog);
if(keep_alpha == 1)
col.a = _col.a;
gl_FragColor = col;
} #endregion
}