libobs: Add premultiplied alpha base effect
parent
50961861c7
commit
96d848f3d2
|
@ -0,0 +1,38 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
|
||||
sampler_state def_sampler {
|
||||
Filter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertInOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertInOut VSDefault(VertInOut vert_in)
|
||||
{
|
||||
VertInOut vert_out;
|
||||
vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = vert_in.uv;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSDraw(VertInOut vert_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(def_sampler, vert_in.uv);
|
||||
if (rgba.a > 0.0)
|
||||
rgba.rgb /= rgba.a;
|
||||
return saturate(rgba);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSDraw(vert_in);
|
||||
}
|
||||
}
|
|
@ -237,6 +237,7 @@ struct obs_core_video {
|
|||
gs_effect_t *bicubic_effect;
|
||||
gs_effect_t *lanczos_effect;
|
||||
gs_effect_t *bilinear_lowres_effect;
|
||||
gs_effect_t *premultiplied_alpha_effect;
|
||||
gs_stagesurf_t *mapped_surface;
|
||||
int cur_texture;
|
||||
|
||||
|
|
|
@ -291,6 +291,11 @@ static int obs_init_graphics(struct obs_video_info *ovi)
|
|||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
filename = find_libobs_data_file("premultiplied_alpha.effect");
|
||||
video->premultiplied_alpha_effect = gs_effect_create_from_file(filename,
|
||||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
obs->video.transparent_texture = gs_texture_create(2, 2, GS_RGBA, 1,
|
||||
&transparent_tex, 0);
|
||||
|
||||
|
@ -306,6 +311,8 @@ static int obs_init_graphics(struct obs_video_info *ovi)
|
|||
success = false;
|
||||
if (!video->conversion_effect)
|
||||
success = false;
|
||||
if (!video->premultiplied_alpha_effect)
|
||||
success = false;
|
||||
if (!video->transparent_texture)
|
||||
success = false;
|
||||
|
||||
|
@ -1351,6 +1358,8 @@ gs_effect_t *obs_get_base_effect(enum obs_base_effect effect)
|
|||
return obs->video.lanczos_effect;
|
||||
case OBS_EFFECT_BILINEAR_LOWRES:
|
||||
return obs->video.bilinear_lowres_effect;
|
||||
case OBS_EFFECT_PREMULTIPLIED_ALPHA:
|
||||
return obs->video.premultiplied_alpha_effect;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -521,6 +521,7 @@ enum obs_base_effect {
|
|||
OBS_EFFECT_BICUBIC, /**< Bicubic downscale */
|
||||
OBS_EFFECT_LANCZOS, /**< Lanczos downscale */
|
||||
OBS_EFFECT_BILINEAR_LOWRES, /**< Bilinear low resolution downscale */
|
||||
OBS_EFFECT_PREMULTIPLIED_ALPHA,/**< Premultiplied alpha */
|
||||
};
|
||||
|
||||
/** Returns a commonly used base effect */
|
||||
|
|
Loading…
Reference in New Issue