Skip to content

Commit

Permalink
Fixes frame check and adjustment masks for all shapes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FiniteSingularity committed Nov 29, 2023
1 parent 9294a88 commit f761738
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 28 deletions.
33 changes: 31 additions & 2 deletions data/shaders/circle-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -95,6 +115,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
29 changes: 27 additions & 2 deletions data/shaders/ellipse-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,33 @@ 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, 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));
Expand Down Expand Up @@ -136,6 +152,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
28 changes: 26 additions & 2 deletions data/shaders/heart-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,32 @@ 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) - 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));
Expand Down Expand Up @@ -114,6 +129,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
28 changes: 27 additions & 1 deletion data/shaders/polygon-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -106,6 +123,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
28 changes: 27 additions & 1 deletion data/shaders/rectangular-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,6 +130,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
28 changes: 26 additions & 2 deletions data/shaders/star-mask.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -115,6 +130,15 @@ technique Alpha
}
}

technique AlphaFrameCheck
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = alphaFrameCheckImage(v_in);
}
}

technique Adjustments
{
pass
Expand Down
54 changes: 36 additions & 18 deletions src/mask-shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit f761738

Please sign in to comment.