Fixed YIQ passes

- fixed half texel offset
- readded usage of A value in encode/decode pass
- readded jitter of B value in encode/decode pass
- readded usage of P value in encode pass
- fixed not set O value uniform for decode pass
- removed duplicate YIQ option definition
- changed default of O value back to 1.0
This commit is contained in:
ImJezze 2016-01-09 16:41:53 +01:00
parent 37b596b7b4
commit ded9493cb0
4 changed files with 127 additions and 81 deletions

View file

@ -1,5 +1,5 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// YIQ Decode Effect
//-----------------------------------------------------------------------------
@ -41,7 +41,7 @@ sampler DiffuseSampler = sampler_state
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Coord0 : TEXCOORD0;
float4 TexCoord : TEXCOORD0;
};
struct VS_INPUT
@ -49,12 +49,11 @@ struct VS_INPUT
float4 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
float2 Unused : TEXCOORD1;
};
struct PS_INPUT
{
float4 Coord0 : TEXCOORD0;
float2 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
@ -71,11 +70,12 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.xy -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Coord0.xy = Input.TexCoord;
Output.Coord0.zw = float2(1.0f / SourceDims.x, 0.0f);
Output.Position.y = 1.0f - Output.Position.y; // flip y
Output.Position.xy -= 0.5f; // center
Output.Position.xy *= 2.0f; // zoom
Output.TexCoord.xy = Input.TexCoord;
Output.TexCoord.xy += 0.5f / SourceDims; // half texel offset correction (DX9)
return Output;
}
@ -84,38 +84,54 @@ VS_OUTPUT vs_main(VS_INPUT Input)
// YIQ Decode Pixel Shader
//-----------------------------------------------------------------------------
uniform float AValue = 0.0f;
uniform float BValue = 0.0f;
uniform float CCValue = 3.04183f;
uniform float PValue = 1.0f;
uniform float AValue = 0.5f;
uniform float BValue = 0.5f;
uniform float CCValue = 3.5975454f;
uniform float OValue = 0.0f;
uniform float PValue = 1.0f; // unused
uniform float ScanTime = 52.6f;
uniform float FrameOffset = 0.0f;
uniform float NotchHalfWidth = 1.0f;
uniform float YFreqResponse = 6.0f;
uniform float IFreqResponse = 1.2f;
uniform float QFreqResponse = 0.6f;
uniform float PI = 3.141592653589;
uniform float PI2 = 6.283185307178;
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
static const float4 NotchOffset = float4(0.0f, 1.0f, 2.0f, 3.0f);
static const float PI = 3.1415927f;
static const float PI2 = 6.2831855f;
static const float MaxC = 2.1183f;
static const float MinC = -1.1183f;
static const float CRange = 3.2366f;
float4 ps_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / SourceDims);
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord.xy);
float2 InvDims = 1.0f / SourceDims;
// YIQ convolution: N coefficients each
float4 YAccum = 0.0f;
float4 IAccum = 0.0f;
float4 QAccum = 0.0f;
float MaxC = 2.1183f;
float MinC = -1.1183f;
float CRange = MaxC - MinC;
float FrameWidthx4 = SourceDims.x * 4.0f * SourceRect.x;
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 BValueFrameOffset = BValue * FrameOffset;
float FrameWidthx4 = SourceDims.x * SourceRect.x * 4.0f;
float TimePerSample = ScanTime / FrameWidthx4;
float Fc_y1 = (CCValue - NotchHalfWidth) * TimePerSample;
float Fc_y2 = (CCValue + NotchHalfWidth) * TimePerSample;
float Fc_y3 = YFreqResponse * TimePerSample;
float Fc_i = IFreqResponse * TimePerSample;
float Fc_q = QFreqResponse * TimePerSample;
float Fc_i_2 = Fc_i * 2.0f;
float Fc_q_2 = Fc_q * 2.0f;
float Fc_y1_2 = Fc_y1 * 2.0f;
@ -127,18 +143,24 @@ float4 ps_main(PS_INPUT Input) : COLOR
float Fc_y2_pi2 = Fc_y2 * PI2;
float Fc_y3_pi2 = Fc_y3 * PI2;
float PI2Length = PI2 / 82.0f;
float4 NOffset = float4(0.0f, 1.0f, 2.0f, 3.0f);
float W = PI2 * CCValue * ScanTime;
float4 CoordY = Input.Coord0.y;
float4 VPosition = (CoordY * SourceRect.y) * (SourceDims.x / SourceRect.x);
float4 Cy = Input.TexCoord.y;
float4 VPosition = Cy * (SourceDims.y * SourceRect.y) * 2.0f;
for(float n = -41.0f; n < 42.0f; n += 4.0f)
{
float4 n4 = n + NOffset;
float4 CoordX = Input.Coord0.x + Input.Coord0.z * n4 * 0.25f;
float2 TexCoord = float2(CoordX.r, CoordY.r);
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.5f, 0.0f) / SourceDims) * CRange + MinC;
float4 T = (CoordX / SourceRect.x) + VPosition + BValue;
float4 n4 = n + NotchOffset;
float4 Cx = Input.TexCoord.x + InvDims.x * n4 * 0.25f;
float4 HPosition = (Cx / SourceRect.x);
float4 C = tex2D(CompositeSampler, float2(Cx.r, Cy.r)) * CRange + MinC;
float4 T = HPosition + AValue * VPosition + BValueFrameOffset;
float4 WT = W * T + OValue;
float4 SincKernel = 0.54f + 0.46f * cos(PI2Length * n4);
float4 SincYIn1 = Fc_y1_pi2 * n4;
@ -147,13 +169,13 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 SincIIn = Fc_i_pi2 * n4;
float4 SincQIn = Fc_q_pi2 * 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 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 = (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 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;
@ -170,9 +192,11 @@ float4 ps_main(PS_INPUT Input) : COLOR
float3 YIQ = float3(Y, I, Q);
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)));
return float4(OutRGB, BaseTexel.a);
float3 Decode = 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)));
return float4(Decode, BaseTexel.a);
}
//-----------------------------------------------------------------------------

View file

@ -1,5 +1,5 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// YIQ Encode Effect
//-----------------------------------------------------------------------------
@ -37,7 +37,6 @@ struct VS_INPUT
float4 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
float2 Unused : TEXCOORD1;
};
struct PS_INPUT
@ -51,6 +50,8 @@ struct PS_INPUT
//-----------------------------------------------------------------------------
uniform float2 ScreenDims;
uniform float2 SourceDims;
uniform float2 SourceRect;
VS_OUTPUT vs_main(VS_INPUT Input)
{
@ -58,11 +59,14 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.xy -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Color = Input.Color;
Output.Position.y = 1.0f - Output.Position.y; // flip y
Output.Position.xy -= 0.5f; // center
Output.Position.xy *= 2.0f; // zoom
Output.TexCoord = Input.TexCoord;
Output.TexCoord += 0.5f / SourceDims; // half texel offset correction (DX9)
Output.Color = Input.Color;
return Output;
}
@ -71,51 +75,64 @@ VS_OUTPUT vs_main(VS_INPUT Input)
// YIQ Encode Pixel Shader
//-----------------------------------------------------------------------------
uniform float AValue = 0.0f;
uniform float BValue = 0.0f;
uniform float CCValue = 3.04183f;
uniform float AValue = 0.5f;
uniform float BValue = 0.5f;
uniform float CCValue = 3.5975454f;
uniform float OValue = 0.0f;
uniform float PValue = 1.0f;
uniform float ScanTime = 52.6f;
uniform float2 SourceDims;
uniform float2 SourceRect;
uniform float4 YDot = float4(0.299f, 0.587f, 0.114f, 0.0f);
uniform float4 IDot = float4(0.595716f, -0.274453f, -0.321263f, 0.0f);
uniform float4 QDot = float4(0.211456f, -0.522591f, 0.311135f, 0.0f);
uniform float4 OffsetX = float4(0.00f, 0.25f, 0.50f, 0.75f);
uniform float PI = 3.1415926535f;
uniform float PI2 = 6.2831853072f;
uniform float FrameOffset = 0.0f;
uniform float MaxC = 2.1183f;
uniform float MinC = -1.1183f;
uniform float CRange = 3.2366f;
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 InvDims = 1.0f / SourceDims;
float4 CoordX = float4(Input.TexCoord.x + OffsetX * InvDims.x);
float4 CoordY = Input.TexCoord.y;
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
float2 TexelOffset = InvDims * 0.5f;
float4 Texel0 = tex2D(DiffuseSampler, float2(CoordX.x, CoordY.x) + TexelOffset);
float4 Texel1 = tex2D(DiffuseSampler, float2(CoordX.y, CoordY.y) + TexelOffset);
float4 Texel2 = tex2D(DiffuseSampler, float2(CoordX.z, CoordY.z) + TexelOffset);
float4 Texel3 = tex2D(DiffuseSampler, float2(CoordX.w, CoordY.w) + TexelOffset);
static const float4 YDot = float4(0.299f, 0.587f, 0.114f, 0.0f);
static const float4 IDot = float4(0.595716f, -0.274453f, -0.321263f, 0.0f);
static const float4 QDot = float4(0.211456f, -0.522591f, 0.311135f, 0.0f);
static const float4 OffsetX = float4(0.0f, 0.25f, 0.50f, 0.75f);
static const float PI = 3.1415927f;
static const float PI2 = 6.2831855f;
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 InvDims = 1.0f / SourceDims;
float2 InvPValue = float2(PValue, 0.0f) * InvDims;
float2 C0 = Input.TexCoord + InvPValue * OffsetX.x;
float2 C1 = Input.TexCoord + InvPValue * OffsetX.y;
float2 C2 = Input.TexCoord + InvPValue * OffsetX.z;
float2 C3 = Input.TexCoord + InvPValue * OffsetX.w;
float4 Cx = float4(C0.x, C1.x, C2.x, C3.x);
float4 Cy = float4(C0.y, C1.y, C2.y, C3.y);
float4 Texel0 = tex2D(DiffuseSampler, C0);
float4 Texel1 = tex2D(DiffuseSampler, C1);
float4 Texel2 = tex2D(DiffuseSampler, C2);
float4 Texel3 = tex2D(DiffuseSampler, C3);
float4 Y = float4(dot(Texel0, YDot), dot(Texel1, YDot), dot(Texel2, YDot), dot(Texel3, YDot));
float4 I = float4(dot(Texel0, IDot), dot(Texel1, IDot), dot(Texel2, IDot), dot(Texel3, IDot));
float4 Q = float4(dot(Texel0, QDot), dot(Texel1, QDot), dot(Texel2, QDot), dot(Texel3, QDot));
float BValueFrameOffset = BValue * FrameOffset;
float4 HPosition = Cx / SourceRect.x;
float4 VPosition = Cy * (SourceDims.y * SourceRect.y) * 2.0f;
float4 W = PI2 * CCValue * ScanTime;
float4 VPosition = (CoordY * SourceRect.y) * (SourceDims.x / SourceRect.x);
float4 T = CoordX / SourceRect.x + VPosition + BValue;
float4 T = HPosition + AValue * VPosition + BValueFrameOffset;
float4 TW = T * W + OValue;
float4 C = Y + I * cos(T * W) + Q * sin(T * W);
C = (C - MinC) / CRange;
float4 Encoded = Y + I * cos(TW) + Q * sin(TW);
return C;
return (Encoded - MinC) / CRange;;
}
//-----------------------------------------------------------------------------

View file

@ -970,6 +970,7 @@ int shaders::create_resources(bool reset)
yiq_encode_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ);
yiq_encode_effect->add_uniform("AValue", uniform::UT_FLOAT, uniform::CU_NTSC_A);
yiq_encode_effect->add_uniform("BValue", uniform::UT_FLOAT, uniform::CU_NTSC_B);
yiq_decode_effect->add_uniform("OValue", uniform::UT_FLOAT, uniform::CU_NTSC_O);
yiq_encode_effect->add_uniform("PValue", uniform::UT_FLOAT, uniform::CU_NTSC_P);
yiq_encode_effect->add_uniform("NotchHalfWidth", uniform::UT_FLOAT, uniform::CU_NTSC_NOTCH);
yiq_encode_effect->add_uniform("YFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_YFREQ);
@ -1244,10 +1245,15 @@ int shaders::ntsc_pass(render_target *rt, int source_index, poly_info *poly, int
return next_index;
}
float frame_offset = curr_texture->get_cur_frame() == 0
? 0.0f
: (float)curr_texture->get_cur_frame();
// Convert our signal into YIQ
curr_effect = yiq_encode_effect;
curr_effect->update_uniforms();
curr_effect->set_float("FrameOffset", frame_offset);
// initial "Diffuse" texture is set in shaders::set_texture()
next_index = rt->next_index(next_index);
@ -1258,7 +1264,8 @@ int shaders::ntsc_pass(render_target *rt, int source_index, poly_info *poly, int
curr_effect->update_uniforms();
curr_effect->set_texture("Composite", rt->native_texture[next_index]);
curr_effect->set_texture("Diffuse", curr_texture->get_finaltex());
curr_effect->set_float("FrameOffset", frame_offset);
next_index = rt->next_index(next_index);
blit(rt->native_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2);

View file

@ -330,7 +330,7 @@ const options_entry windows_options::s_option_entries[] =
{ WINOPTION_YIQ_CCVALUE";yiqcc", "3.59754545", OPTION_FLOAT, "Color Carrier frequency for NTSC signal processing" },
{ WINOPTION_YIQ_AVALUE";yiqa", "0.5", OPTION_FLOAT, "A value for NTSC signal processing" },
{ WINOPTION_YIQ_BVALUE";yiqb", "0.5", OPTION_FLOAT, "B value for NTSC signal processing" },
{ WINOPTION_YIQ_OVALUE";yiqo", "1.570796325", OPTION_FLOAT, "Outgoing Color Carrier phase offset for NTSC signal processing" },
{ WINOPTION_YIQ_OVALUE";yiqo", "1.0", OPTION_FLOAT, "Outgoing Color Carrier phase offset for NTSC signal processing" },
{ WINOPTION_YIQ_PVALUE";yiqp", "1.0", OPTION_FLOAT, "Incoming Pixel Clock scaling value for NTSC signal processing" },
{ WINOPTION_YIQ_NVALUE";yiqn", "1.0", OPTION_FLOAT, "Y filter notch width for NTSC signal processing" },
{ WINOPTION_YIQ_YVALUE";yiqy", "6.0", OPTION_FLOAT, "Y filter cutoff frequency for NTSC signal processing" },
@ -338,8 +338,6 @@ const options_entry windows_options::s_option_entries[] =
{ WINOPTION_YIQ_QVALUE";yiqq", "0.6", OPTION_FLOAT, "Q filter cutoff frequency for NTSC signal processing" },
{ WINOPTION_YIQ_SCAN_TIME";yiqsc", "52.6", OPTION_FLOAT, "Horizontal scanline duration for NTSC signal processing (in usec)" },
{ WINOPTION_YIQ_PHASE_COUNT";yiqp", "2", OPTION_INTEGER, "Phase Count value for NTSC signal processing" },
{ WINOPTION_YIQ_SCAN_TIME";yiqsc", "52.6", OPTION_FLOAT, "Horizontal scanline duration for NTSC signal processing (in usec)" },
{ WINOPTION_YIQ_PHASE_COUNT";yiqp", "2", OPTION_INTEGER, "Phase Count value for NTSC signal processing" },
/* Vector simulation below this line */
{ NULL, NULL, OPTION_HEADER, "VECTOR POST-PROCESSING OPTIONS" },
{ WINOPTION_VECTOR_LENGTH_SCALE";veclength", "0.5", OPTION_FLOAT, "How much length affects vector fade" },