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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uniform float TargetWidth;
|
|
|
|
uniform float TargetHeight;
|
|
|
|
|
|
|
|
uniform float RawWidth;
|
|
|
|
uniform float RawHeight;
|
|
|
|
|
|
|
|
uniform float WidthRatio;
|
|
|
|
uniform float HeightRatio;
|
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT Input)
|
|
|
|
{
|
|
|
|
VS_OUTPUT Output = (VS_OUTPUT)0;
|
|
|
|
|
|
|
|
Output.Position = float4(Input.Position.xyz, 1.0f);
|
|
|
|
Output.Position.x /= TargetWidth;
|
|
|
|
Output.Position.y /= TargetHeight;
|
|
|
|
Output.Position.y = 1.0f - Output.Position.y;
|
|
|
|
Output.Position.x -= 0.5f;
|
|
|
|
Output.Position.y -= 0.5f;
|
|
|
|
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
|
2011-06-03 16:38:59 +02:00
|
|
|
Output.Coord0.xy = Input.TexCoord;
|
2011-05-30 23:10:23 +02:00
|
|
|
Output.Coord0.zw = float2(1.0f / RawWidth, 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
|
|
|
|
|
|
|
float4 ps_main(PS_INPUT Input) : COLOR
|
|
|
|
{
|
2011-05-20 09:37:34 +02:00
|
|
|
float2 RawDims = float2(RawWidth, RawHeight);
|
2011-05-19 21:14:20 +02:00
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / RawDims);
|
|
|
|
|
|
|
|
// 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;
|
2011-06-06 23:25:38 +02:00
|
|
|
float Fc_y1 = (CCValue - NotchHalfWidth) * ScanTime / (RawWidth * 4.0f / WidthRatio);
|
|
|
|
float Fc_y2 = (CCValue + NotchHalfWidth) * ScanTime / (RawWidth * 4.0f / WidthRatio);
|
|
|
|
float Fc_y3 = YFreqResponse * ScanTime / (RawWidth * 4.0f / WidthRatio);
|
2011-05-30 23:10:23 +02:00
|
|
|
float Fc_i = IFreqResponse * ScanTime / (RawWidth * 4.0f / WidthRatio);
|
|
|
|
float Fc_q = QFreqResponse * ScanTime / (RawWidth * 4.0f / WidthRatio);
|
|
|
|
float PI = 3.1415926535897932384626433832795;
|
|
|
|
float PI2 = 2.0f * PI;
|
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;
|
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;
|
|
|
|
float4 CoordY = Input.Coord0.y;
|
2011-05-31 16:43:47 +02:00
|
|
|
float2 TexCoord = float2(CoordX.r, CoordY.r);
|
2011-06-03 16:38:59 +02:00
|
|
|
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.625f, 0.4f) / RawDims) * CRange + MinC;
|
2011-05-31 16:43:47 +02:00
|
|
|
float4 WT = W * (CoordX * WidthRatio + AValue * CoordY * 2.0f * (RawHeight / HeightRatio) + BValue) + OValue;
|
2011-05-30 23:10:23 +02:00
|
|
|
|
2011-06-06 23:25:38 +02:00
|
|
|
float4 SincYIn1 = PI2 * Fc_y1 * n4;
|
|
|
|
float4 SincYIn2 = PI2 * Fc_y2 * n4;
|
|
|
|
float4 SincYIn3 = PI2 * Fc_y3 * n4;
|
|
|
|
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);
|
|
|
|
float4 IdealY = (2.0f * Fc_y1 * SincY1 - 2.0f * Fc_y2 * SincY2) + 2.0f * Fc_y3 * SincY3;
|
|
|
|
float4 FilterY = (0.54f + 0.46f * cos(PI2Length * n4)) * IdealY;
|
2011-05-30 23:10:23 +02:00
|
|
|
|
|
|
|
float4 SincIIn = PI2 * Fc_i * n4;
|
|
|
|
float4 IdealI = 2.0f * Fc_i * ((SincIIn != 0.0f) ? (sin(SincIIn) / SincIIn) : 1.0f);
|
|
|
|
float4 FilterI = (0.54f + 0.46f * cos(PI2Length * n4)) * IdealI;
|
|
|
|
|
|
|
|
float4 SincQIn = PI2 * Fc_q * n4;
|
|
|
|
float4 IdealQ = 2.0f * Fc_q * ((SincQIn != 0.0f) ? (sin(SincQIn) / SincQIn) : 1.0f);
|
|
|
|
float4 FilterQ = (0.54f + 0.46f * cos(PI2Length * n4)) * IdealQ;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|