Commit f66ac83c authored by Lynne's avatar Lynne

overlay_vulkan: add support for overlaying images with an alpha channel

parent 4e813243
...@@ -59,11 +59,27 @@ static const char overlay_noalpha[] = { ...@@ -59,11 +59,27 @@ static const char overlay_noalpha[] = {
C(0, } ) C(0, } )
}; };
static const char overlay_alpha[] = {
C(0, void overlay_alpha_opaque(int i, ivec2 pos) )
C(0, { )
C(1, vec4 res = texture(main_img[i], pos); )
C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
(pos.x < (o_offset[i].x + o_size[i].x)) &&
(pos.y < (o_offset[i].y + o_size[i].y))) { )
C(2, vec4 ovr = texture(overlay_img[i], pos - o_offset[i]); )
C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )
C(2, res.a = 1.0f; )
C(2, imageStore(output_img[i], pos, res); )
C(1, } )
C(1, imageStore(output_img[i], pos, res); )
C(0, } )
};
static av_cold int init_filter(AVFilterContext *ctx) static av_cold int init_filter(AVFilterContext *ctx)
{ {
int err; int err;
OverlayVulkanContext *s = ctx->priv; OverlayVulkanContext *s = ctx->priv;
VkSampler *sampler = ff_vk_init_sampler(ctx, 1, VK_FILTER_LINEAR); VkSampler *sampler = ff_vk_init_sampler(ctx, 1, VK_FILTER_NEAREST);
if (!sampler) if (!sampler)
return AVERROR_EXTERNAL; return AVERROR_EXTERNAL;
...@@ -73,6 +89,7 @@ static av_cold int init_filter(AVFilterContext *ctx) ...@@ -73,6 +89,7 @@ static av_cold int init_filter(AVFilterContext *ctx)
{ /* Create the shader */ { /* Create the shader */
const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
const int ialpha = av_pix_fmt_desc_get(s->vkctx.input_format)->flags & AV_PIX_FMT_FLAG_ALPHA;
VulkanDescriptorSetBinding desc_i[3] = { VulkanDescriptorSetBinding desc_i[3] = {
{ {
...@@ -126,11 +143,15 @@ static av_cold int init_filter(AVFilterContext *ctx) ...@@ -126,11 +143,15 @@ static av_cold int init_filter(AVFilterContext *ctx)
RET(ff_vk_add_descriptor_set(ctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */ RET(ff_vk_add_descriptor_set(ctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */
GLSLD( overlay_noalpha ); GLSLD( overlay_noalpha );
GLSLD( overlay_alpha );
GLSLC(0, void main() ); GLSLC(0, void main() );
GLSLC(0, { ); GLSLC(0, { );
GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); ); GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
GLSLF(1, int planes = %i; ,planes); GLSLF(1, int planes = %i; ,planes);
GLSLC(1, for (int i = 0; i < planes; i++) { ); GLSLC(1, for (int i = 0; i < planes; i++) { );
if (ialpha)
GLSLC(2, overlay_alpha_opaque(i, pos); );
else
GLSLC(2, overlay_noalpha(i, pos); ); GLSLC(2, overlay_noalpha(i, pos); );
GLSLC(1, } ); GLSLC(1, } );
GLSLC(0, } ); GLSLC(0, } );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment