diff --git a/hlsl/post.fx b/hlsl/post.fx index 7bbda640dcf..bbc924af8ed 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -116,8 +116,7 @@ float4 ps_main(PS_INPUT Input) : COLOR float2 Ratios = 1.0f / SizeRatio; // -- Screen Pincushion Calculation -- - float2 PinViewpointOffset = float2(0.0f, 0.0f); - float2 PinUnitCoord = (Input.TexCoord + PinViewpointOffset) * Ratios * 2.0f - 1.0f; + float2 PinUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f; float PincushionR2 = pow(length(PinUnitCoord), 2.0f) / pow(length(Ratios), 2.0f); float2 PincushionCurve = PinUnitCoord * PincushionAmount * PincushionR2; float2 BaseCoord = Input.TexCoord; diff --git a/hlsl/yiq_decode.fx b/hlsl/yiq_decode.fx index c1caa631f14..2148178ec6f 100644 --- a/hlsl/yiq_decode.fx +++ b/hlsl/yiq_decode.fx @@ -55,11 +55,10 @@ struct PS_INPUT // YIQ Decode Vertex Shader //----------------------------------------------------------------------------- -uniform float TargetWidth; -uniform float TargetHeight; +uniform float ScreenWidth; +uniform float ScreenHeight; -uniform float RawWidth; -uniform float RawHeight; +uniform float2 RawDims; uniform float WidthRatio; uniform float HeightRatio; @@ -69,14 +68,14 @@ 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.x /= ScreenWidth; + Output.Position.y /= ScreenHeight; 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); Output.Coord0.xy = Input.TexCoord; - Output.Coord0.zw = float2(1.0f / RawWidth, 0.0f); + Output.Coord0.zw = float2(1.0f / RawDims.x, 0.0f); return Output; } @@ -97,10 +96,11 @@ 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; + float4 ps_main(PS_INPUT Input) : COLOR { - float2 RawDims = float2(RawWidth, RawHeight); - float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / RawDims); // YIQ convolution: N coefficients each @@ -110,41 +110,53 @@ float4 ps_main(PS_INPUT Input) : COLOR float MaxC = 2.1183f; float MinC = -1.1183f; float CRange = MaxC - MinC; - 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); - 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; + float FrameWidthx4 = RawDims.x * 4.0f / WidthRatio; + 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; 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 * (RawDims.x * WidthRatio); 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; - float4 CoordY = Input.Coord0.y; float2 TexCoord = float2(CoordX.r, CoordY.r); - float4 C = tex2D(CompositeSampler, TexCoord + float2(0.625f, 0.4f) / RawDims) * CRange + MinC; - float4 WT = W * (CoordX * WidthRatio + AValue * CoordY * 2.0f * (RawHeight / HeightRatio) + BValue) + OValue; + float4 C = tex2D(CompositeSampler, TexCoord + float2(0.5f, 0.0f) / RawDims) * CRange + MinC; + float4 WT = W * (CoordX * WidthRatio + VPosition + BValue) + OValue; + 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; - 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; - - 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; + + 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; YAccum = YAccum + C * FilterY; IAccum = IAccum + C * cos(WT) * FilterI; diff --git a/hlsl/yiq_encode.fx b/hlsl/yiq_encode.fx index b08f6317ccc..4c659511d54 100644 --- a/hlsl/yiq_encode.fx +++ b/hlsl/yiq_encode.fx @@ -23,10 +23,7 @@ struct VS_OUTPUT { float4 Position : POSITION; float4 Color : COLOR0; - float2 Coord0 : TEXCOORD0; - float2 Coord1 : TEXCOORD1; - float2 Coord2 : TEXCOORD2; - float2 Coord3 : TEXCOORD3; + float2 TexCoord : TEXCOORD0; }; struct VS_INPUT @@ -40,40 +37,29 @@ struct VS_INPUT struct PS_INPUT { float4 Color : COLOR0; - float2 Coord0 : TEXCOORD0; - float2 Coord1 : TEXCOORD1; - float2 Coord2 : TEXCOORD2; - float2 Coord3 : TEXCOORD3; + float2 TexCoord : TEXCOORD0; }; //----------------------------------------------------------------------------- // YIQ Encode Vertex Shader //----------------------------------------------------------------------------- -uniform float TargetWidth; -uniform float TargetHeight; - -uniform float2 RawDims; - -uniform float WidthRatio; -uniform float HeightRatio; +uniform float ScreenWidth; +uniform float ScreenHeight; 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.x /= ScreenWidth; + Output.Position.y /= ScreenHeight; 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); Output.Color = Input.Color; - Output.Coord0 = Input.TexCoord; - Output.Coord1 = Input.TexCoord; - Output.Coord2 = Input.TexCoord; - Output.Coord3 = Input.TexCoord; + Output.TexCoord = Input.TexCoord; return Output; } @@ -88,56 +74,47 @@ uniform float CCValue = 3.04183f; uniform float PValue = 1.0f; uniform float ScanTime = 52.6f; +uniform float2 RawDims; + +uniform float WidthRatio; +uniform float HeightRatio; + +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 MaxC = 2.1183f; +uniform float MinC = -1.1183f; +uniform float CRange = 3.2366f; + float4 ps_main(PS_INPUT Input) : COLOR { - float2 Coord0 = Input.Coord0 + float2(PValue * 0.00f, 0.0f) / RawDims; - float2 Coord1 = Input.Coord1 + float2(PValue * 0.25f, 0.0f) / RawDims; - float2 Coord2 = Input.Coord2 + float2(PValue * 0.50f, 0.0f) / RawDims; - float2 Coord3 = Input.Coord3 + float2(PValue * 0.75f, 0.0f) / RawDims; + float2 InvDims = 1.0f / RawDims; + float4 CoordX = float4(Input.TexCoord.x + OffsetX * InvDims.x); + float4 CoordY = Input.TexCoord.y; - float2 TexelOffset = 0.5f / RawDims; - float3 Texel0 = tex2D(DiffuseSampler, Coord0 + TexelOffset).rgb; - float3 Texel1 = tex2D(DiffuseSampler, Coord1 + TexelOffset).rgb; - float3 Texel2 = tex2D(DiffuseSampler, Coord2 + TexelOffset).rgb; - float3 Texel3 = tex2D(DiffuseSampler, Coord3 + TexelOffset).rgb; + 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); - float PI = 3.1415926535897932384626433832795; - float W = PI * 2.0f * CCValue * ScanTime; - float T0 = Coord0.x * WidthRatio + AValue * Coord0.y * 2.0f * (RawDims.y / HeightRatio) + BValue; - float T1 = Coord1.x * WidthRatio + AValue * Coord1.y * 2.0f * (RawDims.y / HeightRatio) + BValue; - float T2 = Coord2.x * WidthRatio + AValue * Coord2.y * 2.0f * (RawDims.y / HeightRatio) + BValue; - float T3 = Coord3.x * WidthRatio + AValue * Coord3.y * 2.0f * (RawDims.y / HeightRatio) + BValue; + 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 Y0 = dot(Texel0, float3(0.299f, 0.587f, 0.114f)); - float I0 = dot(Texel0, float3(0.595716f, -0.274453f, -0.321263f)); - float Q0 = dot(Texel0, float3(0.211456f, -0.522591f, 0.311135f)); - - float Y1 = dot(Texel1, float3(0.299f, 0.587f, 0.114f)); - float I1 = dot(Texel1, float3(0.595716f, -0.274453f, -0.321263f)); - float Q1 = dot(Texel1, float3(0.211456f, -0.522591f, 0.311135f)); - - float Y2 = dot(Texel2, float3(0.299f, 0.587f, 0.114f)); - float I2 = dot(Texel2, float3(0.595716f, -0.274453f, -0.321263f)); - float Q2 = dot(Texel2, float3(0.211456f, -0.522591f, 0.311135f)); - - float Y3 = dot(Texel3, float3(0.299f, 0.587f, 0.114f)); - float I3 = dot(Texel3, float3(0.595716f, -0.274453f, -0.321263f)); - float Q3 = dot(Texel3, float3(0.211456f, -0.522591f, 0.311135f)); - - float MaxC = 2.1183f; - float MinC = -1.1183f; - float CRange = MaxC - MinC; + float4 W = PI2 * CCValue * ScanTime; + float4 VPosition = CoordY * (RawDims.x * WidthRatio); + float4 T = CoordX * WidthRatio + VPosition + BValue; - float C0 = Y0 + I0 * cos(T0 * W) + Q0 * sin(T0 * W); - float C1 = Y1 + I1 * cos(T1 * W) + Q1 * sin(T1 * W); - float C2 = Y2 + I2 * cos(T2 * W) + Q2 * sin(T2 * W); - float C3 = Y3 + I3 * cos(T3 * W) + Q3 * sin(T3 * W); - C0 = (C0 - MinC) / CRange; - C1 = (C1 - MinC) / CRange; - C2 = (C2 - MinC) / CRange; - C3 = (C3 - MinC) / CRange; + float4 C = Y + I * cos(T * W) + Q * sin(T * W); + C = (C - MinC) / CRange; - return float4(C0, C1, C2, C3); + return C; } //----------------------------------------------------------------------------- diff --git a/src/osd/windows/d3dhlsl.c b/src/osd/windows/d3dhlsl.c index 9d7fb924555..7b5466025b7 100644 --- a/src/osd/windows/d3dhlsl.c +++ b/src/osd/windows/d3dhlsl.c @@ -1483,6 +1483,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) vec2f& rawdims = texture->get_rawdims(); vec2f delta = texture->get_uvstop() - texture->get_uvstart(); + vec2f texsize(rt->width, rt->height); if(options->yiq_enable) { @@ -1491,14 +1492,14 @@ void shaders::render_quad(poly_info *poly, int vertnum) if(options->params_dirty) { - (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); + (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &texsize.c.x); (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x); (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y); - (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); - (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); + (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", d3d->get_width()); + (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", d3d->get_height()); (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); - (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); + (*d3dintf->effect.set_float)(curr_effect, "BValue", options->yiq_b); (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p); (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n); (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y); @@ -1533,12 +1534,11 @@ void shaders::render_quad(poly_info *poly, int vertnum) (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", texture->get_finaltex()); if(true)//options->params_dirty) { - (*d3dintf->effect.set_float)(curr_effect, "RawWidth", rawdims.c.x); - (*d3dintf->effect.set_float)(curr_effect, "RawHeight", rawdims.c.y); + (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &texsize.c.x); (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x); (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y); - (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); - (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); + (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", d3d->get_width()); + (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", d3d->get_height()); (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c index d44f657a879..8823d90979a 100644 --- a/src/osd/windows/drawd3d.c +++ b/src/osd/windows/drawd3d.c @@ -3036,6 +3036,9 @@ bool render_target::init(renderer *d3d, base *d3dintf, int width, int height, in bloom_index++; } + this->width = width; + this->height = height; + target_width = width * prescale_x; target_height = height * prescale_y; diff --git a/src/osd/windows/drawd3d.h b/src/osd/windows/drawd3d.h index 7fc10b3d740..6ab48555f21 100644 --- a/src/osd/windows/drawd3d.h +++ b/src/osd/windows/drawd3d.h @@ -104,6 +104,9 @@ public: int target_width; int target_height; + int prescale_x; + int prescale_y; + int width; int height;