2019-03-07 05:53:15 +01:00
|
|
|
uniform float4x4 ViewProj;
|
|
|
|
uniform float2 base_dimension_i;
|
|
|
|
uniform texture2d image;
|
|
|
|
|
|
|
|
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 PSDrawAreaRGBA(VertInOut vert_in) : TARGET
|
|
|
|
{
|
|
|
|
float4 totalcolor = float4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
2019-03-22 17:10:31 +01:00
|
|
|
float2 uv = vert_in.uv;
|
|
|
|
float2 uvdelta = float2(ddx(uv.x), ddy(uv.y));
|
2019-03-07 05:53:15 +01:00
|
|
|
|
2019-04-04 11:57:46 +02:00
|
|
|
// Handle potential OpenGL flip.
|
|
|
|
uvdelta.y = abs(uvdelta.y);
|
|
|
|
|
2019-03-22 17:10:31 +01:00
|
|
|
float2 uvhalfdelta = 0.5 * uvdelta;
|
|
|
|
float2 uvmin = uv - uvhalfdelta;
|
|
|
|
float2 uvmax = uv + uvhalfdelta;
|
2019-03-07 05:53:15 +01:00
|
|
|
|
2019-03-22 17:10:31 +01:00
|
|
|
int2 loadindexmin = int2(uvmin / base_dimension_i);
|
|
|
|
int2 loadindexmax = int2(uvmax / base_dimension_i);
|
2019-03-07 05:53:15 +01:00
|
|
|
|
2019-03-22 17:10:31 +01:00
|
|
|
float2 targetpos = uv / uvdelta;
|
2019-04-04 11:57:46 +02:00
|
|
|
float2 targetposmin = targetpos - 0.5;
|
|
|
|
float2 targetposmax = targetpos + 0.5;
|
|
|
|
float2 scale = base_dimension_i / uvdelta;
|
2019-03-07 05:53:15 +01:00
|
|
|
for (int loadindexy = loadindexmin.y; loadindexy <= loadindexmax.y; ++loadindexy)
|
|
|
|
{
|
|
|
|
for (int loadindexx = loadindexmin.x; loadindexx <= loadindexmax.x; ++loadindexx)
|
|
|
|
{
|
2019-04-04 11:57:46 +02:00
|
|
|
int2 loadindex = int2(loadindexx, loadindexy);
|
|
|
|
float2 potentialtargetmin = float2(loadindex) * scale;
|
|
|
|
float2 potentialtargetmax = potentialtargetmin + scale;
|
|
|
|
float2 targetmin = max(potentialtargetmin, targetposmin);
|
|
|
|
float2 targetmax = min(potentialtargetmax, targetposmax);
|
2019-03-22 17:10:31 +01:00
|
|
|
float area = (targetmax.x - targetmin.x) * (targetmax.y - targetmin.y);
|
2019-04-04 11:57:46 +02:00
|
|
|
float4 sample = image.Load(int3(loadindex, 0));
|
libobs: Fix various alpha issues
There are cases where alpha is multiplied unnecessarily. This change
attempts to use premultiplied alpha blending for composition.
To keep this change simple, The filter chain will continue to use
straight alpha. Otherwise, every source would need to modified to output
premultiplied, and every filter modified for premultiplied input.
"DrawAlphaDivide" shader techniques have been added to convert from
premultiplied alpha to straight alpha for final output. "DrawMatrix"
techniques ignore alpha, so they do not appear to need changing.
One remaining issue is that scale effects are set up here to use the
same shader logic for both scale filters (straight alpha - incorrectly),
and output composition (premultiplied alpha - correctly). A fix could be
made to add additional shaders for straight alpha, but the "real" fix
may be to eliminate the straight alpha path at some point.
For graphics, SrcBlendAlpha and DestBlendAlpha were both ONE, and could
combine together to form alpha values greater than one. This is not as
noticeable of a problem for UNORM targets because the channels are
clamped, but it will likely become a problem in more situations if FLOAT
targets are used.
This change switches DestBlendAlpha to INVSRCALPHA. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.
obs-transitions: Use premultiplied alpha blend, and simplify shaders
because both inputs and outputs use premultiplied alpha now.
Fixes https://obsproject.com/mantis/view.php?id=1108
2019-05-03 12:54:17 +02:00
|
|
|
totalcolor += area * sample;
|
2019-03-07 05:53:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
libobs: Fix various alpha issues
There are cases where alpha is multiplied unnecessarily. This change
attempts to use premultiplied alpha blending for composition.
To keep this change simple, The filter chain will continue to use
straight alpha. Otherwise, every source would need to modified to output
premultiplied, and every filter modified for premultiplied input.
"DrawAlphaDivide" shader techniques have been added to convert from
premultiplied alpha to straight alpha for final output. "DrawMatrix"
techniques ignore alpha, so they do not appear to need changing.
One remaining issue is that scale effects are set up here to use the
same shader logic for both scale filters (straight alpha - incorrectly),
and output composition (premultiplied alpha - correctly). A fix could be
made to add additional shaders for straight alpha, but the "real" fix
may be to eliminate the straight alpha path at some point.
For graphics, SrcBlendAlpha and DestBlendAlpha were both ONE, and could
combine together to form alpha values greater than one. This is not as
noticeable of a problem for UNORM targets because the channels are
clamped, but it will likely become a problem in more situations if FLOAT
targets are used.
This change switches DestBlendAlpha to INVSRCALPHA. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.
obs-transitions: Use premultiplied alpha blend, and simplify shaders
because both inputs and outputs use premultiplied alpha now.
Fixes https://obsproject.com/mantis/view.php?id=1108
2019-05-03 12:54:17 +02:00
|
|
|
return totalcolor;
|
2019-03-07 05:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
technique Draw
|
|
|
|
{
|
|
|
|
pass
|
|
|
|
{
|
|
|
|
vertex_shader = VSDefault(vert_in);
|
|
|
|
pixel_shader = PSDrawAreaRGBA(vert_in);
|
|
|
|
}
|
|
|
|
}
|