From 4cb634bd8ba5eb945112488632cbf2cd49eba2f9 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 11 Jul 2024 14:23:34 +0700 Subject: [PATCH] - [Invert] Add option to invert alpha. --- scripts/node_invert/node_invert.gml | 26 ++++++++++++-------------- scripts/vectorBox/vectorBox.gml | 2 +- shaders/sh_invert/sh_invert.fsh | 9 +++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/scripts/node_invert/node_invert.gml b/scripts/node_invert/node_invert.gml index 1657c3af8..87633d73d 100644 --- a/scripts/node_invert/node_invert.gml +++ b/scripts/node_invert/node_invert.gml @@ -16,7 +16,9 @@ function Node_Invert(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co __init_mask_modifier(1); // inputs 5, 6 - input_display_list = [ 3, 4, + inputs[| 7] = nodeValue("Include Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + + input_display_list = [ 3, 4, 7, ["Surfaces", true], 0, 1, 2, 5, 6, ] @@ -24,26 +26,22 @@ function Node_Invert(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co attribute_surface_depth(); - static step = function() { #region + static step = function() { __step_mask_modifier(); - } #endregion + } - static processData = function(_outSurf, _data, _output_index, _array_index) { #region - surface_set_target(_outSurf); - DRAW_CLEAR - BLEND_OVERRIDE; - - shader_set(sh_invert); + static processData = function(_outSurf, _data, _output_index, _array_index) { + + surface_set_shader(_outSurf, sh_invert); + shader_set_i("alpha", _data[7]); + draw_surface_safe(_data[0]); - shader_reset(); - - BLEND_NORMAL; - surface_reset_target(); + surface_reset_shader(); __process_mask_modifier(_data); _outSurf = mask_apply(_data[0], _outSurf, _data[1], _data[2]); _outSurf = channel_apply(_data[0], _outSurf, _data[4]); return _outSurf; - } #endregion + } } \ No newline at end of file diff --git a/scripts/vectorBox/vectorBox.gml b/scripts/vectorBox/vectorBox.gml index 213cfb1cc..0c478f861 100644 --- a/scripts/vectorBox/vectorBox.gml +++ b/scripts/vectorBox/vectorBox.gml @@ -118,7 +118,7 @@ function vectorBox(_size, _onModify, _unit = noone) : widget() constructor { var sz = min(size, array_length(_data)); var _bs = min(_h, ui(32)); - if(unit) for(var i = 0; i < sz; i++) tb[i].slide_int = unit.mode == VALUE_UNIT.constant? true : false; + if(unit && unit.reference != noone) for(var i = 0; i < sz; i++) tb[i].slide_int = unit.mode == VALUE_UNIT.constant? true : false; if((_w - _bs) / sz > ui(48)) { if(side_button) { diff --git a/shaders/sh_invert/sh_invert.fsh b/shaders/sh_invert/sh_invert.fsh index 40b7a2c39..424093005 100644 --- a/shaders/sh_invert/sh_invert.fsh +++ b/shaders/sh_invert/sh_invert.fsh @@ -1,10 +1,11 @@ -// -// Simple passthrough fragment shader -// varying vec2 v_vTexcoord; varying vec4 v_vColour; +uniform int alpha; + void main() { vec4 c = texture2D( gm_BaseTexture, v_vTexcoord ); - gl_FragColor = vec4(1. - c.rgb, c.a); + + if(alpha == 0) gl_FragColor = vec4(1. - c.rgb, c.a); + else if(alpha == 1) gl_FragColor = 1. - c; }