2011-05-19 21:14:20 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// YIQ Decode Effect
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-05-22 04:27:31 +02:00
|
|
|
texture Composite;
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-22 03:30:55 +02:00
|
|
|
sampler CompositeSampler = sampler_state
|
2011-05-22 04:27:31 +02:00
|
|
|
{
|
|
|
|
Texture = <Composite>;
|
|
|
|
MipFilter = POINT;
|
|
|
|
MinFilter = POINT;
|
|
|
|
MagFilter = POINT;
|
|
|
|
AddressU = CLAMP;
|
|
|
|
AddressV = CLAMP;
|
|
|
|
AddressW = CLAMP;
|
|
|
|
};
|
|
|
|
|
|
|
|
texture Diffuse;
|
|
|
|
|
|
|
|
sampler DiffuseSampler = sampler_state
|
2011-05-19 21:14:20 +02:00
|
|
|
{
|
|
|
|
Texture = <Diffuse>;
|
2011-05-30 23:10:23 +02:00
|
|
|
MipFilter = LINEAR;
|
|
|
|
MinFilter = LINEAR;
|
|
|
|
MagFilter = LINEAR;
|
2011-05-19 21:14:20 +02:00
|
|
|
AddressU = CLAMP;
|
|
|
|
AddressV = CLAMP;
|
|
|
|
AddressW = CLAMP;
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Vertex Definitions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
2011-05-21 08:47:56 +02:00
|
|
|
float4 Coord0 : TEXCOORD0;
|
2011-05-19 21:14:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
|
|
|
float4 Color : COLOR0;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
2013-05-22 03:58:38 +02:00
|
|
|
float2 Unused : TEXCOORD1;
|
2011-05-19 21:14:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
2011-05-21 08:47:56 +02:00
|
|
|
float4 Coord0 : TEXCOORD0;
|
2011-05-19 21:14:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// YIQ Decode Vertex Shader
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2013-08-29 02:56:33 +02:00
|
|
|
uniform float2 ScreenDims;
|
|
|
|
uniform float2 SourceDims;
|
|
|
|
uniform float2 SourceRect;
|
2011-05-19 21:14:20 +02:00
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT Input)
|
|
|
|
{
|
|
|
|
VS_OUTPUT Output = (VS_OUTPUT)0;
|
|
|
|
|
|
|
|
Output.Position = float4(Input.Position.xyz, 1.0f);
|
2013-08-29 02:56:33 +02:00
|
|
|
Output.Position.xy /= ScreenDims;
|
2011-05-19 21:14:20 +02:00
|
|
|
Output.Position.y = 1.0f - Output.Position.y;
|
2013-08-29 02:56:33 +02:00
|
|
|
Output.Position.xy -= 0.5f;
|
2011-05-19 21:14:20 +02:00
|
|
|
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
|
2011-06-03 16:38:59 +02:00
|
|
|
Output.Coord0.xy = Input.TexCoord;
|
2013-08-29 02:56:33 +02:00
|
|
|
Output.Coord0.zw = float2(1.0f / SourceDims.x, 0.0f);
|
2011-05-19 21:14:20 +02:00
|
|
|
|
|
|
|
return Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// YIQ Decode Pixel Shader
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
uniform float AValue = 0.0f;
|
|
|
|
uniform float BValue = 0.0f;
|
|
|
|
uniform float CCValue = 3.04183f;
|
|
|
|
uniform float PValue = 1.0f;
|
|
|
|
uniform float OValue = 0.0f;
|
|
|
|
uniform float ScanTime = 52.6f;
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-06-06 23:25:38 +02:00
|
|
|
uniform float NotchHalfWidth = 1.0f;
|
|
|
|
uniform float YFreqResponse = 6.0f;
|
2011-05-30 23:10:23 +02:00
|
|
|
uniform float IFreqResponse = 1.2f;
|
|
|
|
uniform float QFreqResponse = 0.6f;
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2013-08-25 22:49:37 +02:00
|
|
|
uniform float PI = 3.141592653589;
|
|
|
|
uniform float PI2 = 6.283185307178;
|
|
|
|
|
2011-05-19 21:14:20 +02:00
|
|
|
float4 ps_main(PS_INPUT Input) : COLOR
|
|
|
|
{
|
2013-08-29 02:56:33 +02:00
|
|
|
float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / SourceDims);
|
2011-05-30 23:10:23 +02:00
|
|
|
|
|
|
|
// YIQ convolution: N coefficients each
|
|
|
|
float4 YAccum = 0.0f;
|
|
|
|
float4 IAccum = 0.0f;
|
|
|
|
float4 QAccum = 0.0f;
|
2011-05-19 21:14:20 +02:00
|
|
|
float MaxC = 2.1183f;
|
|
|
|
float MinC = -1.1183f;
|
|
|
|
float CRange = MaxC - MinC;
|
2013-08-29 02:56:33 +02:00
|
|
|
float FrameWidthx4 = SourceDims.x * 4.0f / SourceRect.x;
|
2013-08-25 22:49:37 +02:00
|
|
|
float Fc_y1 = (CCValue - NotchHalfWidth) * ScanTime / FrameWidthx4;
|
|
|
|
float Fc_y2 = (CCValue + NotchHalfWidth) * ScanTime / FrameWidthx4;
|
|
|
|
float Fc_y3 = YFreqResponse * ScanTime / FrameWidthx4;
|
|
|
|
float Fc_i = IFreqResponse * ScanTime / FrameWidthx4;
|
|
|
|
float Fc_q = QFreqResponse * ScanTime / FrameWidthx4;
|
|
|
|
float Fc_i_2 = Fc_i * 2.0f;
|
|
|
|
float Fc_q_2 = Fc_q * 2.0f;
|
|
|
|
float Fc_y1_2 = Fc_y1 * 2.0f;
|
|
|
|
float Fc_y2_2 = Fc_y2 * 2.0f;
|
|
|
|
float Fc_y3_2 = Fc_y3 * 2.0f;
|
|
|
|
float Fc_i_pi2 = Fc_i * PI2;
|
|
|
|
float Fc_q_pi2 = Fc_q * PI2;
|
|
|
|
float Fc_y1_pi2 = Fc_y1 * PI2;
|
|
|
|
float Fc_y2_pi2 = Fc_y2 * PI2;
|
|
|
|
float Fc_y3_pi2 = Fc_y3 * PI2;
|
2011-06-06 23:25:38 +02:00
|
|
|
float PI2Length = PI2 / 82.0f;
|
2011-05-31 16:43:47 +02:00
|
|
|
float4 NOffset = float4(0.0f, 1.0f, 2.0f, 3.0f);
|
|
|
|
float W = PI2 * CCValue * ScanTime;
|
2013-08-25 22:49:37 +02:00
|
|
|
float4 CoordY = Input.Coord0.y;
|
2013-08-29 02:56:33 +02:00
|
|
|
float4 VPosition = (CoordY / SourceRect.y) * (SourceDims.x * SourceRect.x);
|
2011-06-06 23:25:38 +02:00
|
|
|
for(float n = -41.0f; n < 42.0f; n += 4.0f)
|
2011-05-22 03:30:55 +02:00
|
|
|
{
|
2011-05-31 16:43:47 +02:00
|
|
|
float4 n4 = n + NOffset;
|
2011-05-30 23:10:23 +02:00
|
|
|
float4 CoordX = Input.Coord0.x + Input.Coord0.z * n4 * 0.25f;
|
2011-05-31 16:43:47 +02:00
|
|
|
float2 TexCoord = float2(CoordX.r, CoordY.r);
|
2013-08-29 02:56:33 +02:00
|
|
|
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.5f, 0.0f) / SourceDims) * CRange + MinC;
|
|
|
|
float4 WT = W * (CoordX * SourceRect.x + VPosition + BValue) + OValue;
|
2013-08-25 22:49:37 +02:00
|
|
|
float4 SincKernel = 0.54f + 0.46f * cos(PI2Length * n4);
|
|
|
|
|
|
|
|
float4 SincYIn1 = Fc_y1_pi2 * n4;
|
|
|
|
float4 SincYIn2 = Fc_y2_pi2 * n4;
|
|
|
|
float4 SincYIn3 = Fc_y3_pi2 * n4;
|
|
|
|
float4 SincIIn = Fc_i_pi2 * n4;
|
|
|
|
float4 SincQIn = Fc_q_pi2 * n4;
|
2011-05-30 23:10:23 +02:00
|
|
|
|
2011-06-06 23:25:38 +02:00
|
|
|
float4 SincY1 = ((SincYIn1 != 0.0f) ? (sin(SincYIn1) / SincYIn1) : 1.0f);
|
|
|
|
float4 SincY2 = ((SincYIn2 != 0.0f) ? (sin(SincYIn2) / SincYIn2) : 1.0f);
|
|
|
|
float4 SincY3 = ((SincYIn3 != 0.0f) ? (sin(SincYIn3) / SincYIn3) : 1.0f);
|
2013-08-25 22:49:37 +02:00
|
|
|
|
|
|
|
float4 IdealY = (Fc_y1_2 * SincY1 - Fc_y2_2 * SincY2) + Fc_y3_2 * SincY3;
|
|
|
|
float4 IdealI = Fc_i_2 * ((SincIIn != 0.0f) ? (sin(SincIIn) / SincIIn) : 1.0f);
|
|
|
|
float4 IdealQ = Fc_q_2 * ((SincQIn != 0.0f) ? (sin(SincQIn) / SincQIn) : 1.0f);
|
|
|
|
|
|
|
|
float4 FilterY = SincKernel * IdealY;
|
|
|
|
float4 FilterI = SincKernel * IdealI;
|
|
|
|
float4 FilterQ = SincKernel * IdealQ;
|
2011-05-30 23:10:23 +02:00
|
|
|
|
|
|
|
YAccum = YAccum + C * FilterY;
|
|
|
|
IAccum = IAccum + C * cos(WT) * FilterI;
|
|
|
|
QAccum = QAccum + C * sin(WT) * FilterQ;
|
2011-05-22 03:30:55 +02:00
|
|
|
}
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
float Y = YAccum.r + YAccum.g + YAccum.b + YAccum.a;
|
|
|
|
float I = (IAccum.r + IAccum.g + IAccum.b + IAccum.a) * 2.0f;
|
|
|
|
float Q = (QAccum.r + QAccum.g + QAccum.b + QAccum.a) * 2.0f;
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
float3 YIQ = float3(Y, I, Q);
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-23 03:31:32 +02:00
|
|
|
float3 OutRGB = float3(dot(YIQ, float3(1.0f, 0.956f, 0.621f)), dot(YIQ, float3(1.0f, -0.272f, -0.647f)), dot(YIQ, float3(1.0f, -1.106f, 1.703f)));
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-22 04:27:31 +02:00
|
|
|
return float4(OutRGB, BaseTexel.a);
|
2011-05-19 21:14:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// YIQ Decode Technique
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
technique DecodeTechnique
|
|
|
|
{
|
|
|
|
pass Pass0
|
|
|
|
{
|
|
|
|
Lighting = FALSE;
|
|
|
|
|
|
|
|
VertexShader = compile vs_3_0 vs_main();
|
|
|
|
PixelShader = compile ps_3_0 ps_main();
|
|
|
|
}
|
|
|
|
}
|