From 9e15e3d8fd85b24721e591fb43c1f2d04fcdc8c9 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 3 Mar 2016 17:16:49 -0800 Subject: [PATCH] libobs: Remove need for DrawMatrix technique in effects (Note: This commit also modifies obs-filters and text-freetype2) This simplifies writing of effects. DrawMatrix is no longer necessary because there are no sources that require drawing with a color matrix other than async sources, and async sources are automatically processed and don't defer their initial render stage to filters. --- libobs/data/default_rect.effect | 20 ---------- libobs/obs-source.c | 33 ++++++----------- libobs/obs-source.h | 9 ----- .../obs-filters/data/blend_add_filter.effect | 25 ------------- .../obs-filters/data/blend_mul_filter.effect | 25 ------------- .../obs-filters/data/blend_sub_filter.effect | 25 ------------- .../obs-filters/data/chroma_key_filter.effect | 21 ----------- plugins/obs-filters/data/color_filter.effect | 21 ----------- .../obs-filters/data/color_key_filter.effect | 21 ----------- .../obs-filters/data/mask_alpha_filter.effect | 25 ------------- .../obs-filters/data/mask_color_filter.effect | 24 ------------ plugins/obs-filters/data/sharpness.effect | 37 ------------------- .../text-freetype2/data/text_default.effect | 19 ---------- 13 files changed, 11 insertions(+), 294 deletions(-) diff --git a/libobs/data/default_rect.effect b/libobs/data/default_rect.effect index b9660b262..e8364ef51 100644 --- a/libobs/data/default_rect.effect +++ b/libobs/data/default_rect.effect @@ -1,7 +1,4 @@ uniform float4x4 ViewProj; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture_rect image; sampler_state def_sampler { @@ -28,13 +25,6 @@ float4 PSDrawBare(VertInOut vert_in) : TARGET return image.Sample(def_sampler, vert_in.uv); } -float4 PSDrawMatrix(VertInOut vert_in) : TARGET -{ - float4 yuv = image.Sample(def_sampler, vert_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - return saturate(mul(float4(yuv.xyz, 1.0), color_matrix)); -} - technique Draw { pass @@ -43,13 +33,3 @@ technique Draw pixel_shader = PSDrawBare(vert_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(vert_in); - pixel_shader = PSDrawMatrix(vert_in); - } -} - diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 4cc306cf9..08a6d00ed 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1606,11 +1606,10 @@ static inline void obs_source_render_filters(obs_source_t *source) source->rendering_filter = false; } -static void obs_source_default_render(obs_source_t *source, bool color_matrix) +static void obs_source_default_render(obs_source_t *source) { gs_effect_t *effect = obs->video.default_effect; - const char *tech_name = color_matrix ? "DrawMatrix" : "Draw"; - gs_technique_t *tech = gs_effect_get_technique(effect, tech_name); + gs_technique_t *tech = gs_effect_get_technique(effect, "Draw"); size_t passes, i; passes = gs_technique_begin(tech); @@ -1626,14 +1625,13 @@ static void obs_source_default_render(obs_source_t *source, bool color_matrix) static inline void obs_source_main_render(obs_source_t *source) { uint32_t flags = source->info.output_flags; - bool color_matrix = (flags & OBS_SOURCE_COLOR_MATRIX) != 0; bool custom_draw = (flags & OBS_SOURCE_CUSTOM_DRAW) != 0; bool default_effect = !source->filter_parent && source->filters.num == 0 && !custom_draw; if (default_effect) - obs_source_default_render(source, color_matrix); + obs_source_default_render(source); else if (source->context.data) source->info.video_render(source->context.data, custom_draw ? NULL : gs_get_effect()); @@ -2594,10 +2592,9 @@ const char *obs_source_get_id(const obs_source_t *source) } static inline void render_filter_bypass(obs_source_t *target, - gs_effect_t *effect, bool use_matrix) + gs_effect_t *effect) { - const char *tech_name = use_matrix ? "DrawMatrix" : "Draw"; - gs_technique_t *tech = gs_effect_get_technique(effect, tech_name); + gs_technique_t *tech = gs_effect_get_technique(effect, "Draw"); size_t passes, i; passes = gs_technique_begin(tech); @@ -2610,10 +2607,9 @@ static inline void render_filter_bypass(obs_source_t *target, } static inline void render_filter_tex(gs_texture_t *tex, gs_effect_t *effect, - uint32_t width, uint32_t height, bool use_matrix) + uint32_t width, uint32_t height) { - const char *tech_name = use_matrix ? "DrawMatrix" : "Draw"; - gs_technique_t *tech = gs_effect_get_technique(effect, tech_name); + gs_technique_t *tech = gs_effect_get_technique(effect, "Draw"); gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image"); size_t passes, i; @@ -2645,7 +2641,6 @@ void obs_source_process_filter_begin(obs_source_t *filter, obs_source_t *target, *parent; uint32_t target_flags, parent_flags; int cx, cy; - bool use_matrix; if (!obs_ptr_valid(filter, "obs_source_process_filter_begin")) return; @@ -2656,7 +2651,6 @@ void obs_source_process_filter_begin(obs_source_t *filter, parent_flags = parent->info.output_flags; cx = get_base_width(target); cy = get_base_height(target); - use_matrix = !!(target_flags & OBS_SOURCE_COLOR_MATRIX); filter->allow_direct = allow_direct; @@ -2690,7 +2684,7 @@ void obs_source_process_filter_begin(obs_source_t *filter, gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f); if (target == parent && !custom_draw && !async) - obs_source_default_render(target, use_matrix); + obs_source_default_render(target); else obs_source_video_render(target); @@ -2706,7 +2700,6 @@ void obs_source_process_filter_end(obs_source_t *filter, gs_effect_t *effect, obs_source_t *target, *parent; gs_texture_t *texture; uint32_t target_flags, parent_flags; - bool use_matrix; if (!obs_ptr_valid(filter, "obs_source_process_filter_end")) return; @@ -2715,15 +2708,13 @@ void obs_source_process_filter_end(obs_source_t *filter, gs_effect_t *effect, parent = obs_filter_get_parent(filter); target_flags = target->info.output_flags; parent_flags = parent->info.output_flags; - use_matrix = !!(target_flags & OBS_SOURCE_COLOR_MATRIX); if (can_bypass(target, parent, parent_flags, filter->allow_direct)) { - render_filter_bypass(target, effect, use_matrix); + render_filter_bypass(target, effect); } else { texture = gs_texrender_get_texture(filter->filter_texrender); if (texture) - render_filter_tex(texture, effect, width, height, - use_matrix); + render_filter_tex(texture, effect, width, height); } } @@ -2732,7 +2723,6 @@ void obs_source_skip_video_filter(obs_source_t *filter) obs_source_t *target, *parent; bool custom_draw, async; uint32_t parent_flags; - bool use_matrix; if (!obs_ptr_valid(filter, "obs_source_skip_video_filter")) return; @@ -2742,11 +2732,10 @@ void obs_source_skip_video_filter(obs_source_t *filter) parent_flags = parent->info.output_flags; custom_draw = (parent_flags & OBS_SOURCE_CUSTOM_DRAW) != 0; async = (parent_flags & OBS_SOURCE_ASYNC) != 0; - use_matrix = !!(parent_flags & OBS_SOURCE_COLOR_MATRIX); if (target == parent) { if (!custom_draw && !async) - obs_source_default_render(target, use_matrix); + obs_source_default_render(target); else if (target->info.video_render) obs_source_main_render(target); else diff --git a/libobs/obs-source.h b/libobs/obs-source.h index c852cebfb..f4b0f809e 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -87,15 +87,6 @@ enum obs_source_type { */ #define OBS_SOURCE_CUSTOM_DRAW (1<<3) -/** - * Source uses a color matrix (usually YUV sources). - * - * When this is used, the video_render callback will automatically assign a - * 4x4 YUV->RGB matrix to the "color_matrix" parameter of the effect, or it can - * be changed to a custom value. - */ -#define OBS_SOURCE_COLOR_MATRIX (1<<4) - /** * Source supports interaction. * diff --git a/plugins/obs-filters/data/blend_add_filter.effect b/plugins/obs-filters/data/blend_add_filter.effect index ccb5107d5..ad7189fa7 100644 --- a/plugins/obs-filters/data/blend_add_filter.effect +++ b/plugins/obs-filters/data/blend_add_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color; @@ -44,19 +41,6 @@ float4 PSAddImageRGBA(VertDataOut v_in) : TARGET return rgba; } -float4 PSAddImageMatrix(VertDataOut v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * - color; - - float4 targetRGB = target.Sample(textureSampler, v_in.uv2); - rgba.rgb = saturate(rgba.rgb + targetRGB.rgb); - return rgba; -} - technique Draw { pass @@ -65,12 +49,3 @@ technique Draw pixel_shader = PSAddImageRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSAddImageMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/blend_mul_filter.effect b/plugins/obs-filters/data/blend_mul_filter.effect index 94bbe5935..c4c793a1d 100644 --- a/plugins/obs-filters/data/blend_mul_filter.effect +++ b/plugins/obs-filters/data/blend_mul_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color; @@ -44,19 +41,6 @@ float4 PSMuliplyImageRGBA(VertDataOut v_in) : TARGET return rgba; } -float4 PSMuliplyImageMatrix(VertDataOut v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * - color; - - float4 targetRGB = target.Sample(textureSampler, v_in.uv2); - rgba.rgb = saturate(rgba.rgb * targetRGB.rgb); - return rgba; -} - technique Draw { pass @@ -65,12 +49,3 @@ technique Draw pixel_shader = PSMuliplyImageRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSMuliplyImageMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/blend_sub_filter.effect b/plugins/obs-filters/data/blend_sub_filter.effect index 5b63329d9..a91aa71cc 100644 --- a/plugins/obs-filters/data/blend_sub_filter.effect +++ b/plugins/obs-filters/data/blend_sub_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color; @@ -44,19 +41,6 @@ float4 PSSubtractImageRGBA(VertDataOut v_in) : TARGET return rgba; } -float4 PSSubtractImageMatrix(VertDataOut v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * - color; - - float4 targetRGB = target.Sample(textureSampler, v_in.uv2); - rgba.rgb = saturate(rgba.rgb - targetRGB.rgb); - return rgba; -} - technique Draw { pass @@ -65,12 +49,3 @@ technique Draw pixel_shader = PSSubtractImageRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSSubtractImageMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/chroma_key_filter.effect b/plugins/obs-filters/data/chroma_key_filter.effect index 79df92522..4ea43ce15 100644 --- a/plugins/obs-filters/data/chroma_key_filter.effect +++ b/plugins/obs-filters/data/chroma_key_filter.effect @@ -1,11 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix = {1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0}; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform float4x4 yuv_mat = { 0.182586, 0.614231, 0.062007, 0.062745, -0.100644, -0.338572, 0.439216, 0.501961, @@ -107,12 +101,6 @@ float4 PSChromaKeyRGBA(VertData v_in) : TARGET return ProcessChromaKey(rgba, v_in, false); } -float4 PSChromaKeyMatrix(VertData v_in) : TARGET -{ - float4 rgba = SampleYUVToRGB(v_in.uv) * color; - return ProcessChromaKey(rgba, v_in, true); -} - technique Draw { pass @@ -121,12 +109,3 @@ technique Draw pixel_shader = PSChromaKeyRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSChromaKeyMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/color_filter.effect b/plugins/obs-filters/data/color_filter.effect index 712ca4b95..5f4eecdd5 100644 --- a/plugins/obs-filters/data/color_filter.effect +++ b/plugins/obs-filters/data/color_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform float4 color; uniform float contrast; @@ -39,15 +36,6 @@ float4 PSColorFilterRGBA(VertData v_in) : TARGET return CalcColor(rgba); } -float4 PSColorFilterMatrix(VertData v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * color; - - return CalcColor(rgba); -} - technique Draw { pass @@ -56,12 +44,3 @@ technique Draw pixel_shader = PSColorFilterRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSColorFilterMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/color_key_filter.effect b/plugins/obs-filters/data/color_key_filter.effect index 7d611ec56..599d08841 100644 --- a/plugins/obs-filters/data/color_key_filter.effect +++ b/plugins/obs-filters/data/color_key_filter.effect @@ -1,11 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix = {1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0}; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform float4 color; uniform float contrast; @@ -67,12 +61,6 @@ float4 PSColorKeyRGBA(VertData v_in) : TARGET return ProcessColorKey(rgba, v_in); } -float4 PSColorKeyMatrix(VertData v_in) : TARGET -{ - float4 rgba = SampleYUVToRGB(v_in.uv) * color; - return ProcessColorKey(rgba, v_in); -} - technique Draw { pass @@ -81,12 +69,3 @@ technique Draw pixel_shader = PSColorKeyRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSColorKeyMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/mask_alpha_filter.effect b/plugins/obs-filters/data/mask_alpha_filter.effect index 72f3d7a9a..7e9d5138e 100644 --- a/plugins/obs-filters/data/mask_alpha_filter.effect +++ b/plugins/obs-filters/data/mask_alpha_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color; @@ -44,19 +41,6 @@ float4 PSAlphaMaskRGBA(VertDataOut v_in) : TARGET return rgba; } -float4 PSAlphaMaskMatrix(VertDataOut v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * - color; - - float4 targetRGB = target.Sample(textureSampler, v_in.uv2); - rgba.a = targetRGB.a; - return rgba; -} - technique Draw { pass @@ -65,12 +49,3 @@ technique Draw pixel_shader = PSAlphaMaskRGBA(v_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSAlphaMaskMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/mask_color_filter.effect b/plugins/obs-filters/data/mask_color_filter.effect index 6e0ab7e72..6822a2f34 100644 --- a/plugins/obs-filters/data/mask_color_filter.effect +++ b/plugins/obs-filters/data/mask_color_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color; @@ -44,19 +41,6 @@ float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET return rgba; } -float4 PSColorMaskMatrix(VertDataOut v_in) : TARGET -{ - float4 yuv = image.Sample(textureSampler, v_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - - float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) * - color; - - float4 targetRGB = target.Sample(textureSampler, v_in.uv2); - rgba.a = (targetRGB.r + targetRGB.g + targetRGB.b) / 3.0; - return rgba; -} - technique Draw { pass @@ -66,11 +50,3 @@ technique Draw } } -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSColorMaskMatrix(v_in); - } -} diff --git a/plugins/obs-filters/data/sharpness.effect b/plugins/obs-filters/data/sharpness.effect index b27e90a72..54a023ef9 100644 --- a/plugins/obs-filters/data/sharpness.effect +++ b/plugins/obs-filters/data/sharpness.effect @@ -3,9 +3,6 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d target; uniform float4 color = {1.0, 1.0, 1.0, 1.0}; @@ -74,31 +71,6 @@ float4 PSDrawBare(VertOut vert_in) : TARGET return colorx; } -float4 PSDrawMatrix(VertOut vert_in) : TARGET -{ - float4 E = image.Sample(def_sampler, vert_in.uv); - - float4 colorx = 8*E; - float4 B = image.Sample(def_sampler, vert_in.t1.yw); - float4 D = image.Sample(def_sampler, vert_in.t2.xw); - float4 F = image.Sample(def_sampler, vert_in.t2.zw); - float4 H = image.Sample(def_sampler, vert_in.t3.yw); - colorx -= image.Sample(def_sampler, vert_in.t1.xw); - colorx -= B; - colorx -= image.Sample(def_sampler, vert_in.t1.zw); - colorx -= D; - colorx -= F; - colorx -= image.Sample(def_sampler, vert_in.t3.xw); - colorx -= H; - colorx -= image.Sample(def_sampler, vert_in.t3.zw); - - colorx = ((E!=F && E!=D) || (E!=B && E!=H)) ? saturate(E + colorx*sharpness) : E; - - float4 yuv = colorx; - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - return saturate(mul(float4(yuv.xyz, 1.0), color_matrix)); -} - technique Draw { pass @@ -107,12 +79,3 @@ technique Draw pixel_shader = PSDrawBare(vert_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(vert_in); - pixel_shader = PSDrawMatrix(vert_in); - } -} diff --git a/plugins/text-freetype2/data/text_default.effect b/plugins/text-freetype2/data/text_default.effect index 968041610..8792f1a15 100644 --- a/plugins/text-freetype2/data/text_default.effect +++ b/plugins/text-freetype2/data/text_default.effect @@ -1,7 +1,4 @@ uniform float4x4 ViewProj; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform texture2d image; sampler_state def_sampler { @@ -30,13 +27,6 @@ float4 PSDrawBare(VertInOut vert_in) : TARGET return image.Sample(def_sampler, vert_in.uv) * vert_in.col; } -float4 PSDrawMatrix(VertInOut vert_in) : TARGET -{ - float4 yuv = image.Sample(def_sampler, vert_in.uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - return saturate(mul(float4(yuv.xyz, 1.0), color_matrix)); -} - technique Draw { pass @@ -45,12 +35,3 @@ technique Draw pixel_shader = PSDrawBare(vert_in); } } - -technique DrawMatrix -{ - pass - { - vertex_shader = VSDefault(vert_in); - pixel_shader = PSDrawMatrix(vert_in); - } -} -- GitLab