1
0
Эх сурвалжийг харах

libobs: Render async video with DrawNonlinearAlpha

Match previous OBS alpha behavior.

DrawNonlinearAlpha requires premultiplied alpha blend state.
jpark37 4 жил өмнө
parent
commit
aed52412d4
1 өөрчлөгдсөн 14 нэмэгдсэн , 1 устгасан
  1. 14 1
      libobs/obs-source.c

+ 14 - 1
libobs/obs-source.c

@@ -2056,17 +2056,30 @@ static void obs_source_draw_async_texture(struct obs_source *source)
 {
 	gs_effect_t *effect = gs_get_effect();
 	bool def_draw = (!effect);
+	bool premultiplied = false;
 	gs_technique_t *tech = NULL;
 
 	if (def_draw) {
 		effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
-		tech = gs_effect_get_technique(effect, "Draw");
+		const bool linear = gs_get_linear_srgb();
+		const char *tech_name = linear ? "DrawNonlinearAlpha" : "Draw";
+		premultiplied = linear;
+		tech = gs_effect_get_technique(effect, tech_name);
 		gs_technique_begin(tech);
 		gs_technique_begin_pass(tech, 0);
 	}
 
+	if (premultiplied) {
+		gs_blend_state_push();
+		gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
+	}
+
 	obs_source_draw_texture(source, effect);
 
+	if (premultiplied) {
+		gs_blend_state_pop();
+	}
+
 	if (def_draw) {
 		gs_technique_end_pass(tech);
 		gs_technique_end(tech);