mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 06:26:42 +01:00
Fix alpha blending error when using custom channel mix.
This commit is contained in:
parent
da3c628ec2
commit
1b10d98962
3 changed files with 26 additions and 29 deletions
|
@ -5,6 +5,7 @@
|
|||
#region macro
|
||||
#macro BLEND_NORMAL gpu_set_blendmode(bm_normal); gpu_set_blendequation(bm_eq_add);
|
||||
#macro BLEND_ADD gpu_set_blendmode(bm_add);
|
||||
#macro BLEND_ADD_ONE gpu_set_blendmode_ext(bm_one, bm_one);
|
||||
#macro BLEND_OVERRIDE gpu_set_blendmode_ext(bm_one, bm_zero);
|
||||
//#macro BLEND_ADD_ALPHA gpu_set_blendmode_ext_sepalpha(bm_one, bm_inv_src_alpha, bm_one, bm_one)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function __init_mask_modifier(_mask_index) { #region
|
||||
function __init_mask_modifier(_mask_index) {
|
||||
var _ind = array_length(inputs);
|
||||
|
||||
newInput(_ind + 0, nodeValue_Bool("Invert mask", self, false));
|
||||
|
@ -10,20 +10,20 @@ function __init_mask_modifier(_mask_index) { #region
|
|||
__mask_mod_index = _ind;
|
||||
__mask_invert = false;
|
||||
__mask_feather = 0;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function __step_mask_modifier() { #region
|
||||
function __step_mask_modifier() {
|
||||
var _msk = is_surface(getSingleValue(__mask_index));
|
||||
inputs[__mask_mod_index + 0].setVisible(_msk);
|
||||
inputs[__mask_mod_index + 1].setVisible(_msk);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function __process_mask_modifier(data) { #region
|
||||
function __process_mask_modifier(data) {
|
||||
__mask_invert = data[__mask_mod_index + 0];
|
||||
__mask_feather = data[__mask_mod_index + 1];
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function mask_modify(mask, invert = false, feather = 0) { #region
|
||||
function mask_modify(mask, invert = false, feather = 0) {
|
||||
if(!is_surface(mask)) return mask;
|
||||
if(!invert && feather == 0) return mask;
|
||||
|
||||
|
@ -42,9 +42,9 @@ function mask_modify(mask, invert = false, feather = 0) { #region
|
|||
}
|
||||
|
||||
return __temp_mask;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function mask_apply(original, edited, mask, mix = 1) { #region
|
||||
function mask_apply(original, edited, mask, mix = 1) {
|
||||
if(!is_surface(mask) && mix == 1) return edited;
|
||||
|
||||
var _f = surface_get_format(edited);
|
||||
|
@ -69,9 +69,9 @@ function mask_apply(original, edited, mask, mix = 1) { #region
|
|||
|
||||
surface_free(edited);
|
||||
return _s;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function channel_apply(original, edited, channel) { #region
|
||||
function channel_apply(original, edited, channel) {
|
||||
if(channel == 0b1111) return edited;
|
||||
|
||||
var _f = surface_get_format(edited);
|
||||
|
@ -79,13 +79,13 @@ function channel_apply(original, edited, channel) { #region
|
|||
|
||||
surface_set_target(_s);
|
||||
DRAW_CLEAR
|
||||
BLEND_ADD
|
||||
BLEND_ADD_ONE
|
||||
|
||||
gpu_set_colorwriteenable(!(channel & 0b0001), !(channel & 0b0010), !(channel & 0b0100), !(channel & 0b1000));
|
||||
draw_surface_safe(original);
|
||||
draw_surface(original, 0, 0);
|
||||
|
||||
gpu_set_colorwriteenable(channel & 0b0001, channel & 0b0010, channel & 0b0100, channel & 0b1000);
|
||||
draw_surface_safe(edited);
|
||||
draw_surface(edited, 0, 0);
|
||||
|
||||
gpu_set_colorwriteenable(1, 1, 1, 1);
|
||||
BLEND_NORMAL
|
||||
|
@ -93,4 +93,4 @@ function channel_apply(original, edited, channel) { #region
|
|||
|
||||
surface_free(edited);
|
||||
return _s;
|
||||
} #endregion
|
||||
}
|
|
@ -13,24 +13,17 @@ uniform int normalized;
|
|||
vec4 sampleTexture(vec2 pos) {
|
||||
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
|
||||
return texture2D(gm_BaseTexture, pos);
|
||||
|
||||
if(sampleMode == 0)
|
||||
return vec4(0.);
|
||||
|
||||
else if(sampleMode == 1)
|
||||
return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
|
||||
|
||||
else if(sampleMode == 2)
|
||||
return texture2D(gm_BaseTexture, fract(pos));
|
||||
|
||||
else if(sampleMode == 3)
|
||||
return vec4(vec3(0.), 1.);
|
||||
if(sampleMode == 0) return vec4(0.);
|
||||
else if(sampleMode == 1) return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
|
||||
else if(sampleMode == 2) return texture2D(gm_BaseTexture, fract(pos));
|
||||
else if(sampleMode == 3) return vec4(vec3(0.), 1.);
|
||||
|
||||
return vec4(0.);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 tex = 1. / dimension;
|
||||
vec2 tx = 1. / dimension;
|
||||
float sum = 1.;
|
||||
|
||||
if(normalized == 1) {
|
||||
|
@ -47,9 +40,12 @@ void main() {
|
|||
for(int i = 0; i < size; i++)
|
||||
for(int j = 0; j < size; j++) {
|
||||
int index = i * size + j;
|
||||
vec2 px = v_vTexcoord + vec2((float(j) + st) * tex.x, (float(i) + st) * tex.y);
|
||||
vec2 px = v_vTexcoord + vec2((float(j) + st) * tx.x, (float(i) + st) * tx.y);
|
||||
|
||||
c += kernel[index] * sampleTexture(px) / sum;
|
||||
float w = kernel[index];
|
||||
if(w == 0.) continue;
|
||||
|
||||
c += w * sampleTexture(px) / sum;
|
||||
}
|
||||
|
||||
gl_FragColor = c;
|
||||
|
|
Loading…
Reference in a new issue