From 8f613c115bfef732fe63bc58bd992a8e56c3d934 Mon Sep 17 00:00:00 2001 From: Ryan Holtz Date: Fri, 30 Aug 2013 01:05:13 +0000 Subject: more HLSL cleanup, part e of pi (nw) --- hlsl/bloom.fx | 4 +-- hlsl/downsample.fx | 21 ++++++++-------- hlsl/phosphor.fx | 6 ++--- hlsl/post.fx | 72 ++++++++++++++++++++++++------------------------------ hlsl/yiq_decode.fx | 7 +++--- hlsl/yiq_encode.fx | 4 +-- 6 files changed, 51 insertions(+), 63 deletions(-) (limited to 'hlsl') diff --git a/hlsl/bloom.fx b/hlsl/bloom.fx index dbdb13868b3..cec6aa3aab7 100644 --- a/hlsl/bloom.fx +++ b/hlsl/bloom.fx @@ -165,7 +165,6 @@ struct PS_INPUT //----------------------------------------------------------------------------- uniform float2 TargetSize; -uniform float2 SourceSize; VS_OUTPUT vs_main(VS_INPUT Input) { @@ -177,8 +176,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position.xy -= float2(0.5f, 0.5f); Output.Position.xy *= float2(2.0f, 2.0f); Output.Color = Input.Color; - float2 inversePixel = 1.0f / TargetSize; - Output.TexCoord = Input.Position.xy * inversePixel - float2(0.5f, 0.5f) * inversePixel; + Output.TexCoord = (Input.Position.xy + 0.5f) / TargetSize; return Output; } diff --git a/hlsl/downsample.fx b/hlsl/downsample.fx index 7c1adc383bb..8d073e4cdb0 100644 --- a/hlsl/downsample.fx +++ b/hlsl/downsample.fx @@ -2,11 +2,11 @@ // Effect File Variables //----------------------------------------------------------------------------- -texture Diffuse; +texture DiffuseTexture; sampler DiffuseSampler = sampler_state { - Texture = ; + Texture = ; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; @@ -48,8 +48,6 @@ struct PS_INPUT uniform float2 ScreenSize; uniform float2 TargetSize; -uniform float2 SourceSize; -uniform float2 PrimRatio; uniform float BloomRescale; VS_OUTPUT vs_main(VS_INPUT Input) @@ -59,14 +57,15 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position = float4(Input.Position.xyz, 1.0f); Output.Position.xy /= ScreenSize; Output.Position.y = 1.0f - Output.Position.y; - Output.Position.xy -= float2(0.5f, 0.5f); - Output.Position.xy *= float2(2.0f, 2.0f); + Output.Position.xy -= 0.5f; + Output.Position.xy *= 2.0f; Output.Color = Input.Color; - float2 inversePixel = 1.0f / ScreenSize; - Output.TexCoord01.xy = Input.Position.xy / ScreenSize + float2(0.5f, 0.5f) / TargetSize; - Output.TexCoord01.zw = Input.Position.xy / ScreenSize + float2(1.5f, 0.5f) / TargetSize; - Output.TexCoord23.xy = Input.Position.xy / ScreenSize + float2(0.5f, 1.5f) / TargetSize; - Output.TexCoord23.zw = Input.Position.xy / ScreenSize + float2(1.5f, 1.5f) / TargetSize; + float2 InvTargetSize = 1.0f / TargetSize; + float2 TexCoord = Input.Position.xy / ScreenSize; + Output.TexCoord01.xy = TexCoord + float2(0.5f, 0.5f) * InvTargetSize; + Output.TexCoord01.zw = TexCoord + float2(1.5f, 0.5f) * InvTargetSize; + Output.TexCoord23.xy = TexCoord + float2(0.5f, 1.5f) * InvTargetSize; + Output.TexCoord23.zw = TexCoord + float2(1.5f, 1.5f) * InvTargetSize; return Output; } diff --git a/hlsl/phosphor.fx b/hlsl/phosphor.fx index 99f7574e1f5..97575051843 100644 --- a/hlsl/phosphor.fx +++ b/hlsl/phosphor.fx @@ -61,8 +61,7 @@ struct PS_INPUT uniform float2 ScreenDims; -uniform float TextureWidth; -uniform float TextureHeight; +uniform float2 TargetDims; uniform float Passthrough; @@ -77,8 +76,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); Output.Color = Input.Color; - float2 HalfTexOffset = 0.5f / float2(TextureWidth, TextureHeight); - Output.TexCoord = Input.TexCoord + HalfTexOffset; + Output.TexCoord = Input.TexCoord + 0.5f / TargetDims; Output.PrevCoord = Output.TexCoord; return Output; diff --git a/hlsl/post.fx b/hlsl/post.fx index 0fb466926ba..89a92fd6969 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -2,11 +2,11 @@ // Scanline & Shadowmask Effect //----------------------------------------------------------------------------- -texture Diffuse; +texture DiffuseTexture; sampler DiffuseSampler = sampler_state { - Texture = ; + Texture = ; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; @@ -15,11 +15,11 @@ sampler DiffuseSampler = sampler_state AddressW = CLAMP; }; -texture Shadow; +texture ShadowTexture; sampler ShadowSampler = sampler_state { - Texture = ; + Texture = ; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; @@ -58,9 +58,7 @@ struct PS_INPUT //----------------------------------------------------------------------------- uniform float2 ScreenDims; - uniform float2 SourceDims; - uniform float2 SourceRect; VS_OUTPUT vs_main(VS_INPUT Input) @@ -87,55 +85,50 @@ uniform float PI = 3.14159265f; uniform float PincushionAmount = 0.00f; uniform float CurvatureAmount = 0.08f; -uniform float ScanlineAmount = 1.0f; +uniform float ScanlineAlpha = 1.0f; uniform float ScanlineScale = 1.0f; uniform float ScanlineBrightScale = 1.0f; uniform float ScanlineBrightOffset = 1.0f; uniform float ScanlineOffset = 1.0f; uniform float ScanlineHeight = 0.5f; -uniform float UseShadow = 0.0f; -uniform float ShadowBrightness = 1.0f; -uniform float ShadowPixelSizeX = 3.0f; -uniform float ShadowPixelSizeY = 3.0f; -uniform float ShadowMaskSizeX = 3.0f; -uniform float ShadowMaskSizeY = 3.0f; -uniform float ShadowU = 0.375f; -uniform float ShadowV = 0.375f; -uniform float ShadowWidth = 8.0f; -uniform float ShadowHeight = 8.0f; +uniform float ShadowAlpha = 0.0f; +uniform float2 ShadowCount = float2(320.0f, 240.0f); +uniform float2 ShadowUV = float2(0.375f, 0.375f); +uniform float2 ShadowDims = float2(8.0f, 8.0f); uniform float3 Power = float3(1.0f, 1.0f, 1.0f); uniform float3 Floor = float3(0.0f, 0.0f, 0.0f); float4 ps_main(PS_INPUT Input) : COLOR { - float2 Ratios = 1.0f / SourceRect; - + float2 UsedArea = 1.0f / SourceRect; + float2 HalfRect = SourceRect * 0.5f; + float2 R2 = 1.0f / pow(length(UsedArea), 2.0f); // -- Screen Pincushion Calculation -- - float2 PinUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f; - float PincushionR2 = pow(length(PinUnitCoord), 2.0f) / pow(length(Ratios), 2.0f); + float2 PinUnitCoord = Input.TexCoord * UsedArea * 2.0f - 1.0f; + float PincushionR2 = pow(length(PinUnitCoord), 2.0f) * R2; float2 PincushionCurve = PinUnitCoord * PincushionAmount * PincushionR2; float2 BaseCoord = Input.TexCoord; float2 ScanCoord = BaseCoord - 0.5f / ScreenDims; - BaseCoord -= 0.5f / Ratios; - BaseCoord *= 1.0f - PincushionAmount * Ratios * 0.2f; // Warning: Magic constant - BaseCoord += 0.5f / Ratios; + BaseCoord -= HalfRect; + BaseCoord *= 1.0f - PincushionAmount * UsedArea * 0.2f; // Warning: Magic constant + BaseCoord += HalfRect; BaseCoord += PincushionCurve; - ScanCoord -= 0.5f / Ratios; - ScanCoord *= 1.0f - PincushionAmount * Ratios * 0.2f; // Warning: Magic constant - ScanCoord += 0.5f / Ratios; + ScanCoord -= HalfRect; + ScanCoord *= 1.0f - PincushionAmount * UsedArea * 0.2f; // Warning: Magic constant + ScanCoord += HalfRect; ScanCoord += PincushionCurve; - float2 CurveClipUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f; - float CurvatureClipR2 = pow(length(CurveClipUnitCoord),2.0f) / pow(length(Ratios), 2.0f); + float2 CurveClipUnitCoord = Input.TexCoord * UsedArea * 2.0f - 1.0f; + float CurvatureClipR2 = pow(length(CurveClipUnitCoord), 2.0f) * R2; float2 CurvatureClipCurve = CurveClipUnitCoord * CurvatureAmount * CurvatureClipR2; float2 ScreenClipCoord = Input.TexCoord; - ScreenClipCoord -= 0.5f / Ratios; - ScreenClipCoord *= 1.0f - CurvatureAmount * Ratios * 0.2f; // Warning: Magic constant - ScreenClipCoord += 0.5f / Ratios; + ScreenClipCoord -= HalfRect; + ScreenClipCoord *= 1.0f - CurvatureAmount * UsedArea * 0.2f; // Warning: Magic constant + ScreenClipCoord += HalfRect; ScreenClipCoord += CurvatureClipCurve; // RGB Pincushion Calculation @@ -151,21 +144,20 @@ float4 ps_main(PS_INPUT Input) : COLOR // -- Scanline Simulation -- float InnerSine = ScanCoord.y * SourceDims.y * ScanlineScale; float ScanBrightMod = sin(InnerSine * PI + ScanlineOffset * SourceDims.y); - float3 ScanBrightness = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f) * 0.5f, ScanlineAmount); + float3 ScanBrightness = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f) * 0.5f, ScanlineAlpha); float3 Scanned = BaseTexel.rgb * ScanBrightness; // -- Color Compression (increasing the floor of the signal without affecting the ceiling) -- Scanned = Floor + (1.0f - Floor) * Scanned; - float2 ShadowDims = float2(ShadowWidth, ShadowHeight); - float2 ShadowUV = float2(ShadowU, ShadowV); - float2 ShadowMaskSize = float2(ShadowMaskSizeX, ShadowMaskSizeY); - float2 ShadowFrac = frac(BaseCoord * ShadowMaskSize); - float2 ShadowCoord = ShadowFrac * ShadowUV + float2(1.5f / ShadowWidth, 1.5f / ShadowHeight); - float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, ShadowCoord).rgb, UseShadow); + // Shadow mask + // Note: This is broken right now and needs fixed + float2 ShadowFrac = frac(BaseCoord * ShadowCount); + float2 ShadowCoord = ShadowFrac * ShadowUV + 0.5f / ShadowDims; + float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, ShadowCoord).rgb, ShadowAlpha); // -- Final Pixel -- - float4 Output = float4(Scanned * lerp(1.0f, ShadowTexel, ShadowBrightness), BaseTexel.a) * Input.Color; + float4 Output = float4(Scanned * ShadowTexel, BaseTexel.a) * Input.Color; Output.r = pow(Output.r, Power.r); Output.g = pow(Output.g, Power.g); diff --git a/hlsl/yiq_decode.fx b/hlsl/yiq_decode.fx index 00d5a6d721a..cdd804af5e4 100644 --- a/hlsl/yiq_decode.fx +++ b/hlsl/yiq_decode.fx @@ -104,7 +104,7 @@ float4 ps_main(PS_INPUT Input) : COLOR float MaxC = 2.1183f; float MinC = -1.1183f; float CRange = MaxC - MinC; - float FrameWidthx4 = SourceDims.x * 4.0f / SourceRect.x; + 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; @@ -124,14 +124,15 @@ float4 ps_main(PS_INPUT Input) : COLOR 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 VPosition = (CoordY * SourceRect.y) * (SourceDims.x / SourceRect.x); 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 WT = W * (CoordX * SourceRect.x + VPosition + BValue) + OValue; + float4 T = (CoordX / SourceRect.x) + VPosition + BValue; + float4 WT = W * T + OValue; float4 SincKernel = 0.54f + 0.46f * cos(PI2Length * n4); float4 SincYIn1 = Fc_y1_pi2 * n4; diff --git a/hlsl/yiq_encode.fx b/hlsl/yiq_encode.fx index f87141d689b..ffd4a8cb727 100644 --- a/hlsl/yiq_encode.fx +++ b/hlsl/yiq_encode.fx @@ -103,8 +103,8 @@ float4 ps_main(PS_INPUT Input) : COLOR float4 Q = float4(dot(Texel0, QDot), dot(Texel1, QDot), dot(Texel2, QDot), dot(Texel3, QDot)); float4 W = PI2 * CCValue * ScanTime; - float4 VPosition = (CoordY / SourceRect.y) * (SourceDims.x * SourceRect.x); - float4 T = CoordX * SourceRect.x + VPosition + BValue; + float4 VPosition = (CoordY * SourceRect.y) * (SourceDims.x / SourceRect.x); + float4 T = CoordX / SourceRect.x + VPosition + BValue; float4 C = Y + I * cos(T * W) + Q * sin(T * W); C = (C - MinC) / CRange; -- cgit v1.2.3-70-g09d2