From 7c0addead892338251099d8fabf2bb97530aed7d Mon Sep 17 00:00:00 2001 From: FiniteSingularity <72580859+FiniteSingularity@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:18:50 -0600 Subject: [PATCH] Fixes frame check and adjustment masks for all shapes. (#36) --- data/shaders/circle-mask.effect | 33 +++++++++++++++-- data/shaders/ellipse-mask.effect | 29 +++++++++++++-- data/shaders/heart-mask.effect | 28 +++++++++++++-- data/shaders/polygon-mask.effect | 28 ++++++++++++++- data/shaders/rectangular-mask.effect | 28 ++++++++++++++- data/shaders/star-mask.effect | 28 +++++++++++++-- src/mask-shape.c | 54 ++++++++++++++++++---------- 7 files changed, 200 insertions(+), 28 deletions(-) diff --git a/data/shaders/circle-mask.effect b/data/shaders/circle-mask.effect index 1239456..a9daa41 100644 --- a/data/shaders/circle-mask.effect +++ b/data/shaders/circle-mask.effect @@ -56,16 +56,36 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); } -float4 adjustmentsImage(VertData v_in) : TARGET +float4 alphaFrameCheckImage(VertData v_in) : TARGET { float2 coord = v_in.uv * uv_size; float2 shift = global_position - mask_position; float2 coord_p = coord - shift; float2 dist = coord_p - mask_position; float d = SDF(dist, radius); + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); +} + +float4 adjustmentsImage(VertData v_in) : TARGET +{ + //float2 coord = v_in.uv * uv_size; + //float2 dist = coord - mask_position; + //float2 sample_dist = float2(dist.x * cos_theta - dist.y * sin_theta, dist.x * sin_theta + dist.y * cos_theta); + //float d = SDF(sample_dist, float2(width, height), corner_radius) + feather_shift; + //d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d) : saturate(-d); + + float2 coord = v_in.uv * uv_size; + float2 dist = coord - mask_position; + float d = SDF(dist, radius); d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, v_in.uv)); @@ -95,6 +115,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/data/shaders/ellipse-mask.effect b/data/shaders/ellipse-mask.effect index 1da6679..6f0575d 100644 --- a/data/shaders/ellipse-mask.effect +++ b/data/shaders/ellipse-mask.effect @@ -96,10 +96,10 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); } -float4 adjustmentsImage(VertData v_in) : TARGET +float4 alphaFrameCheckImage(VertData v_in) : TARGET { float2 coord = v_in.uv * uv_size; float2 shift = global_position - mask_position; @@ -107,6 +107,22 @@ float4 adjustmentsImage(VertData v_in) : TARGET float2 dist = coord_p - mask_position; float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); float d = SDF(sample_dist, ellipse); + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); +} + +float4 adjustmentsImage(VertData v_in) : TARGET +{ + + float2 coord = v_in.uv * uv_size; + float2 dist = coord - mask_position; + float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); + float d = SDF(sample_dist, ellipse); d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, v_in.uv)); @@ -136,6 +152,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/data/shaders/heart-mask.effect b/data/shaders/heart-mask.effect index 1039b24..93487a4 100644 --- a/data/shaders/heart-mask.effect +++ b/data/shaders/heart-mask.effect @@ -74,10 +74,10 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); } -float4 adjustmentsImage(VertData v_in) : TARGET +float4 alphaFrameCheckImage(VertData v_in) : TARGET { float2 coord = v_in.uv * uv_size; float2 shift = global_position - mask_position; @@ -85,6 +85,21 @@ float4 adjustmentsImage(VertData v_in) : TARGET float2 dist = coord_p - mask_position; float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); float d = SDF(sample_dist) - corner_radius; + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); +} + +float4 adjustmentsImage(VertData v_in) : TARGET +{ + float2 coord = v_in.uv * uv_size; + float2 dist = coord - mask_position; + float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); + float d = SDF(sample_dist) - corner_radius; d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, v_in.uv)); @@ -114,6 +129,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/data/shaders/polygon-mask.effect b/data/shaders/polygon-mask.effect index 0474f3b..27db053 100644 --- a/data/shaders/polygon-mask.effect +++ b/data/shaders/polygon-mask.effect @@ -69,7 +69,24 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); +} + +float4 alphaFrameCheckImage(VertData v_in) : TARGET +{ + float2 coord = v_in.uv * uv_size; + float2 shift = global_position - mask_position; + float2 coord_p = coord - shift; + float2 dist = coord_p - mask_position; + float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); + float d = SDF(sample_dist, num_sides, radius) - corner_radius; + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); } float4 adjustmentsImage(VertData v_in) : TARGET @@ -106,6 +123,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/data/shaders/rectangular-mask.effect b/data/shaders/rectangular-mask.effect index 2cf1301..3c13249 100644 --- a/data/shaders/rectangular-mask.effect +++ b/data/shaders/rectangular-mask.effect @@ -76,7 +76,24 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); +} + +float4 alphaFrameCheckImage(VertData v_in) : TARGET +{ + float2 coord = v_in.uv * uv_size; + float2 shift = global_position - mask_position; + float2 coord_p = coord - shift; + float2 dist = coord_p - mask_position; + float2 sample_dist = float2(dist.x * cos_theta - dist.y * sin_theta, dist.x * sin_theta + dist.y * cos_theta); + float d = SDF(sample_dist, float2(width, height), corner_radius); + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); } float4 adjustmentsImage(VertData v_in) : TARGET @@ -113,6 +130,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/data/shaders/star-mask.effect b/data/shaders/star-mask.effect index 3793208..801406d 100644 --- a/data/shaders/star-mask.effect +++ b/data/shaders/star-mask.effect @@ -75,16 +75,31 @@ float4 alphaImage(VertData v_in) : TARGET d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); - return float4(color.rgb, color.a * max(d, alpha_zero)); + return float4(color.rgb, color.a * d); } -float4 adjustmentsImage(VertData v_in) : TARGET +float4 alphaFrameCheckImage(VertData v_in) : TARGET { float2 coord = v_in.uv * uv_size; float2 shift = global_position - mask_position; float2 coord_p = coord - shift; float2 dist = coord_p - mask_position; float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); + float d = SDF(sample_dist, radius) - corner_radius; + float2 sample_uv = (mask_position + dist / zoom / global_scale) / uv_size; + float alpha_scale = sample_uv.x >= 0.0f && sample_uv.x <= 1.0f && + sample_uv.y >= 0.0f && sample_uv.y <= 1.0f ? 1.0f : 0.0f; + d = feather_amount > 0.0f ? smoothstep(alpha_zero * alpha_scale, feather_amount, -d + feather_amount) : clamp(-d, alpha_zero * alpha_scale, 1.0f); + + float4 color = pmrgba_to_rgba(image.Sample(textureSampler, (mask_position + dist / zoom / global_scale) / uv_size)); + return float4(color.rgb, color.a * d); +} + +float4 adjustmentsImage(VertData v_in) : TARGET +{ + float2 coord = v_in.uv * uv_size; + float2 dist = coord - mask_position; + float2 sample_dist = float2(dist.x * cos_rot - dist.y * sin_rot, dist.x * sin_rot + dist.y * cos_rot); float d = SDF(dist, radius) - corner_radius; d = feather_amount > 0.0f ? smoothstep(0.0f, feather_amount, -d + feather_amount) : saturate(-d); @@ -115,6 +130,15 @@ technique Alpha } } +technique AlphaFrameCheck +{ + pass + { + vertex_shader = mainTransform(v_in); + pixel_shader = alphaFrameCheckImage(v_in); + } +} + technique Adjustments { pass diff --git a/src/mask-shape.c b/src/mask-shape.c index 2f7bc63..6174d6d 100644 --- a/src/mask-shape.c +++ b/src/mask-shape.c @@ -1265,9 +1265,12 @@ static void render_rectangle_mask(mask_shape_data_t *data, } set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) { @@ -1441,9 +1444,12 @@ static void render_polygon_mask(mask_shape_data_t *data, } set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) { @@ -1614,9 +1620,12 @@ static void render_star_mask(mask_shape_data_t *data, base_filter_data_t *base, } set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) { @@ -1767,9 +1776,12 @@ static void render_circle_mask(mask_shape_data_t *data, set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) { @@ -1934,9 +1946,12 @@ static void render_heart_mask(mask_shape_data_t *data, base_filter_data_t *base, set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) { @@ -2096,9 +2111,12 @@ static void render_ellipse_mask(mask_shape_data_t *data, set_blending_parameters(); - const char *technique = base->mask_effect == MASK_EFFECT_ALPHA - ? "Alpha" - : "Adjustments"; + const char *technique = + base->mask_effect == MASK_EFFECT_ALPHA && !data->frame_check + ? "Alpha" + : base->mask_effect == MASK_EFFECT_ALPHA && data->frame_check + ? "AlphaFrameCheck" + : "Adjustments"; if (gs_texrender_begin(base->output_texrender, base->width, base->height)) {