gfx-shader: Actually write alpha channel to render target

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-04-24 06:06:46 +02:00 committed by Michael Fabian Dirks
parent c4b4cbdafd
commit 93207d4655
3 changed files with 105 additions and 2 deletions

View file

@ -0,0 +1,53 @@
// This file is used to test features.
uniform float4x4 ViewProj<
bool automatic = true;
>;
uniform float4 Time<
bool automatic = true;
>;
uniform texture2d InputA<
bool automatic = true;
>;
struct VertexData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
sampler_state def_sampler {
AddressU = Wrap;
AddressV = Wrap;
Filter = Linear;
};
VertexData VSDefault(VertexData vtx) {
vtx.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj);
return vtx;
}
float4 PSSolid(VertexData vtx) : TARGET {
return InputA.Sample(def_sampler, vtx.uv) * float4(cos(Time.y * 3.141 * 2.) * .5 + .5, cos(sin(Time.y * 3.141 * 2.) * 3.141), sin(Time.y * 3.141 * 2.) * .5 + .5, 1.);
}
technique Solid
{
pass
{
vertex_shader = VSDefault(vtx);
pixel_shader = PSSolid(vtx);
}
}
float4 PSTranslucent(VertexData vtx) : TARGET {
return InputA.Sample(def_sampler, vtx.uv) * float4(1., 1., 1., sin(Time.y * 3.141 * 2.) * .5 + .5);
}
technique Translucent
{
pass
{
vertex_shader = VSDefault(vtx);
pixel_shader = PSTranslucent(vtx);
}
}

View file

@ -0,0 +1,44 @@
// This file is used to test features.
uniform float4x4 ViewProj<
bool automatic = true;
>;
uniform float4 Time<
bool automatic = true;
>;
struct VertexData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertexData VSDefault(VertexData vtx) {
vtx.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj);
return vtx;
}
float4 PSSolid(VertexData vtx) : TARGET {
return float4(cos(Time.y * 3.141 * 2.) * .5 + .5, cos(sin(Time.y * 3.141 * 2.) * 3.141), sin(Time.y * 3.141 * 2.) * .5 + .5, 1.);
}
technique Solid
{
pass
{
vertex_shader = VSDefault(vtx);
pixel_shader = PSSolid(vtx);
}
}
float4 PSTranslucent(VertexData vtx) : TARGET {
return float4(1., 1., 1., sin(Time.y * 3.141 * 2.) * .5 + .5);
}
technique Translucent
{
pass
{
vertex_shader = VSDefault(vtx);
pixel_shader = PSTranslucent(vtx);
}
}

View file

@ -477,12 +477,18 @@ void gfx::shader::shader::render()
vec4 zero = {0, 0, 0, 0};
gs_ortho(0, width(), 0, height(), 0, 1);
gs_clear(GS_CLEAR_COLOR, &zero, 0, 0);
gs_blend_state_push();
gs_reset_blend_state();
gs_enable_blending(true);
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
gs_blend_function_separate(GS_BLEND_SRCCOLOR, GS_BLEND_ZERO, GS_BLEND_SRCALPHA, GS_BLEND_ZERO);
gs_enable_color(true, true, true, true);
while (gs_effect_loop(_shader.get_object(), _shader_tech.c_str())) {
gs_draw_sprite(nullptr, 0, width(), height());
}
gs_blend_state_pop();
}
gs_effect_set_texture(gs_effect_get_param_by_name(obs_get_base_effect(OBS_EFFECT_DEFAULT), "image"),