2010-05-24 19:28:51 +04:00
|
|
|
float4x4 mLayerTransform;
|
|
|
|
float4 vRenderTargetOffset;
|
|
|
|
float4x4 mProjection;
|
|
|
|
|
2010-09-08 07:27:38 +04:00
|
|
|
typedef float4 rect;
|
|
|
|
rect vTextureCoords;
|
2010-10-02 02:24:58 +04:00
|
|
|
rect vLayerQuad;
|
2012-03-07 01:09:19 +04:00
|
|
|
rect vMaskQuad;
|
2010-09-08 07:27:38 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
texture tex0;
|
|
|
|
sampler s2D;
|
2011-01-03 04:48:09 +03:00
|
|
|
sampler s2DWhite;
|
2010-05-24 19:28:51 +04:00
|
|
|
sampler s2DY;
|
|
|
|
sampler s2DCb;
|
|
|
|
sampler s2DCr;
|
2014-07-03 04:48:18 +04:00
|
|
|
sampler s2DMask;
|
2012-03-07 01:09:19 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
|
|
|
|
float fLayerOpacity;
|
|
|
|
float4 fLayerColor;
|
|
|
|
|
|
|
|
struct VS_INPUT {
|
|
|
|
float4 vPosition : POSITION;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_OUTPUT {
|
|
|
|
float4 vPosition : POSITION;
|
|
|
|
float2 vTexCoords : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
struct VS_OUTPUT_MASK {
|
|
|
|
float4 vPosition : POSITION;
|
|
|
|
float2 vTexCoords : TEXCOORD0;
|
|
|
|
float3 vMaskCoords : TEXCOORD1;
|
|
|
|
};
|
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex)
|
|
|
|
{
|
|
|
|
VS_OUTPUT outp;
|
|
|
|
outp.vPosition = aVertex.vPosition;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2010-10-02 02:24:58 +04:00
|
|
|
// We use 4 component floats to uniquely describe a rectangle, by the structure
|
|
|
|
// of x, y, width, height. This allows us to easily generate the 4 corners
|
|
|
|
// of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
|
|
|
|
// stream source for our LayerQuad vertex shader. We do this by doing:
|
|
|
|
// Xout = x + Xin * width
|
|
|
|
// Yout = y + Yin * height
|
|
|
|
float2 position = vLayerQuad.xy;
|
|
|
|
float2 size = vLayerQuad.zw;
|
|
|
|
outp.vPosition.x = position.x + outp.vPosition.x * size.x;
|
|
|
|
outp.vPosition.y = position.y + outp.vPosition.y * size.y;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
outp.vPosition = mul(mLayerTransform, outp.vPosition);
|
2011-12-19 01:11:30 +04:00
|
|
|
outp.vPosition.xyz /= outp.vPosition.w;
|
2010-05-24 19:28:51 +04:00
|
|
|
outp.vPosition = outp.vPosition - vRenderTargetOffset;
|
2011-12-19 01:11:30 +04:00
|
|
|
outp.vPosition.xyz *= outp.vPosition.w;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2010-09-02 01:10:51 +04:00
|
|
|
// adjust our vertices to match d3d9's pixel coordinate system
|
|
|
|
// which has pixel centers at integer locations
|
|
|
|
outp.vPosition.xy -= 0.5;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
outp.vPosition = mul(mProjection, outp.vPosition);
|
2010-10-02 02:24:58 +04:00
|
|
|
|
|
|
|
position = vTextureCoords.xy;
|
|
|
|
size = vTextureCoords.zw;
|
2010-09-08 07:27:38 +04:00
|
|
|
outp.vTexCoords.x = position.x + aVertex.vPosition.x * size.x;
|
|
|
|
outp.vTexCoords.y = position.y + aVertex.vPosition.y * size.y;
|
2010-10-02 02:24:58 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
return outp;
|
|
|
|
}
|
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
VS_OUTPUT_MASK LayerQuadVSMask(const VS_INPUT aVertex)
|
|
|
|
{
|
|
|
|
VS_OUTPUT_MASK outp;
|
|
|
|
float4 position = float4(0, 0, 0, 1);
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
// We use 4 component floats to uniquely describe a rectangle, by the structure
|
|
|
|
// of x, y, width, height. This allows us to easily generate the 4 corners
|
|
|
|
// of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
|
|
|
|
// stream source for our LayerQuad vertex shader. We do this by doing:
|
|
|
|
// Xout = x + Xin * width
|
|
|
|
// Yout = y + Yin * height
|
|
|
|
float2 size = vLayerQuad.zw;
|
|
|
|
position.x = vLayerQuad.x + aVertex.vPosition.x * size.x;
|
|
|
|
position.y = vLayerQuad.y + aVertex.vPosition.y * size.y;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
position = mul(mLayerTransform, position);
|
|
|
|
outp.vPosition.w = position.w;
|
|
|
|
outp.vPosition.xyz = position.xyz / position.w;
|
|
|
|
outp.vPosition = outp.vPosition - vRenderTargetOffset;
|
|
|
|
outp.vPosition.xyz *= outp.vPosition.w;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
// adjust our vertices to match d3d9's pixel coordinate system
|
|
|
|
// which has pixel centers at integer locations
|
|
|
|
outp.vPosition.xy -= 0.5;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2012-03-07 01:09:19 +04:00
|
|
|
outp.vPosition = mul(mProjection, outp.vPosition);
|
|
|
|
|
|
|
|
// calculate the position on the mask texture
|
|
|
|
outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z;
|
|
|
|
outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w;
|
2016-03-21 23:10:37 +03:00
|
|
|
// correct for perspective correct interpolation, see comment in D3D11 shader
|
2012-03-07 01:09:19 +04:00
|
|
|
outp.vMaskCoords.z = 1;
|
|
|
|
outp.vMaskCoords *= position.w;
|
|
|
|
|
|
|
|
size = vTextureCoords.zw;
|
|
|
|
outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x;
|
|
|
|
outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y;
|
|
|
|
|
|
|
|
return outp;
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
float4 ComponentPass1Shader(const VS_OUTPUT aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 src = tex2D(s2D, aVertex.vTexCoords);
|
|
|
|
float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
|
|
|
|
alphas.a = alphas.g;
|
|
|
|
return alphas * fLayerOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 ComponentPass2Shader(const VS_OUTPUT aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 src = tex2D(s2D, aVertex.vTexCoords);
|
|
|
|
float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
|
|
|
|
src.a = alphas.g;
|
|
|
|
return src * fLayerOpacity;
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:51:04 +04:00
|
|
|
float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR
|
2010-05-24 19:28:51 +04:00
|
|
|
{
|
|
|
|
return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:51:04 +04:00
|
|
|
float4 RGBShader(const VS_OUTPUT aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 result;
|
2012-03-20 11:55:40 +04:00
|
|
|
result = tex2D(s2D, aVertex.vTexCoords);
|
2010-09-03 07:51:04 +04:00
|
|
|
result.a = 1.0;
|
2012-03-20 11:55:40 +04:00
|
|
|
return result * fLayerOpacity;
|
2010-09-03 07:51:04 +04:00
|
|
|
}
|
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 yuv;
|
|
|
|
float4 color;
|
|
|
|
|
2013-11-21 20:40:55 +04:00
|
|
|
yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5;
|
|
|
|
yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625;
|
|
|
|
yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5;
|
2010-05-24 19:28:51 +04:00
|
|
|
|
|
|
|
color.r = yuv.g * 1.164 + yuv.r * 1.596;
|
|
|
|
color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b;
|
|
|
|
color.b = yuv.g * 1.164 + yuv.b * 2.018;
|
|
|
|
color.a = 1.0f;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2010-05-24 19:28:51 +04:00
|
|
|
return color * fLayerOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 SolidColorShader(const VS_OUTPUT aVertex) : COLOR
|
|
|
|
{
|
|
|
|
return fLayerColor;
|
|
|
|
}
|
2012-03-07 01:09:19 +04:00
|
|
|
|
|
|
|
float4 ComponentPass1ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 src = tex2D(s2D, aVertex.vTexCoords);
|
|
|
|
float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
|
|
|
|
alphas.a = alphas.g;
|
2016-03-21 23:10:37 +03:00
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
2012-03-07 01:09:19 +04:00
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return alphas * fLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 ComponentPass2ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 src = tex2D(s2D, aVertex.vTexCoords);
|
|
|
|
float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
|
|
|
|
src.a = alphas.g;
|
2016-03-21 23:10:37 +03:00
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
2012-03-07 01:09:19 +04:00
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return src * fLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 RGBAShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 RGBShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 result;
|
|
|
|
result = tex2D(s2D, aVertex.vTexCoords);
|
|
|
|
result.a = 1.0;
|
2016-03-21 23:10:37 +03:00
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
2012-03-07 01:09:19 +04:00
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return result * fLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
|
2014-07-03 04:48:18 +04:00
|
|
|
/* From Rec601:
|
|
|
|
[R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
|
|
|
|
[G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
|
|
|
|
[B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
|
|
|
|
|
|
|
|
For [0,1] instead of [0,255], and to 5 places:
|
|
|
|
[R] [1.16438, 0.00000, 1.59603] [ Y - 0.06275]
|
|
|
|
[G] = [1.16438, -0.39176, -0.81297] x [Cb - 0.50196]
|
|
|
|
[B] [1.16438, 2.01723, 0.00000] [Cr - 0.50196]
|
|
|
|
*/
|
2012-03-07 01:09:19 +04:00
|
|
|
float4 YCbCrShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
|
|
|
float4 yuv;
|
|
|
|
float4 color;
|
|
|
|
|
2014-07-03 04:48:18 +04:00
|
|
|
yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.50196;
|
|
|
|
yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.06275;
|
|
|
|
yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.50196;
|
2012-03-07 01:09:19 +04:00
|
|
|
|
2014-07-03 04:48:18 +04:00
|
|
|
color.r = yuv.g * 1.16438 + yuv.r * 1.59603;
|
|
|
|
color.g = yuv.g * 1.16438 - 0.81297 * yuv.r - 0.39176 * yuv.b;
|
|
|
|
color.b = yuv.g * 1.16438 + yuv.b * 2.01723;
|
2012-03-07 01:09:19 +04:00
|
|
|
color.a = 1.0f;
|
2014-07-03 04:48:18 +04:00
|
|
|
|
2016-03-21 23:10:37 +03:00
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
2012-03-07 01:09:19 +04:00
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return color * fLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 SolidColorShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
|
|
|
|
{
|
2016-03-21 23:10:37 +03:00
|
|
|
float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
|
2012-03-07 01:09:19 +04:00
|
|
|
float mask = tex2D(s2DMask, maskCoords).a;
|
|
|
|
return fLayerColor * mask;
|
|
|
|
}
|