diff options
author | Miodrag Milanović <mmicko@gmail.com> | 2016-01-27 06:46:02 +0100 |
---|---|---|
committer | Miodrag Milanović <mmicko@gmail.com> | 2016-01-27 06:46:02 +0100 |
commit | 8b283b9753e6848fec640c0d174a33f90595f6a7 (patch) | |
tree | 554beaee0abbf31376280ed6b21c409c41a1f95b | |
parent | fa02dd2f6f5a73ade0b203f9d50e6734b6d1af5a (diff) | |
parent | 8d5848718c30a960d07d569937cb1678f75f0463 (diff) |
Merge pull request #587 from ImJezze/pull
HLSL: NTSC and color convergence refactoring
-rw-r--r-- | artwork/monochrome-chessboard.png | bin | 0 -> 23358 bytes | |||
-rw-r--r-- | artwork/monochrome-matrix.png | bin | 31397 -> 33194 bytes | |||
-rw-r--r-- | artwork/slot-mask-aligned.png | bin | 0 -> 26638 bytes | |||
-rw-r--r-- | docs/hlsl.txt | 28 | ||||
-rw-r--r-- | hlsl/artwork_support/distortion.fx | 6 | ||||
-rw-r--r-- | hlsl/artwork_support/post.fx | 78 | ||||
-rw-r--r-- | hlsl/bloom.fx | 157 | ||||
-rw-r--r-- | hlsl/color.fx | 18 | ||||
-rw-r--r-- | hlsl/deconverge.fx | 100 | ||||
-rw-r--r-- | hlsl/distortion.fx | 17 | ||||
-rw-r--r-- | hlsl/downsample.fx | 29 | ||||
-rw-r--r-- | hlsl/focus.fx | 34 | ||||
-rw-r--r-- | hlsl/ntsc.fx | 252 | ||||
-rw-r--r-- | hlsl/phosphor.fx | 17 | ||||
-rw-r--r-- | hlsl/pincushion.fx | 126 | ||||
-rw-r--r-- | hlsl/post.fx | 72 | ||||
-rw-r--r-- | hlsl/prescale.fx | 24 | ||||
-rw-r--r-- | hlsl/primary.fx | 16 | ||||
-rw-r--r-- | hlsl/vector.fx | 10 | ||||
-rw-r--r-- | hlsl/yiq_decode.fx | 187 | ||||
-rw-r--r-- | hlsl/yiq_encode.fx | 130 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.cpp | 493 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.h | 13 | ||||
-rw-r--r-- | src/osd/modules/render/drawd3d.cpp | 33 | ||||
-rw-r--r-- | src/osd/modules/render/drawd3d.h | 3 | ||||
-rw-r--r-- | src/osd/windows/winmain.cpp | 12 | ||||
-rw-r--r-- | src/osd/windows/winmain.h | 8 |
27 files changed, 893 insertions, 970 deletions
diff --git a/artwork/monochrome-chessboard.png b/artwork/monochrome-chessboard.png Binary files differnew file mode 100644 index 00000000000..b10019847bf --- /dev/null +++ b/artwork/monochrome-chessboard.png diff --git a/artwork/monochrome-matrix.png b/artwork/monochrome-matrix.png Binary files differindex c44d063c397..c1180363087 100644 --- a/artwork/monochrome-matrix.png +++ b/artwork/monochrome-matrix.png diff --git a/artwork/slot-mask-aligned.png b/artwork/slot-mask-aligned.png Binary files differnew file mode 100644 index 00000000000..764c5fcb5be --- /dev/null +++ b/artwork/slot-mask-aligned.png diff --git a/docs/hlsl.txt b/docs/hlsl.txt index 5bde3f85ebb..d42f608c5c5 100644 --- a/docs/hlsl.txt +++ b/docs/hlsl.txt @@ -38,15 +38,16 @@ scanline_size 0.0 to 4.0 The overall height of each scanline. scanline_height [height] Individual height scaling value for scanlines. scanline_bright_scale 0.0 to 2.0 The overall brightness multiplier for each scanline. scanline_bright_offset 0.0 to 1.0 The overall brightness additive value for each scanline. -scanline_jitter 0.0 to 2.0 The relative scanline movement per field. +scanline_jitter 0.0 to 1.0 The relative scanline movement per field. +hum_bar_alpha 0.0 to 1.0 The maximum darkness of the hum bar gradient. defocus [xval,yval] This defines the overall defocus radius for the three - post-converged beams. Values allowed range from 0.0 to - 32.0. + post-converged beams. Values allowed range from 0.0 to + 10.0. converge_x [r,g,b] Convergence in screen-relative X direction. converge_y [r,g,b] Convergence in screen-relative Y direction. radial_converge_x [r,g,b] Radial convergence in screen-relative X direction. radial_converge_y [r,g,b] Radial convergence in screen-relative Y direction. - Allowed values for convergence: -150 to 150 for each color. + Allowed values for convergence: -10.0 to 10.0 for each color. red_ratio [r,g,b] These parameters define a 3x3 matrix which is multiplied grn_ratio [r,g,b] by the incoming RGB signal. This can be used for any blu_ratio [r,g,b] standard matrix convolution, including H/S/V or simply @@ -78,15 +79,16 @@ NTSC Processing Parameters -------------------------- Name Default Values Description -yiq_cc 3.59754545 Color Carrier frequency for NTSC signal processing. -yiq_a 0.5 A value for NTSC signal processing. -yiq_b 0.5 B value for NTSC signal processing. -yiq_o 0.0 Outgoing Color Carrier phase offset for NTSC signal processing. -yiq_p 1.0 Incoming Pixel Clock scaling value for NTSC signal processing. -yiq_n 1.0 Y filter notch width for NTSC signal processing. -yiq_y 6.0 Y filter cutoff frequency for NTSC signal processing. -yiq_i 1.2 I filter cutoff frequency for NTSC signal processing. -yiq_q 0.6 Q filter cutoff frequency for NTSC signal processing. +yiq_jitter 0.0 Jitter for the NTSC signal processing. (0.0 to 1.0) +yiq_cc 3.57954545 Color Carrier frequency for NTSC signal processing. (0.0 to 6.0) +yiq_a 0.5 A value for NTSC signal processing. (-1.0 to 1.0) +yiq_b 0.5 B value for NTSC signal processing. (-1.0 to 1.0) +yiq_o 0.0 Outgoing Color Carrier phase offset for NTSC signal processing. (-3.0 to 3.0) +yiq_p 1.0 Incoming Pixel Clock scaling value for NTSC signal processing. (-3.0 to 3.0) +yiq_n 1.0 Y filter notch width for NTSC signal processing. (0.0 to 6.0) +yiq_y 6.0 Y filter cutoff frequency for NTSC signal processing. (0.0 to 6.0) +yiq_i 1.2 I filter cutoff frequency for NTSC signal processing. (0.0 to 6.0) +yiq_q 0.6 Q filter cutoff frequency for NTSC signal processing. (0.0 to 6.0) yiq_scan_time 52.6 Horizontal scanline duration for NTSC signal processing. (usec) yiq_phase_count 2 Phase Count value for NTSC signal processing. (3 for NES, else 2) diff --git a/hlsl/artwork_support/distortion.fx b/hlsl/artwork_support/distortion.fx index 65896bceb96..333363afeb8 100644 --- a/hlsl/artwork_support/distortion.fx +++ b/hlsl/artwork_support/distortion.fx @@ -4,6 +4,10 @@ // Distortion Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + texture DiffuseTexture; sampler DiffuseSampler = sampler_state @@ -85,7 +89,7 @@ float4 ps_main(PS_INPUT Input) : COLOR // Distortion Effect //----------------------------------------------------------------------------- -technique DistortionTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/artwork_support/post.fx b/hlsl/artwork_support/post.fx index e7618bafd0e..9a3b693cd61 100644 --- a/hlsl/artwork_support/post.fx +++ b/hlsl/artwork_support/post.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- -// Scanline & Shadowmask Effect +// Scanline, Shadowmask & Distortion Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture DiffuseTexture; @@ -62,6 +66,7 @@ struct PS_INPUT static const float Epsilon = 1.0e-7f; static const float PI = 3.1415927f; +static const float PHI = 1.618034f; static const float E = 2.7182817f; static const float Gelfond = 23.140692f; // e^pi (Gelfond constant) static const float GelfondSchneider = 2.6651442f; // 2^sqrt(2) (Gelfond-Schneider constant) @@ -70,11 +75,6 @@ static const float GelfondSchneider = 2.6651442f; // 2^sqrt(2) (Gelfond-Schneide // Functions //----------------------------------------------------------------------------- -bool xor(bool a, bool b) -{ - return (a || b) && !(a && b); -} - // www.stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader/ float random(float2 seed) { @@ -98,7 +98,7 @@ float roundBox(float2 p, float2 b, float r) } //----------------------------------------------------------------------------- -// Scanline & Shadowmask Vertex Shader +// Scanline, Shadowmask & Distortion Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; // size of the window or fullscreen @@ -110,8 +110,8 @@ uniform float2 QuadDims; // size of the screen quad uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) uniform float2 ShadowUVOffset = float2(0.0f, 0.0f); -uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation -uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation +uniform bool SwapXY = false; + uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270° uniform bool PrepareBloom = false; // disables some effects for rendering bloom textures @@ -122,7 +122,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) VS_OUTPUT Output = (VS_OUTPUT)0; float2 shadowUVOffset = ShadowUVOffset; - shadowUVOffset = xor(OrientationSwapXY, RotationSwapXY) + shadowUVOffset = SwapXY ? shadowUVOffset.yx : shadowUVOffset.xy; @@ -149,9 +149,14 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Post-Processing Pixel Shader +// Scanline, Shadowmask & Distortion Pixel Shader //----------------------------------------------------------------------------- +uniform float HumBarHertzRate = 60.0f / 59.94f - 1.0f; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) +uniform float HumBarAlpha = 0.0f; + +uniform float TimeMilliseconds = 0.0f; + uniform float2 ScreenScale = float2(1.0f, 1.0f); uniform float2 ScreenOffset = float2(0.0f, 0.0f); @@ -223,7 +228,7 @@ float GetSpotAddend(float2 coord, float amount) // normalized screen canvas ratio float2 CanvasRatio = PrepareVector ? float2(1.0f, QuadDims.y / QuadDims.x) - : float2(1.0f, xor(OrientationSwapXY, RotationSwapXY) + : float2(1.0f, SwapXY ? QuadDims.x / QuadDims.y : QuadDims.y / QuadDims.x); @@ -236,7 +241,7 @@ float GetSpotAddend(float2 coord, float amount) : RotationType == 3 // 270° ? float2(0.25f, 0.25f) : float2(-0.25f, 0.25f) - : OrientationSwapXY + : SwapXY ? float2(0.25f, 0.25f) : float2(-0.25f, 0.25f); @@ -268,7 +273,7 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount) float2 CanvasDims = PrepareVector ? ScreenDims - : xor(OrientationSwapXY, RotationSwapXY) + : SwapXY ? QuadDims.yx / SourceRect : QuadDims.xy / SourceRect; @@ -371,9 +376,7 @@ float4 ps_main(PS_INPUT Input) : COLOR float2 ScreenTexelDims = 1.0f / ScreenDims; float2 SourceTexelDims = 1.0f / SourceDims; - float2 HalfSourceRect = PrepareVector - ? float2(0.5f, 0.5f) - : SourceRect * 0.5f; + float2 HalfSourceRect = SourceRect * 0.5f; float2 ScreenCoord = Input.ScreenCoord / ScreenDims; ScreenCoord = GetCoords(ScreenCoord, float2(0.5f, 0.5f), CurvatureAmount * 0.25f); // reduced amount @@ -399,37 +402,37 @@ float4 ps_main(PS_INPUT Input) : COLOR } // Mask Simulation (may not affect bloom) - if (!PrepareBloom) + if (!PrepareBloom && ShadowAlpha > 0.0f) { float2 shadowDims = ShadowDims; - shadowDims = xor(OrientationSwapXY, RotationSwapXY) + shadowDims = SwapXY ? shadowDims.yx : shadowDims.xy; float2 shadowUV = ShadowUV; - // shadowUV = xor(OrientationSwapXY, RotationSwapXY) + // shadowUV = SwapXY // ? shadowUV.yx // : shadowUV.xy; float2 screenCoord = ShadowTileMode == 0 ? ScreenCoord : BaseCoord; - screenCoord = xor(OrientationSwapXY, RotationSwapXY) + screenCoord = SwapXY ? screenCoord.yx : screenCoord.xy; float2 shadowCount = ShadowCount; - shadowCount = xor(OrientationSwapXY, RotationSwapXY) + shadowCount = SwapXY ? shadowCount.yx : shadowCount.xy; float2 shadowTile = ((ShadowTileMode == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount); - shadowTile = xor(OrientationSwapXY, RotationSwapXY) + shadowTile = SwapXY ? shadowTile.yx : shadowTile.xy; float2 ShadowFrac = frac(screenCoord / shadowTile); float2 ShadowCoord = (ShadowFrac * shadowUV); ShadowCoord += 0.5f / shadowDims; // half texel offset - // ShadowCoord = xor(OrientationSwapXY, RotationSwapXY) + // ShadowCoord = SwapXY // ? ShadowCoord.yx // : ShadowCoord.xy; @@ -458,15 +461,24 @@ float4 ps_main(PS_INPUT Input) : COLOR // Scanline Simulation (may not affect bloom) if (!PrepareBloom) { - // Scanline Simulation (disabled for vector) - if (!PrepareVector) + // Scanline Simulation (may not affect vector screen) + if (!PrepareVector && ScanlineAlpha > 0.0f) { - float InnerSine = BaseCoord.y * ScanlineScale * SourceDims.y; - float ScanJitter = ScanlineOffset * SourceDims.y; - float ScanBrightMod = sin(InnerSine * PI + ScanJitter); - float3 ScanColor = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f + ScanlineBrightOffset) * 0.5f, ScanlineAlpha); + float ScanCoord = BaseCoord.y * SourceDims.y * ScanlineScale * PI; + float ScanCoordJitter = ScanlineOffset * PHI; + float ScanSine = sin(ScanCoord + ScanCoordJitter); + float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineHeight); + float ScanBrightness = ScanSineScaled * ScanlineBrightScale + 1.0f + ScanlineBrightOffset; - BaseColor.rgb *= ScanColor; + BaseColor.rgb *= lerp(1.0f, ScanBrightness * 0.5f, ScanlineAlpha); + } + + // Hum Bar Simulation (may not affect vector screen) + if (!PrepareVector && HumBarAlpha > 0.0f) + { + float HumTimeStep = frac(TimeMilliseconds * HumBarHertzRate); + float HumBrightness = 1.0 - frac(BaseCoord.y / SourceRect.y + HumTimeStep) * HumBarAlpha; + BaseColor.rgb *= HumBrightness; } } @@ -511,14 +523,12 @@ float4 ps_main(PS_INPUT Input) : COLOR // Scanline & Shadowmask Effect //----------------------------------------------------------------------------- -technique ScanMaskTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - //Sampler[0] = <DiffuseSampler>; - VertexShader = compile vs_3_0 vs_main(); PixelShader = compile ps_3_0 ps_main(); } diff --git a/hlsl/bloom.fx b/hlsl/bloom.fx index f766bf9ee39..1ee152adfec 100644 --- a/hlsl/bloom.fx +++ b/hlsl/bloom.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- -// Effect File Variables +// Bloom Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture DiffuseA; @@ -145,17 +149,17 @@ struct VS_OUTPUT { float4 Position : POSITION; float4 Color : COLOR0; - float4 TexCoord01 : TEXCOORD0; - float4 TexCoord23 : TEXCOORD1; - float4 TexCoord45 : TEXCOORD2; - float4 TexCoord67 : TEXCOORD3; - float4 TexCoord89 : TEXCOORD4; - float2 TexCoordA : TEXCOORD5; + float2 TexCoord0 : TEXCOORD0; + float4 TexCoord12 : TEXCOORD1; + float4 TexCoord34 : TEXCOORD2; + float4 TexCoord56 : TEXCOORD3; + float4 TexCoord78 : TEXCOORD4; + float4 TexCoord9A : TEXCOORD5; }; struct VS_INPUT { - float3 Position : POSITION; + float4 Position : POSITION; float4 Color : COLOR0; float2 TexCoord : TEXCOORD0; }; @@ -163,12 +167,12 @@ struct VS_INPUT struct PS_INPUT { float4 Color : COLOR0; - float4 TexCoord01 : TEXCOORD0; - float4 TexCoord23 : TEXCOORD1; - float4 TexCoord45 : TEXCOORD2; - float4 TexCoord67 : TEXCOORD3; - float4 TexCoord89 : TEXCOORD4; - float2 TexCoordA : TEXCOORD5; + float2 TexCoord0 : TEXCOORD0; + float4 TexCoord12 : TEXCOORD1; + float4 TexCoord34 : TEXCOORD2; + float4 TexCoord56 : TEXCOORD3; + float4 TexCoord78 : TEXCOORD4; + float4 TexCoord9A : TEXCOORD5; }; //----------------------------------------------------------------------------- @@ -198,13 +202,14 @@ float random(float2 seed) uniform float2 ScreenDims; uniform float2 TargetDims; +uniform float2 SourceRect; -uniform float4 Level01Size; -uniform float4 Level23Size; -uniform float4 Level45Size; -uniform float4 Level67Size; -uniform float4 Level89Size; -uniform float2 LevelASize; +uniform float2 Level0Size; +uniform float4 Level12Size; +uniform float4 Level34Size; +uniform float4 Level56Size; +uniform float4 Level78Size; +uniform float4 Level9ASize; VS_OUTPUT vs_main(VS_INPUT Input) { @@ -221,13 +226,12 @@ VS_OUTPUT vs_main(VS_INPUT Input) float2 TexCoord = Input.Position.xy / ScreenDims; TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) - Output.TexCoord01.xy = TexCoord.xy; - Output.TexCoord01.zw = TexCoord.xy + 0.5f / Level01Size.zw; - Output.TexCoord23 = TexCoord.xyxy + 0.5f / Level23Size; - Output.TexCoord45 = TexCoord.xyxy + 0.5f / Level45Size; - Output.TexCoord67 = TexCoord.xyxy + 0.5f / Level67Size; - Output.TexCoord89 = TexCoord.xyxy + 0.5f / Level89Size; - Output.TexCoordA = TexCoord.xy + 0.5f / LevelASize; + Output.TexCoord0 = TexCoord; + Output.TexCoord12 = TexCoord.xyxy + (0.5f / Level12Size); + Output.TexCoord34 = TexCoord.xyxy + (0.5f / Level34Size); + Output.TexCoord56 = TexCoord.xyxy + (0.5f / Level56Size); + Output.TexCoord78 = TexCoord.xyxy + (0.5f / Level78Size); + Output.TexCoord9A = TexCoord.xyxy + (0.5f / Level9ASize); return Output; } @@ -236,11 +240,14 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Bloom Pixel Shader //----------------------------------------------------------------------------- -uniform float4 Level0123Weight; -uniform float4 Level4567Weight; -uniform float3 Level89AWeight; +uniform float Level0Weight; +uniform float2 Level12Weight; +uniform float2 Level34Weight; +uniform float2 Level56Weight; +uniform float2 Level78Weight; +uniform float2 Level9AWeight; -uniform int BloomBlendMode = 1; // 0 addition, 1 darken +uniform int BloomBlendMode = 0; // 0 addition, 1 darken uniform float BloomScale; uniform float3 BloomOverdrive; @@ -252,34 +259,34 @@ float3 GetNoiseFactor(float3 n, float random) float4 ps_main(PS_INPUT Input) : COLOR { - float3 texel0 = tex2D(DiffuseSampler0, Input.TexCoord01.xy).rgb; - float3 texel1 = tex2D(DiffuseSampler1, Input.TexCoord01.zw).rgb; - float3 texel2 = tex2D(DiffuseSampler2, Input.TexCoord23.xy).rgb; - float3 texel3 = tex2D(DiffuseSampler3, Input.TexCoord23.zw).rgb; - float3 texel4 = tex2D(DiffuseSampler4, Input.TexCoord45.xy).rgb; - float3 texel5 = tex2D(DiffuseSampler5, Input.TexCoord45.zw).rgb; - float3 texel6 = tex2D(DiffuseSampler6, Input.TexCoord67.xy).rgb; - float3 texel7 = tex2D(DiffuseSampler7, Input.TexCoord67.zw).rgb; - float3 texel8 = tex2D(DiffuseSampler8, Input.TexCoord89.xy).rgb; - float3 texel9 = tex2D(DiffuseSampler9, Input.TexCoord89.zw).rgb; - float3 texelA = tex2D(DiffuseSamplerA, Input.TexCoordA).rgb; + float3 texel0 = tex2D(DiffuseSampler0, Input.TexCoord0).rgb; + float3 texel1 = tex2D(DiffuseSampler1, Input.TexCoord12.xy).rgb; + float3 texel2 = tex2D(DiffuseSampler2, Input.TexCoord12.zw).rgb; + float3 texel3 = tex2D(DiffuseSampler3, Input.TexCoord34.xy).rgb; + float3 texel4 = tex2D(DiffuseSampler4, Input.TexCoord34.zw).rgb; + float3 texel5 = tex2D(DiffuseSampler5, Input.TexCoord56.xy).rgb; + float3 texel6 = tex2D(DiffuseSampler6, Input.TexCoord56.zw).rgb; + float3 texel7 = tex2D(DiffuseSampler7, Input.TexCoord78.xy).rgb; + float3 texel8 = tex2D(DiffuseSampler8, Input.TexCoord78.zw).rgb; + float3 texel9 = tex2D(DiffuseSampler9, Input.TexCoord9A.xy).rgb; + float3 texelA = tex2D(DiffuseSamplerA, Input.TexCoord9A.zw).rgb; float3 blend; // addition if (BloomBlendMode == 0) { - texel0 *= Level0123Weight.x; - texel1 *= Level0123Weight.y; - texel2 *= Level0123Weight.z; - texel3 *= Level0123Weight.w; - texel4 *= Level4567Weight.x; - texel5 *= Level4567Weight.y; - texel6 *= Level4567Weight.z; - texel7 *= Level4567Weight.w; - texel8 *= Level89AWeight.x; - texel9 *= Level89AWeight.y; - texelA *= Level89AWeight.z; + texel0 *= Level0Weight; + texel1 *= Level12Weight.x; + texel2 *= Level12Weight.y; + texel3 *= Level34Weight.x; + texel4 *= Level34Weight.y; + texel5 *= Level56Weight.x; + texel6 *= Level56Weight.y; + texel7 *= Level78Weight.x; + texel8 *= Level78Weight.y; + texel9 *= Level9AWeight.x; + texelA *= Level9AWeight.y; float3 bloom = float3( texel1 + @@ -302,15 +309,15 @@ float4 ps_main(PS_INPUT Input) : COLOR bloom.b += bloomOverdrive.r * 0.5f; bloom.b += bloomOverdrive.g * 0.5f; - float2 NoiseCoord = Input.TexCoord01.xy; + float2 NoiseCoord = Input.TexCoord0; float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord)); - + blend = texel0 + bloom * NoiseFactor; } // darken else - { + { texel1 = min(texel0, texel1); texel2 = min(texel0, texel2); texel3 = min(texel0, texel3); @@ -322,44 +329,32 @@ float4 ps_main(PS_INPUT Input) : COLOR texel9 = min(texel0, texel9); texelA = min(texel0, texelA); - blend = texel0 * Level0123Weight.x; - blend = lerp(blend, texel1, Level0123Weight.y * BloomScale); - blend = lerp(blend, texel2, Level0123Weight.z * BloomScale); - blend = lerp(blend, texel3, Level0123Weight.w * BloomScale); - blend = lerp(blend, texel4, Level4567Weight.x * BloomScale); - blend = lerp(blend, texel5, Level4567Weight.y * BloomScale); - blend = lerp(blend, texel6, Level4567Weight.z * BloomScale); - blend = lerp(blend, texel7, Level4567Weight.w * BloomScale); - blend = lerp(blend, texel8, Level89AWeight.x * BloomScale); - blend = lerp(blend, texel9, Level89AWeight.y * BloomScale); - blend = lerp(blend, texelA, Level89AWeight.z * BloomScale); + blend = texel0 * Level0Weight; + blend = lerp(blend, texel1, Level12Weight.x * BloomScale); + blend = lerp(blend, texel2, Level12Weight.y * BloomScale); + blend = lerp(blend, texel3, Level34Weight.x * BloomScale); + blend = lerp(blend, texel4, Level34Weight.y * BloomScale); + blend = lerp(blend, texel5, Level56Weight.x * BloomScale); + blend = lerp(blend, texel6, Level56Weight.y * BloomScale); + blend = lerp(blend, texel7, Level78Weight.x * BloomScale); + blend = lerp(blend, texel8, Level78Weight.y * BloomScale); + blend = lerp(blend, texel9, Level9AWeight.x * BloomScale); + blend = lerp(blend, texelA, Level9AWeight.y * BloomScale); } return float4(blend, 1.0f); } //----------------------------------------------------------------------------- -// Bloom Effect +// Bloom Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler0>; // 2048x2048 - Sampler[1] = <DiffuseSampler1>; // 1024x1024 - Sampler[2] = <DiffuseSampler2>; // 512x512 - Sampler[3] = <DiffuseSampler3>; // 256x256 - Sampler[4] = <DiffuseSampler4>; // 128x128 - Sampler[5] = <DiffuseSampler5>; // 64x64 - Sampler[6] = <DiffuseSampler6>; // 32x32 - Sampler[7] = <DiffuseSampler7>; // 16x16 - Sampler[8] = <DiffuseSampler8>; // 8x8 - Sampler[9] = <DiffuseSampler9>; // 4x4 - Sampler[10] = <DiffuseSamplerA>; // 2x2 - VertexShader = compile vs_3_0 vs_main(); PixelShader = compile ps_3_0 ps_main(); } diff --git a/hlsl/color.fx b/hlsl/color.fx index 7724eeb10f7..79f55260d4f 100644 --- a/hlsl/color.fx +++ b/hlsl/color.fx @@ -4,6 +4,10 @@ // Color-Convolution Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + texture Diffuse; sampler DiffuseSampler = sampler_state @@ -43,7 +47,7 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Post-Processing Vertex Shader +// Color-Convolution Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; @@ -68,7 +72,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Post-Processing Pixel Shader +// Color-Convolution Pixel Shader //----------------------------------------------------------------------------- uniform float3 RedRatios = float3(1.0f, 0.0f, 0.0f); @@ -81,23 +85,23 @@ uniform float Saturation = 1.0f; float4 ps_main(PS_INPUT Input) : COLOR { float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); - + float3 OutRGB = BaseTexel.rgb; // RGB Tint & Shift float ShiftedRed = dot(OutRGB, RedRatios); float ShiftedGrn = dot(OutRGB, GrnRatios); float ShiftedBlu = dot(OutRGB, BluRatios); - + // RGB Scale & Offset float3 OutTexel = float3(ShiftedRed, ShiftedGrn, ShiftedBlu) * Scale + Offset; - + // Saturation float3 Grayscale = float3(0.299f, 0.587f, 0.114f); float OutLuma = dot(OutTexel, Grayscale); float3 OutChroma = OutTexel - OutLuma; float3 Saturated = OutLuma + OutChroma * Saturation; - + return float4(Saturated, BaseTexel.a); } @@ -105,7 +109,7 @@ float4 ps_main(PS_INPUT Input) : COLOR // Color-Convolution Technique //----------------------------------------------------------------------------- -technique ColorTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/deconverge.fx b/hlsl/deconverge.fx index 3de37764e4f..3c1cbeeeb1f 100644 --- a/hlsl/deconverge.fx +++ b/hlsl/deconverge.fx @@ -1,9 +1,13 @@ // license:BSD-3-Clause -// copyright-holders:Ryan Holtz +// copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- // Deconvergence Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + texture Diffuse; sampler DiffuseSampler = sampler_state @@ -25,12 +29,8 @@ struct VS_OUTPUT { float4 Position : POSITION; float4 Color : COLOR0; - //float2 RedCoord : TEXCOORD0; - //float2 GrnCoord : TEXCOORD1; - //float2 BluCoord : TEXCOORD2; - float3 CoordX : TEXCOORD0; - float3 CoordY : TEXCOORD1; - float2 TexCoord : TEXCOORD2; + float3 TexCoordX : TEXCOORD0; + float3 TexCoordY : TEXCOORD1; }; struct VS_INPUT @@ -38,61 +38,78 @@ struct VS_INPUT float4 Position : POSITION; float4 Color : COLOR0; float2 TexCoord : TEXCOORD0; - float2 Unused : TEXCOORD1; }; struct PS_INPUT { float4 Color : COLOR0; - //float2 RedCoord : TEXCOORD0; - //float2 GrnCoord : TEXCOORD1; - //float2 BluCoord : TEXCOORD2; - float3 CoordX : TEXCOORD0; - float3 CoordY : TEXCOORD1; - float2 TexCoord : TEXCOORD2; + float3 TexCoordX : TEXCOORD0; + float3 TexCoordY : TEXCOORD1; }; //----------------------------------------------------------------------------- // Deconvergence Vertex Shader //----------------------------------------------------------------------------- -uniform float3 ConvergeX = float3(0.0f, 0.0f, 0.0f); -uniform float3 ConvergeY = float3(0.0f, 0.0f, 0.0f); - uniform float2 ScreenDims; uniform float2 SourceDims; uniform float2 SourceRect; +uniform float2 TargetDims; +uniform float2 QuadDims; + +uniform bool SwapXY = false; +uniform float3 ConvergeX = float3(0.0f, 0.0f, 0.0f); +uniform float3 ConvergeY = float3(0.0f, 0.0f, 0.0f); uniform float3 RadialConvergeX = float3(0.0f, 0.0f, 0.0f); uniform float3 RadialConvergeY = float3(0.0f, 0.0f, 0.0f); -uniform float Prescale; - VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; - float2 invDims = 1.0f / SourceDims; - float2 Ratios = SourceRect; + float2 HalfSourceRect = SourceRect * 0.5f; + + float2 QuadRatio = + float2(1.0f, SwapXY + ? QuadDims.y / QuadDims.x + : QuadDims.x / QuadDims.y); + + // imaginary texel dimensions independed from quad dimensions, but dependend on quad ratio + float2 FixedTexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio; + 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; // toom + float2 TexCoord = Input.TexCoord; + TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) + + Output.Color = Input.Color; + + Output.TexCoordX = TexCoord.xxx; + Output.TexCoordY = TexCoord.yyy; + + // center coordinates + Output.TexCoordX -= HalfSourceRect.xxx; + Output.TexCoordY -= HalfSourceRect.yyy; - float2 RadialRed = float2(RadialConvergeX.x, RadialConvergeY.x); - float2 RadialGrn = float2(RadialConvergeX.y, RadialConvergeY.y); - float2 RadialBlu = float2(RadialConvergeX.z, RadialConvergeY.z); - float2 ConvergeRed = float2(ConvergeX.x, ConvergeY.x); - float2 ConvergeGrn = float2(ConvergeX.y, ConvergeY.y); - float2 ConvergeBlu = float2(ConvergeX.z, ConvergeY.z); - float2 ScaledRatio = ((TexCoord * SourceRect) - 0.5f); + // radial converge offset to "translate" the most outer pixel as thay would be translated by the linar converge with the same amount + float2 radialConvergeOffset = 2.0f / SourceRect; - Output.CoordX = ((((TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + RadialConvergeX / SourceDims.x) + 0.5f) * Ratios.x + ConvergeX * invDims.x; - Output.CoordY = ((((TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + RadialConvergeY / SourceDims.y) + 0.5f) * Ratios.y + ConvergeY * invDims.y; - Output.TexCoord = TexCoord; + // radial converge + Output.TexCoordX *= 1.0f + RadialConvergeX * FixedTexelDims.xxx * radialConvergeOffset.xxx; + Output.TexCoordY *= 1.0f + RadialConvergeY * FixedTexelDims.yyy * radialConvergeOffset.yyy; + + // un-center coordinates + Output.TexCoordX += HalfSourceRect.xxx; + Output.TexCoordY += HalfSourceRect.yyy; + + // linear converge + Output.TexCoordX += ConvergeX * FixedTexelDims.xxx; + Output.TexCoordY += ConvergeY * FixedTexelDims.yyy; return Output; } @@ -103,19 +120,18 @@ VS_OUTPUT vs_main(VS_INPUT Input) float4 ps_main(PS_INPUT Input) : COLOR { - float Alpha = tex2D(DiffuseSampler, Input.TexCoord).a; - float RedTexel = tex2D(DiffuseSampler, float2(Input.CoordX.x, Input.CoordY.x)).r; - float GrnTexel = tex2D(DiffuseSampler, float2(Input.CoordX.y, Input.CoordY.y)).g; - float BluTexel = tex2D(DiffuseSampler, float2(Input.CoordX.z, Input.CoordY.z)).b; + float r = tex2D(DiffuseSampler, float2(Input.TexCoordX.x, Input.TexCoordY.x)).r; + float g = tex2D(DiffuseSampler, float2(Input.TexCoordX.y, Input.TexCoordY.y)).g; + float b = tex2D(DiffuseSampler, float2(Input.TexCoordX.z, Input.TexCoordY.z)).b; - return float4(RedTexel, GrnTexel, BluTexel, Alpha); + return float4(r, g, b, 1.0f); } //----------------------------------------------------------------------------- -// Deconvergence Effect +// Deconvergence Technique //----------------------------------------------------------------------------- -technique DeconvergeTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx index 77c7ddcd3e1..63d35789393 100644 --- a/hlsl/distortion.fx +++ b/hlsl/distortion.fx @@ -4,6 +4,10 @@ // Distortion Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + texture DiffuseTexture; sampler DiffuseSampler = sampler_state @@ -55,11 +59,6 @@ static const float GelfondSchneider = 2.6651442f; // 2^sqrt(2) (Gelfond-Schneide // Functions //----------------------------------------------------------------------------- -bool xor(bool a, bool b) -{ - return (a || b) && !(a && b); -} - // www.stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader/ float random(float2 seed) { @@ -109,7 +108,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Post-Processing Pixel Shader +// Distortion Pixel Shader //----------------------------------------------------------------------------- uniform float CurvatureAmount = 0.0f; @@ -118,8 +117,6 @@ uniform float SmoothBorderAmount = 0.0f; uniform float VignettingAmount = 0.0f; uniform float ReflectionAmount = 0.0f; -uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation -uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270° float2 GetRatioCorrection() @@ -299,10 +296,10 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Distortion Effect +// Distortion Technique //----------------------------------------------------------------------------- -technique DistortionTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/downsample.fx b/hlsl/downsample.fx index 4a4a8fe3743..122172350f9 100644 --- a/hlsl/downsample.fx +++ b/hlsl/downsample.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- -// Effect File Variables +// Downsample Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture DiffuseTexture; @@ -31,7 +35,7 @@ struct VS_OUTPUT struct VS_INPUT { - float3 Position : POSITION; + float4 Position : POSITION; float4 Color : COLOR0; float2 TexCoord : TEXCOORD0; }; @@ -49,6 +53,7 @@ struct PS_INPUT uniform float2 ScreenDims; uniform float2 TargetDims; +uniform float2 SourceRect; uniform bool PrepareVector; @@ -68,7 +73,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) float2 TexCoord = Input.Position.xy / ScreenDims; TexCoord += PrepareVector - ? 0.5f / TargetDims // half texel offset correction (DX9) + ? 0.5f / TargetDims // half texel offset correction (DX9) - only for vector grpahics : 0.0f; Output.TexCoord01.xy = TexCoord + float2(-0.5f, -0.5f) * TargetTexelDims; @@ -85,28 +90,26 @@ VS_OUTPUT vs_main(VS_INPUT Input) float4 ps_main(PS_INPUT Input) : COLOR { - float4 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy); - float4 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw); - float4 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy); - float4 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw); + float3 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy).rgb; + float3 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw).rgb; + float3 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy).rgb; + float3 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw).rgb; - float4 outTexel = (texel0 + texel1 + texel2 + texel3) / 4.0; + float3 outTexel = (texel0 + texel1 + texel2 + texel3) / 4.0; - return float4(outTexel.rgb, 1.0f); + return float4(outTexel, 1.0f); } //----------------------------------------------------------------------------- -// Downsample Effect +// Downsample Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler>; - VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); } diff --git a/hlsl/focus.fx b/hlsl/focus.fx index af0d9314d32..c5e5262fedd 100644 --- a/hlsl/focus.fx +++ b/hlsl/focus.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- -// Effect File Variables +// Defocus Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture Diffuse; @@ -42,16 +46,7 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Functions -//----------------------------------------------------------------------------- - -bool xor(bool a, bool b) -{ - return (a || b) && !(a && b); -} - -//----------------------------------------------------------------------------- -// Simple Vertex Shader +// Defocus Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; @@ -80,7 +75,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Simple Pixel Shader +// Defocus Pixel Shader //----------------------------------------------------------------------------- float2 Coord1Offset = float2( 0.75f, 0.50f); @@ -94,18 +89,19 @@ float2 Coord8Offset = float2( 1.00f, -0.25f); uniform float2 Defocus = float2(0.0f, 0.0f); -uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation -uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation +uniform bool SwapXY = false; float4 ps_main(PS_INPUT Input) : COLOR { float2 QuadRatio = - float2(1.0f, xor(OrientationSwapXY, RotationSwapXY) + float2(1.0f, SwapXY ? QuadDims.y / QuadDims.x : QuadDims.x / QuadDims.y); // imaginary texel dimensions independed from quad dimensions, but dependend on quad ratio - float2 DefocusTexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio * Defocus; + float2 TexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio; + + float2 DefocusTexelDims = Defocus * TexelDims; float4 d = tex2D(DiffuseSampler, Input.TexCoord); float3 d1 = tex2D(DiffuseSampler, Input.TexCoord + Coord1Offset * DefocusTexelDims).rgb; @@ -124,17 +120,15 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Simple Effect +// Defocus Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler>; - VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); } diff --git a/hlsl/ntsc.fx b/hlsl/ntsc.fx new file mode 100644 index 00000000000..107be16af16 --- /dev/null +++ b/hlsl/ntsc.fx @@ -0,0 +1,252 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz,ImJezze +//----------------------------------------------------------------------------- +// NTSC Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + +texture Diffuse; + +sampler DiffuseSampler = sampler_state +{ + Texture = <Diffuse>; + MipFilter = LINEAR; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; + AddressW = CLAMP; +}; + +//----------------------------------------------------------------------------- +// Vertex Definitions +//----------------------------------------------------------------------------- + +struct VS_OUTPUT +{ + float4 Position : POSITION; + float4 TexCoord : TEXCOORD0; +}; + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; +}; + +struct PS_INPUT +{ + float2 TexCoord : TEXCOORD0; +}; + +//----------------------------------------------------------------------------- +// YIQ Decode Vertex Shader +//----------------------------------------------------------------------------- + +uniform float2 ScreenDims; +uniform float2 SourceDims; +uniform float2 SourceRect; + +VS_OUTPUT vs_main(VS_INPUT Input) +{ + VS_OUTPUT Output = (VS_OUTPUT)0; + + Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position.xy /= ScreenDims; + 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; +} + +//----------------------------------------------------------------------------- +// NTSC Pixel Shader +//----------------------------------------------------------------------------- + +uniform float AValue = 0.5f; +uniform float BValue = 0.5f; +uniform float CCValue = 3.5795454f; +uniform float OValue = 0.0f; +uniform float PValue = 1.0f; +uniform float ScanTime = 52.6f; + +uniform float NotchHalfWidth = 1.0f; +uniform float YFreqResponse = 6.0f; +uniform float IFreqResponse = 1.2f; +uniform float QFreqResponse = 0.6f; + +uniform float SignalOffset = 0.0f; + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +static const float PI = 3.1415927f; +static const float PI2 = PI * 2.0f; + +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 float3 RDot = float3(1.0f, 0.956f, 0.621f); +static const float3 GDot = float3(1.0f, -0.272f, -0.647f); +static const float3 BDot = float3(1.0f, -1.106f, 1.703f); + +static const float4 OffsetX = float4(0.0f, 0.25f, 0.50f, 0.75f); +static const float4 NotchOffset = float4(0.0f, 1.0f, 2.0f, 3.0f); + +static const int SampleCount = 64; +static const int HalfSampleCount = SampleCount / 2; + +float4 GetCompositeYIQ(float2 TexCoord) +{ + float2 SourceTexelDims = 1.0f / SourceDims; + float2 SourceRes = SourceDims * SourceRect; + + float2 PValueSourceTexel = float2(PValue, 0.0f) * SourceTexelDims; + + float2 C0 = TexCoord + PValueSourceTexel * OffsetX.x; + float2 C1 = TexCoord + PValueSourceTexel * OffsetX.y; + float2 C2 = TexCoord + PValueSourceTexel * OffsetX.z; + float2 C3 = TexCoord + PValueSourceTexel * 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 HPosition = Cx / SourceRect.x; + float4 VPosition = Cy / SourceRect.y; + + 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 W = PI2 * CCValue * ScanTime; + float WoPI = W / PI; + + float HOffset = (BValue + SignalOffset) / WoPI; + float VScale = (AValue * SourceRes.y) / WoPI; + + float4 T = HPosition + HOffset + VPosition * VScale; + float4 TW = T * W; + + float4 CompositeYIQ = Y + I * cos(TW) + Q * sin(TW); + + return CompositeYIQ; +} + +float4 ps_main(PS_INPUT Input) : COLOR +{ + float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); + + float2 SourceTexelDims = 1.0f / SourceDims; + float2 SourceRes = SourceDims * SourceRect; + + float TimePerSample = ScanTime / (SourceRes.x * 4.0f); + + 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; + 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 / SampleCount; + + float W = PI2 * CCValue * ScanTime; + float WoPI = W / PI; + + float HOffset = (BValue + SignalOffset) / WoPI; + float VScale = (AValue * SourceRes.y) / WoPI; + + float4 YAccum = 0.0f; + float4 IAccum = 0.0f; + float4 QAccum = 0.0f; + + float4 Cy = Input.TexCoord.y; + float4 VPosition = Cy / SourceRect.y; + + for (float i = 0; i < SampleCount; i += 4.0f) + { + float n = i - HalfSampleCount; + + float4 n4 = n + NotchOffset; + + float4 Cx = Input.TexCoord.x + SourceTexelDims.x * (n4 * 0.25f); + float4 HPosition = Cx / SourceRect.x; + + float4 C = GetCompositeYIQ(float2(Cx.r, Cy.r)); + + float4 T = HPosition + HOffset + VPosition * VScale; + float4 WT = W * T + 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 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 FilterY = SincKernel * IdealY; + float4 FilterI = SincKernel * IdealI; + float4 FilterQ = SincKernel * IdealQ; + + YAccum = YAccum + C * FilterY; + IAccum = IAccum + C * cos(WT) * FilterI; + QAccum = QAccum + C * sin(WT) * FilterQ; + } + + float3 YIQ = float3( + (YAccum.r + YAccum.g + YAccum.b + YAccum.a), + (IAccum.r + IAccum.g + IAccum.b + IAccum.a) * 2.0f, + (QAccum.r + QAccum.g + QAccum.b + QAccum.a) * 2.0f); + + float3 RGB = float3( + dot(YIQ, RDot), + dot(YIQ, GDot), + dot(YIQ, BDot)); + + return float4(RGB, BaseTexel.a); +} + +//----------------------------------------------------------------------------- +// NTSC Technique +//----------------------------------------------------------------------------- + +technique DefaultTechnique +{ + pass Pass0 + { + Lighting = FALSE; + + VertexShader = compile vs_3_0 vs_main(); + PixelShader = compile ps_3_0 ps_main(); + } +} diff --git a/hlsl/phosphor.fx b/hlsl/phosphor.fx index 13c7700e2e8..7d665b44749 100644 --- a/hlsl/phosphor.fx +++ b/hlsl/phosphor.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz //----------------------------------------------------------------------------- -// Effect File Variables +// Phosphor Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture Diffuse; @@ -57,7 +61,7 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Simple Vertex Shader +// Phosphor Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; @@ -86,7 +90,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Simple Pixel Shader +// Phosphor Pixel Shader //----------------------------------------------------------------------------- uniform float3 Phosphor = float3(0.0f, 0.0f, 0.0f); @@ -106,18 +110,15 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Simple Effect +// Phosphor Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler>; - Sampler[1] = <PreviousSampler>; - VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); } diff --git a/hlsl/pincushion.fx b/hlsl/pincushion.fx deleted file mode 100644 index 7968363c1d6..00000000000 --- a/hlsl/pincushion.fx +++ /dev/null @@ -1,126 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -//----------------------------------------------------------------------------- -// Pincushion Post-Processing Effect -//----------------------------------------------------------------------------- - -texture Diffuse; - -sampler DiffuseSampler = sampler_state -{ - Texture = <Diffuse>; - MipFilter = LINEAR; - MinFilter = LINEAR; - MagFilter = LINEAR; - AddressU = CLAMP; - AddressV = CLAMP; - AddressW = CLAMP; -}; - -//----------------------------------------------------------------------------- -// Vertex Definitions -//----------------------------------------------------------------------------- - -struct VS_OUTPUT -{ - float4 Position : POSITION; - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; - float2 RedCoord : TEXCOORD2; - float2 GreenCoord : TEXCOORD3; - float2 BlueCoord : TEXCOORD4; -}; - -struct VS_INPUT -{ - float3 Position : POSITION; - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; - float2 Unused : TEXCOORD1; -}; - -struct PS_INPUT -{ - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; - float2 RedCoord : TEXCOORD2; - float2 GreenCoord : TEXCOORD3; - float2 BlueCoord : TEXCOORD4; -}; - -//----------------------------------------------------------------------------- -// Post-Processing Vertex Shader -//----------------------------------------------------------------------------- - -uniform float TargetWidth; -uniform float TargetHeight; - -uniform float RawWidth; -uniform float RawHeight; - -VS_OUTPUT vs_main(VS_INPUT Input) -{ - VS_OUTPUT Output = (VS_OUTPUT)0; - - float2 invDims = float2(1.0f / RawWidth, 1.0f / RawHeight); - 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); - Output.Color = Input.Color; - Output.TexCoord = Input.TexCoord; - - Output.TexCoord.x -= 0.25f; - Output.TexCoord.y -= 0.25f; - Output.TexCoord.x -= 0.5f; - Output.TexCoord.y -= 0.5f; - Output.TexCoord.x /= 18.0f * (TargetWidth / RawWidth); - Output.TexCoord.y /= 18.0f * (TargetHeight / RawHeight); - Output.TexCoord.x += 0.5f; - Output.TexCoord.y += 0.5f; - - return Output; -} - -//----------------------------------------------------------------------------- -// Post-Processing Pixel Shader -//----------------------------------------------------------------------------- - -uniform float PI = 3.14159265f; - -uniform float PincushionAmountX = 0.1f; -uniform float PincushionAmountY = 0.1f; - -uniform float2 ActiveArea; - -float4 ps_main(PS_INPUT Input) : COLOR -{ - // -- Screen Pincushion Calculation -- - float2 UnitCoord = Input.TexCoord * ActiveArea * 2.0f - 1.0f; - - float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(ActiveArea), 2.0f); - float2 PincushionCurve = UnitCoord * PincushionAmountX * PincushionR2; - float2 BaseCoord = Input.TexCoord + PincushionCurve; - - return tex2D(DiffuseSampler, BaseCoord); -} - -//----------------------------------------------------------------------------- -// Post-Processing Effect -//----------------------------------------------------------------------------- - -technique TestTechnique -{ - pass Pass0 - { - Lighting = FALSE; - - Sampler[0] = <DiffuseSampler>; - - VertexShader = compile vs_2_0 vs_main(); - PixelShader = compile ps_2_0 ps_main(); - } -} diff --git a/hlsl/post.fx b/hlsl/post.fx index 39548bcf73a..deec349e2fc 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -4,6 +4,10 @@ // Scanline & Shadowmask Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + texture DiffuseTexture; sampler DiffuseSampler = sampler_state @@ -61,15 +65,7 @@ struct PS_INPUT //----------------------------------------------------------------------------- static const float PI = 3.1415927f; - -//----------------------------------------------------------------------------- -// Functions -//----------------------------------------------------------------------------- - -bool xor(bool a, bool b) -{ - return (a || b) && !(a && b); -} +static const float PHI = 1.618034f; //----------------------------------------------------------------------------- // Scanline & Shadowmask Vertex Shader @@ -83,8 +79,7 @@ uniform float2 TargetDims; // size of the target surface uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) uniform float2 ShadowUVOffset = float2(0.0f, 0.0f); -uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation -uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation +uniform bool SwapXY = false; uniform bool PrepareBloom = false; // disables some effects for rendering bloom textures uniform bool PrepareVector = false; @@ -94,7 +89,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) VS_OUTPUT Output = (VS_OUTPUT)0; float2 shadowUVOffset = ShadowUVOffset; - shadowUVOffset = xor(OrientationSwapXY, RotationSwapXY) + shadowUVOffset = SwapXY ? shadowUVOffset.yx : shadowUVOffset.xy; @@ -121,9 +116,14 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Post-Processing Pixel Shader +// Scanline & Shadowmask Pixel Shader //----------------------------------------------------------------------------- +uniform float HumBarHertzRate = 60.0f / 59.94f - 1.0f; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) +uniform float HumBarAlpha = 0.0f; + +uniform float TimeMilliseconds = 0.0f; + uniform float2 ScreenScale = float2(1.0f, 1.0f); uniform float2 ScreenOffset = float2(0.0f, 0.0f); @@ -165,10 +165,9 @@ float4 ps_main(PS_INPUT Input) : COLOR { float2 ScreenTexelDims = 1.0f / ScreenDims; float2 SourceTexelDims = 1.0f / SourceDims; + float2 SourceRes = SourceDims * SourceRect; - float2 HalfSourceRect = PrepareVector - ? float2(0.5f, 0.5f) - : SourceRect * 0.5f; + float2 HalfSourceRect = SourceRect * 0.5f; float2 ScreenCoord = Input.ScreenCoord / ScreenDims; float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect); @@ -183,37 +182,37 @@ float4 ps_main(PS_INPUT Input) : COLOR } // Mask Simulation (may not affect bloom) - if (!PrepareBloom) + if (!PrepareBloom && ShadowAlpha > 0.0f) { float2 shadowDims = ShadowDims; - shadowDims = xor(OrientationSwapXY, RotationSwapXY) + shadowDims = SwapXY ? shadowDims.yx : shadowDims.xy; float2 shadowUV = ShadowUV; - // shadowUV = xor(OrientationSwapXY, RotationSwapXY) + // shadowUV = SwapXY // ? shadowUV.yx // : shadowUV.xy; float2 screenCoord = ShadowTileMode == 0 ? ScreenCoord : BaseCoord; - screenCoord = xor(OrientationSwapXY, RotationSwapXY) + screenCoord = SwapXY ? screenCoord.yx : screenCoord.xy; float2 shadowCount = ShadowCount; - shadowCount = xor(OrientationSwapXY, RotationSwapXY) + shadowCount = SwapXY ? shadowCount.yx : shadowCount.xy; float2 shadowTile = ((ShadowTileMode == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount); - shadowTile = xor(OrientationSwapXY, RotationSwapXY) + shadowTile = SwapXY ? shadowTile.yx : shadowTile.xy; float2 ShadowFrac = frac(screenCoord / shadowTile); float2 ShadowCoord = (ShadowFrac * shadowUV); ShadowCoord += 0.5f / shadowDims; // half texel offset - // ShadowCoord = xor(OrientationSwapXY, RotationSwapXY) + // ShadowCoord = SwapXY // ? ShadowCoord.yx // : ShadowCoord.xy; @@ -243,14 +242,23 @@ float4 ps_main(PS_INPUT Input) : COLOR if (!PrepareBloom) { // Scanline Simulation (may not affect vector screen) - if (!PrepareVector) + if (!PrepareVector && ScanlineAlpha > 0.0f) { - float InnerSine = BaseCoord.y * ScanlineScale * SourceDims.y; - float ScanJitter = ScanlineOffset * SourceDims.y; - float ScanBrightMod = sin(InnerSine * PI + ScanJitter); - float3 ScanColor = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f + ScanlineBrightOffset) * 0.5f, ScanlineAlpha); + float ScanCoord = BaseCoord.y * SourceDims.y * ScanlineScale * PI; + float ScanCoordJitter = ScanlineOffset * PHI; + float ScanSine = sin(ScanCoord + ScanCoordJitter); + float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineHeight); + float ScanBrightness = ScanSineScaled * ScanlineBrightScale + 1.0f + ScanlineBrightOffset; + + BaseColor.rgb *= lerp(1.0f, ScanBrightness * 0.5f, ScanlineAlpha); + } - BaseColor.rgb *= ScanColor; + // Hum Bar Simulation (may not affect vector screen) + if (!PrepareVector && HumBarAlpha > 0.0f) + { + float HumTimeStep = frac(TimeMilliseconds * HumBarHertzRate); + float HumBrightness = 1.0 - frac(BaseCoord.y / SourceRect.y + HumTimeStep) * HumBarAlpha; + BaseColor.rgb *= HumBrightness; } } @@ -264,17 +272,15 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Scanline & Shadowmask Effect +// Scanline & Shadowmask Technique //----------------------------------------------------------------------------- -technique ScanMaskTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler>; - VertexShader = compile vs_3_0 vs_main(); PixelShader = compile ps_3_0 ps_main(); } diff --git a/hlsl/prescale.fx b/hlsl/prescale.fx index 16df349c583..846c02577ce 100644 --- a/hlsl/prescale.fx +++ b/hlsl/prescale.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz //----------------------------------------------------------------------------- -// Passthrough Effect +// Prescale Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture Diffuse; @@ -41,10 +45,11 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Passthrough Vertex Shader +// Prescale Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; +uniform float2 TargetDims; VS_OUTPUT vs_main(VS_INPUT Input) { @@ -52,17 +57,18 @@ 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.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 + 0.5f / ScreenDims; + Output.TexCoord = Input.TexCoord; + Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) return Output; } //----------------------------------------------------------------------------- -// Passthrough Pixel Shader +// Prescale Pixel Shader //----------------------------------------------------------------------------- float4 ps_main(PS_INPUT Input) : COLOR @@ -71,10 +77,10 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Passthrough Effect +// Prescale Technique //----------------------------------------------------------------------------- -technique DeconvergeTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/primary.fx b/hlsl/primary.fx index 130c1cd4706..f0a1c1da0e7 100644 --- a/hlsl/primary.fx +++ b/hlsl/primary.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz //----------------------------------------------------------------------------- -// Effect File Variables +// Primary Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions //----------------------------------------------------------------------------- texture Diffuse; @@ -42,7 +46,7 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Simple Vertex Shader +// Primary Vertex Shader //----------------------------------------------------------------------------- static const float Epsilon = 1.0e-7f; @@ -79,7 +83,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Simple Pixel Shader +// Primary Pixel Shader //----------------------------------------------------------------------------- float4 ps_main(PS_INPUT Input) : COLOR @@ -91,17 +95,15 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Simple Effect +// Primary Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { Lighting = FALSE; - Sampler[0] = <DiffuseSampler>; - VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); } diff --git a/hlsl/vector.fx b/hlsl/vector.fx index 19267453f30..1e94042ad5e 100644 --- a/hlsl/vector.fx +++ b/hlsl/vector.fx @@ -1,7 +1,7 @@ // license:BSD-3-Clause // copyright-holders:Ryan Holtz //----------------------------------------------------------------------------- -// Effect File Variables +// Vector Effect //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -32,7 +32,7 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Simple Vertex Shader +// Vector Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; @@ -59,7 +59,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) } //----------------------------------------------------------------------------- -// Simple Pixel Shader +// Vector Pixel Shader //----------------------------------------------------------------------------- // TimeParams.x: Frame time of the vector @@ -80,10 +80,10 @@ float4 ps_main(PS_INPUT Input) : COLOR } //----------------------------------------------------------------------------- -// Simple Effect +// Vector Technique //----------------------------------------------------------------------------- -technique TestTechnique +technique DefaultTechnique { pass Pass0 { diff --git a/hlsl/yiq_decode.fx b/hlsl/yiq_decode.fx deleted file mode 100644 index c7526fbe870..00000000000 --- a/hlsl/yiq_decode.fx +++ /dev/null @@ -1,187 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -//----------------------------------------------------------------------------- -// YIQ Decode Effect -//----------------------------------------------------------------------------- - -texture Composite; - -sampler CompositeSampler = sampler_state -{ - Texture = <Composite>; - MipFilter = POINT; - MinFilter = POINT; - MagFilter = POINT; - AddressU = CLAMP; - AddressV = CLAMP; - AddressW = CLAMP; -}; - -texture Diffuse; - -sampler DiffuseSampler = sampler_state -{ - Texture = <Diffuse>; - MipFilter = LINEAR; - MinFilter = LINEAR; - MagFilter = LINEAR; - AddressU = CLAMP; - AddressV = CLAMP; - AddressW = CLAMP; -}; - -//----------------------------------------------------------------------------- -// Vertex Definitions -//----------------------------------------------------------------------------- - -struct VS_OUTPUT -{ - float4 Position : POSITION; - float4 Coord0 : TEXCOORD0; -}; - -struct VS_INPUT -{ - float4 Position : POSITION; - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; - float2 Unused : TEXCOORD1; -}; - -struct PS_INPUT -{ - float4 Coord0 : TEXCOORD0; -}; - -//----------------------------------------------------------------------------- -// YIQ Decode Vertex Shader -//----------------------------------------------------------------------------- - -uniform float2 ScreenDims; -uniform float2 SourceDims; -uniform float2 SourceRect; - -VS_OUTPUT vs_main(VS_INPUT Input) -{ - VS_OUTPUT Output = (VS_OUTPUT)0; - - 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); - - return Output; -} - -//----------------------------------------------------------------------------- -// 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 OValue = 0.0f; -uniform float ScanTime = 52.6f; - -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; - -float4 ps_main(PS_INPUT Input) : COLOR -{ - float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / 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 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 * 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 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; - 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 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 FilterY = SincKernel * IdealY; - float4 FilterI = SincKernel * IdealI; - float4 FilterQ = SincKernel * IdealQ; - - YAccum = YAccum + C * FilterY; - IAccum = IAccum + C * cos(WT) * FilterI; - QAccum = QAccum + C * sin(WT) * FilterQ; - } - - 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; - - 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); -} - -//----------------------------------------------------------------------------- -// YIQ Decode Technique -//----------------------------------------------------------------------------- - -technique DecodeTechnique -{ - pass Pass0 - { - Lighting = FALSE; - - VertexShader = compile vs_3_0 vs_main(); - PixelShader = compile ps_3_0 ps_main(); - } -} diff --git a/hlsl/yiq_encode.fx b/hlsl/yiq_encode.fx deleted file mode 100644 index e35062f0722..00000000000 --- a/hlsl/yiq_encode.fx +++ /dev/null @@ -1,130 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -//----------------------------------------------------------------------------- -// YIQ Encode Effect -//----------------------------------------------------------------------------- - -texture Diffuse; - -sampler DiffuseSampler = sampler_state -{ - Texture = <Diffuse>; - MipFilter = LINEAR; - MinFilter = LINEAR; - MagFilter = LINEAR; - AddressU = CLAMP; - AddressV = CLAMP; - AddressW = CLAMP; -}; - -//----------------------------------------------------------------------------- -// Vertex Definitions -//----------------------------------------------------------------------------- - -struct VS_OUTPUT -{ - float4 Position : POSITION; - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; -}; - -struct VS_INPUT -{ - float4 Position : POSITION; - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; - float2 Unused : TEXCOORD1; -}; - -struct PS_INPUT -{ - float4 Color : COLOR0; - float2 TexCoord : TEXCOORD0; -}; - -//----------------------------------------------------------------------------- -// YIQ Encode Vertex Shader -//----------------------------------------------------------------------------- - -uniform float2 ScreenDims; - -VS_OUTPUT vs_main(VS_INPUT Input) -{ - VS_OUTPUT Output = (VS_OUTPUT)0; - - 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.TexCoord = Input.TexCoord; - - return Output; -} - -//----------------------------------------------------------------------------- -// YIQ Encode Pixel Shader -//----------------------------------------------------------------------------- - -uniform float AValue = 0.0f; -uniform float BValue = 0.0f; -uniform float CCValue = 3.04183f; -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 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; - - 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); - - 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)); - - float4 W = PI2 * CCValue * ScanTime; - 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; - - return C; -} - -//----------------------------------------------------------------------------- -// YIQ Encode Technique -//----------------------------------------------------------------------------- - -technique EncodeTechnique -{ - pass Pass0 - { - Lighting = FALSE; - - VertexShader = compile vs_3_0 vs_main(); - PixelShader = compile ps_3_0 ps_main(); - } -} diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 84c30717e77..62e1a29fa42 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -76,7 +76,7 @@ shaders::shaders() : vecbuf_type(), vecbuf_index(0), vecbuf_count(0), avi_output_file(NULL), avi_frame(0), avi_copy_surface(NULL), avi_copy_texture(NULL), avi_final_target(NULL), avi_final_texture(NULL), black_surface(NULL), black_texture(NULL), render_snap(false), snap_rendered(false), snap_copy_target(NULL), snap_copy_texture(NULL), snap_target(NULL), snap_texture(NULL), snap_width(0), snap_height(0), lines_pending(false), backbuffer(NULL), curr_effect(NULL), default_effect(NULL), prescale_effect(NULL), post_effect(NULL), distortion_effect(NULL), - focus_effect(NULL), phosphor_effect(NULL), deconverge_effect(NULL), color_effect(NULL), yiq_encode_effect(NULL), yiq_decode_effect(NULL), bloom_effect(NULL), + focus_effect(NULL), phosphor_effect(NULL), deconverge_effect(NULL), color_effect(NULL), ntsc_effect(NULL), bloom_effect(NULL), downsample_effect(NULL), vector_effect(NULL), fsfx_vertices(NULL), curr_texture(NULL), curr_render_target(NULL), curr_poly(NULL) { master_enable = false; @@ -632,7 +632,7 @@ void shaders::set_texture(texture_info *texture) default_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); if (options->yiq_enable) { - yiq_encode_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); + ntsc_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); } else { @@ -706,7 +706,8 @@ void shaders::init(base *d3dintf, running_machine *machine, d3d::renderer *rende options->scanline_height = winoptions.screen_scanline_height(); options->scanline_bright_scale = winoptions.screen_scanline_bright_scale(); options->scanline_bright_offset = winoptions.screen_scanline_bright_offset(); - options->scanline_offset = winoptions.screen_scanline_offset(); + options->scanline_jitter = winoptions.screen_scanline_jitter(); + options->hum_bar_alpha = winoptions.screen_hum_bar_alpha(); get_vector(winoptions.screen_defocus(), 2, options->defocus, TRUE); get_vector(winoptions.screen_converge_x(), 3, options->converge_x, TRUE); get_vector(winoptions.screen_converge_y(), 3, options->converge_y, TRUE); @@ -722,6 +723,7 @@ void shaders::init(base *d3dintf, running_machine *machine, d3d::renderer *rende get_vector(winoptions.screen_phosphor(), 3, options->phosphor, TRUE); options->saturation = winoptions.screen_saturation(); options->yiq_enable = winoptions.screen_yiq_enable(); + options->yiq_jitter = winoptions.screen_yiq_jitter(); options->yiq_cc = winoptions.screen_yiq_cc(); options->yiq_a = winoptions.screen_yiq_a(); options->yiq_b = winoptions.screen_yiq_b(); @@ -917,8 +919,7 @@ int shaders::create_resources(bool reset) focus_effect = new effect(this, d3d->get_device(), "focus.fx", fx_dir); deconverge_effect = new effect(this, d3d->get_device(), "deconverge.fx", fx_dir); color_effect = new effect(this, d3d->get_device(), "color.fx", fx_dir); - yiq_encode_effect = new effect(this, d3d->get_device(), "yiq_encode.fx", fx_dir); - yiq_decode_effect = new effect(this, d3d->get_device(), "yiq_decode.fx", fx_dir); + ntsc_effect = new effect(this, d3d->get_device(), "ntsc.fx", fx_dir); bloom_effect = new effect(this, d3d->get_device(), "bloom.fx", fx_dir); downsample_effect = new effect(this, d3d->get_device(), "downsample.fx", fx_dir); vector_effect = new effect(this, d3d->get_device(), "vector.fx", fx_dir); @@ -931,8 +932,7 @@ int shaders::create_resources(bool reset) !focus_effect->is_valid() || !deconverge_effect->is_valid() || !color_effect->is_valid() || - !yiq_encode_effect->is_valid() || - !yiq_decode_effect->is_valid() || + !ntsc_effect->is_valid() || !bloom_effect->is_valid() || !downsample_effect->is_valid() || !vector_effect->is_valid()) @@ -940,35 +940,42 @@ int shaders::create_resources(bool reset) return 1; } - yiq_encode_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - yiq_encode_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); - yiq_encode_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); - 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_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); - yiq_encode_effect->add_uniform("IFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_IFREQ); - yiq_encode_effect->add_uniform("QFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_QFREQ); - yiq_encode_effect->add_uniform("ScanTime", uniform::UT_FLOAT, uniform::CU_NTSC_HTIME); - - yiq_decode_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - yiq_decode_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); - yiq_decode_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); - yiq_decode_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ); - yiq_decode_effect->add_uniform("AValue", uniform::UT_FLOAT, uniform::CU_NTSC_A); - yiq_decode_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_decode_effect->add_uniform("PValue", uniform::UT_FLOAT, uniform::CU_NTSC_P); - yiq_decode_effect->add_uniform("NotchHalfWidth", uniform::UT_FLOAT, uniform::CU_NTSC_NOTCH); - yiq_decode_effect->add_uniform("YFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_YFREQ); - yiq_decode_effect->add_uniform("IFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_IFREQ); - yiq_decode_effect->add_uniform("QFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_QFREQ); - yiq_decode_effect->add_uniform("ScanTime", uniform::UT_FLOAT, uniform::CU_NTSC_HTIME); - - color_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - color_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); + effect *effects[13] = { + default_effect, + post_effect, + distortion_effect, + prescale_effect, + phosphor_effect, + focus_effect, + deconverge_effect, + color_effect, + ntsc_effect, + color_effect, + bloom_effect, + downsample_effect, + vector_effect + }; + + for (int i = 0; i < 13; i++) + { + effects[i]->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); + effects[i]->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); + effects[i]->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); + effects[i]->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); + effects[i]->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); + effects[i]->add_uniform("SwapXY", uniform::UT_BOOL, uniform::CU_SWAP_XY); + } + + ntsc_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ); + ntsc_effect->add_uniform("AValue", uniform::UT_FLOAT, uniform::CU_NTSC_A); + ntsc_effect->add_uniform("BValue", uniform::UT_FLOAT, uniform::CU_NTSC_B); + ntsc_effect->add_uniform("OValue", uniform::UT_FLOAT, uniform::CU_NTSC_O); + ntsc_effect->add_uniform("PValue", uniform::UT_FLOAT, uniform::CU_NTSC_P); + ntsc_effect->add_uniform("NotchHalfWidth", uniform::UT_FLOAT, uniform::CU_NTSC_NOTCH); + ntsc_effect->add_uniform("YFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_YFREQ); + ntsc_effect->add_uniform("IFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_IFREQ); + ntsc_effect->add_uniform("QFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_QFREQ); + ntsc_effect->add_uniform("ScanTime", uniform::UT_FLOAT, uniform::CU_NTSC_HTIME); color_effect->add_uniform("RedRatios", uniform::UT_VEC3, uniform::CU_COLOR_RED_RATIOS); color_effect->add_uniform("GrnRatios", uniform::UT_VEC3, uniform::CU_COLOR_GRN_RATIOS); @@ -977,39 +984,15 @@ int shaders::create_resources(bool reset) color_effect->add_uniform("Scale", uniform::UT_VEC3, uniform::CU_COLOR_SCALE); color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION); - prescale_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - - deconverge_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - deconverge_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); - deconverge_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); deconverge_effect->add_uniform("ConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_X); deconverge_effect->add_uniform("ConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_Y); deconverge_effect->add_uniform("RadialConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_RADIAL_X); deconverge_effect->add_uniform("RadialConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_RADIAL_Y); - focus_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - focus_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); - focus_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); - focus_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); focus_effect->add_uniform("Defocus", uniform::UT_VEC2, uniform::CU_FOCUS_SIZE); - focus_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP); - focus_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP); - phosphor_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - phosphor_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE); - downsample_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - - bloom_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - bloom_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); - - post_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); - post_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); - post_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - post_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); - post_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); // backward compatibility - post_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); // backward compatibility post_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE); // backward compatibility post_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER); // backward compatibility @@ -1030,29 +1013,16 @@ int shaders::create_resources(bool reset) post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER); post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR); - post_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP); - post_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP); post_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE); - distortion_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - distortion_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); - distortion_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); - distortion_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); distortion_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE); distortion_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER); distortion_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER); distortion_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION); - distortion_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP); - distortion_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP); distortion_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE); - vector_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - - default_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); - default_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); - initialized = true; return 0; @@ -1072,15 +1042,19 @@ void shaders::begin_draw() curr_effect = default_effect; - default_effect->set_technique("TestTechnique"); - post_effect->set_technique("ScanMaskTechnique"); - distortion_effect->set_technique("DistortionTechnique"); - phosphor_effect->set_technique("TestTechnique"); - focus_effect->set_technique("TestTechnique"); - deconverge_effect->set_technique("DeconvergeTechnique"); - color_effect->set_technique("ColorTechnique"); - yiq_encode_effect->set_technique("EncodeTechnique"); - yiq_decode_effect->set_technique("DecodeTechnique"); + default_effect->set_technique("DefaultTechnique"); + post_effect->set_technique("DefaultTechnique"); + distortion_effect->set_technique("DefaultTechnique"); + prescale_effect->set_technique("DefaultTechnique"); + phosphor_effect->set_technique("DefaultTechnique"); + focus_effect->set_technique("DefaultTechnique"); + deconverge_effect->set_technique("DefaultTechnique"); + color_effect->set_technique("DefaultTechnique"); + ntsc_effect->set_technique("DefaultTechnique"); + color_effect->set_technique("DefaultTechnique"); + bloom_effect->set_technique("DefaultTechnique"); + downsample_effect->set_technique("DefaultTechnique"); + vector_effect->set_technique("DefaultTechnique"); HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer); if (result != D3D_OK) @@ -1258,20 +1232,15 @@ int shaders::ntsc_pass(render_target *rt, int source_index, poly_info *poly, int return next_index; } - // Convert our signal into YIQ - curr_effect = yiq_encode_effect; - curr_effect->update_uniforms(); + float signal_offset = curr_texture->get_cur_frame() == 0 + ? 0.0f + : options->yiq_jitter; // initial "Diffuse" texture is set in shaders::set_texture() - next_index = rt->next_index(next_index); - blit(rt->native_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); - - // Convert our signal from YIQ - curr_effect = yiq_decode_effect; + curr_effect = ntsc_effect; 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("SignalOffset", signal_offset); next_index = rt->next_index(next_index); blit(rt->native_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); @@ -1354,6 +1323,15 @@ int shaders::deconverge_pass(render_target *rt, int source_index, poly_info *pol { int next_index = source_index; + // skip deconverge if no influencing settings + if (options->converge_x[0] == 0.0f && options->converge_x[1] == 0.0f && options->converge_x[2] == 0.0f && + options->converge_y[0] == 0.0f && options->converge_y[1] == 0.0f && options->converge_y[2] == 0.0f && + options->radial_converge_x[0] == 0.0f && options->radial_converge_x[1] == 0.0f && options->radial_converge_x[2] == 0.0f && + options->radial_converge_y[0] == 0.0f && options->radial_converge_y[1] == 0.0f && options->radial_converge_y[2] == 0.0f) + { + return next_index; + } + curr_effect = deconverge_effect; curr_effect->update_uniforms(); curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); @@ -1368,11 +1346,8 @@ int shaders::defocus_pass(render_target *rt, int source_index, poly_info *poly, { int next_index = source_index; - float defocus_x = options->defocus[0]; - float defocus_y = options->defocus[1]; - // skip defocus if no influencing settings - if (defocus_x == 0.0f && defocus_y == 0.0f) + if (options->defocus[0] == 0.0f && options->defocus[1] == 0.0f) { return next_index; } @@ -1391,6 +1366,12 @@ int shaders::phosphor_pass(render_target *rt, cache_target *ct, int source_index { int next_index = source_index; + // skip phosphor if no influencing settings + if (options->phosphor[0] == 0.0f && options->defocus[1] == 0.0f && options->defocus[2] == 0.0f) + { + return next_index; + } + curr_effect = phosphor_effect; curr_effect->update_uniforms(); curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); @@ -1416,8 +1397,6 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int { int next_index = source_index; - texture_info *texture = poly->get_texture(); - bool prepare_vector = machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; @@ -1454,7 +1433,9 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int curr_effect->set_vector("BackColor", 3, back_color); curr_effect->set_vector("ScreenScale", 2, screen_scale); curr_effect->set_vector("ScreenOffset", 2, screen_offset); - curr_effect->set_float("ScanlineOffset", texture->get_cur_frame() == 0 ? 0.0f : options->scanline_offset); + curr_effect->set_float("ScanlineOffset", curr_texture->get_cur_frame() == 0 ? 0.0f : options->scanline_jitter); + curr_effect->set_float("TimeMilliseconds", (float)machine->time().as_double() * 1000.0f); + curr_effect->set_float("HumBarAlpha", options->hum_bar_alpha); curr_effect->set_bool("PrepareBloom", prepare_bloom); curr_effect->set_bool("PrepareVector", prepare_vector); @@ -1468,16 +1449,15 @@ int shaders::downsample_pass(render_target *rt, int source_index, poly_info *pol { int next_index = source_index; - bool prepare_vector = - machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; - float bloom_rescale = options->bloom_scale; - // skip downsample if no influencing settings - if (bloom_rescale == 0.0f) + if (options->bloom_scale == 0.0f) { return next_index; } + bool prepare_vector = + machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + curr_effect = downsample_effect; curr_effect->update_uniforms(); curr_effect->set_bool("PrepareVector", prepare_vector); @@ -1514,46 +1494,52 @@ int shaders::bloom_pass(render_target *rt, int source_index, poly_info *poly, in { int next_index = source_index; - float bloom_rescale = options->bloom_scale; - // skip bloom if no influencing settings - if (bloom_rescale == 0.0f) + if (options->bloom_scale == 0.0f) { return next_index; } - curr_effect = bloom_effect; - curr_effect->update_uniforms(); - - float weight0123[4] = { - options->bloom_level0_weight, + float weight12[2] = { options->bloom_level1_weight, - options->bloom_level2_weight, - options->bloom_level3_weight + options->bloom_level2_weight + }; + float weight34[2] = { + options->bloom_level3_weight, + options->bloom_level4_weight }; - float weight4567[4] = { - options->bloom_level4_weight, + float weight56[2] = { options->bloom_level5_weight, options->bloom_level6_weight, - options->bloom_level7_weight }; - float weight89A[3] = { - options->bloom_level8_weight, + float weight78[2] = { + options->bloom_level7_weight, + options->bloom_level8_weight + }; + float weight9A[2] = { options->bloom_level9_weight, options->bloom_level10_weight }; - curr_effect->set_vector("Level0123Weight", 4, weight0123); - curr_effect->set_vector("Level4567Weight", 4, weight4567); - curr_effect->set_vector("Level89AWeight", 3, weight89A); - curr_effect->set_vector("Level01Size", 4, bloom_dims[0]); - curr_effect->set_vector("Level23Size", 4, bloom_dims[2]); - curr_effect->set_vector("Level45Size", 4, bloom_dims[4]); - curr_effect->set_vector("Level67Size", 4, bloom_dims[6]); - curr_effect->set_vector("Level89Size", 4, bloom_dims[8]); - curr_effect->set_vector("LevelASize", 2, bloom_dims[10]); + + curr_effect = bloom_effect; + curr_effect->update_uniforms(); + + curr_effect->set_float ("Level0Weight", options->bloom_level0_weight); + curr_effect->set_vector("Level12Weight", 2, weight12); + curr_effect->set_vector("Level34Weight", 2, weight34); + curr_effect->set_vector("Level56Weight", 2, weight56); + curr_effect->set_vector("Level78Weight", 2, weight78); + curr_effect->set_vector("Level9AWeight", 2, weight9A); + + curr_effect->set_vector("Level0Size", 2, bloom_dims[0]); + curr_effect->set_vector("Level12Size", 4, bloom_dims[1]); + curr_effect->set_vector("Level34Size", 4, bloom_dims[3]); + curr_effect->set_vector("Level56Size", 4, bloom_dims[5]); + curr_effect->set_vector("Level78Size", 4, bloom_dims[7]); + curr_effect->set_vector("Level9ASize", 4, bloom_dims[9]); curr_effect->set_int("BloomBlendMode", options->bloom_blend_mode); - curr_effect->set_float("BloomScale", bloom_rescale); + curr_effect->set_float("BloomScale", options->bloom_scale); curr_effect->set_vector("BloomOverdrive", 3, options->bloom_overdrive); curr_effect->set_texture("DiffuseA", rt->prescale_texture[next_index]); @@ -1750,7 +1736,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) // render on screen d3d->set_wrap(D3DTADDRESS_MIRROR); next_index = screen_pass(rt, next_index, poly, vertnum); - d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); + d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(curr_texture->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); curr_texture->increment_frame_count(); curr_texture->mask_frame_count(options->yiq_phase_count); @@ -1796,6 +1782,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) int next_index = 0; next_index = vector_buffer_pass(rt, next_index, poly, vertnum); + next_index = deconverge_pass(rt, next_index, poly, vertnum); next_index = defocus_pass(rt, next_index, poly, vertnum); // 1st pass next_index = defocus_pass(rt, next_index, poly, vertnum); // 2nd pass next_index = phosphor_pass(rt, ct, next_index, poly, vertnum); @@ -2150,15 +2137,10 @@ void shaders::delete_resources(bool reset) delete color_effect; color_effect = NULL; } - if (yiq_encode_effect != NULL) - { - delete yiq_encode_effect; - yiq_encode_effect = NULL; - } - if (yiq_decode_effect != NULL) + if (ntsc_effect != NULL) { - delete yiq_decode_effect; - yiq_decode_effect = NULL; + delete ntsc_effect; + ntsc_effect = NULL; } if (backbuffer != NULL) @@ -2414,22 +2396,28 @@ static INT32 slider_scanline_bright_offset(running_machine &machine, void *arg, return slider_set(&(((hlsl_options*)arg)->scanline_bright_offset), 0.05f, "%2.2f", str, newval); } -static INT32 slider_scanline_offset(running_machine &machine, void *arg, std::string *str, INT32 newval) +static INT32 slider_scanline_jitter(running_machine &machine, void *arg, std::string *str, INT32 newval) { ((hlsl_options*)arg)->params_dirty = true; - return slider_set(&(((hlsl_options*)arg)->scanline_offset), 0.05f, "%2.2f", str, newval); + return slider_set(&(((hlsl_options*)arg)->scanline_jitter), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_hum_bar_alpha(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->hum_bar_alpha), 0.01f, "%1.2f", str, newval); } static INT32 slider_defocus_x(running_machine &machine, void *arg, std::string *str, INT32 newval) { ((hlsl_options*)arg)->params_dirty = true; - return slider_set(&(((hlsl_options*)arg)->defocus[0]), 0.5f, "%2.1f", str, newval); + return slider_set(&(((hlsl_options*)arg)->defocus[0]), 0.1f, "%2.1f", str, newval); } static INT32 slider_defocus_y(running_machine &machine, void *arg, std::string *str, INT32 newval) { ((hlsl_options*)arg)->params_dirty = true; - return slider_set(&(((hlsl_options*)arg)->defocus[1]), 0.5f, "%2.1f", str, newval); + return slider_set(&(((hlsl_options*)arg)->defocus[1]), 0.1f, "%2.1f", str, newval); } static INT32 slider_red_converge_x(running_machine &machine, void *arg, std::string *str, INT32 newval) @@ -2772,6 +2760,105 @@ static INT32 slider_bloom_lvl10_scale(running_machine &machine, void *arg, std:: return slider_set(&(((hlsl_options*)arg)->bloom_level10_weight), 0.01f, "%1.2f", str, newval); } + +static INT32 slider_ntsc_enable(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + hlsl_options *options = (hlsl_options*)arg; + if (newval != SLIDER_NOCHANGE) + { + options->yiq_enable = newval; + } + if (str != NULL) + { + strprintf(*str, "%s", options->yiq_enable == 0 ? "Off" : "On"); + } + options->params_dirty = true; + + return options->yiq_enable; +} + +// static INT32 slider_ntsc_phase_count(running_machine &machine, void *arg, std::string *str, INT32 newval) +// { +// hlsl_options *options = (hlsl_options*)arg; +// if (newval != SLIDER_NOCHANGE) +// { +// options->yiq_phase_count = newval; +// } +// if (str != NULL) +// { +// strprintf(*str, "%d", options->yiq_phase_count); +// } +// options->params_dirty = true; + +// return options->yiq_phase_count; +// } + +static INT32 slider_ntsc_jitter(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_jitter), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_ntsc_a_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_a), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_ntsc_b_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_b), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_ntsc_p_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_p), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_ntsc_o_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_o), 0.01f, "%1.2f", str, newval); +} + +static INT32 slider_ntsc_cc_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_cc), 0.0001f, "%1.4f", str, newval); +} + +static INT32 slider_ntsc_n_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_n), 0.01f, "%1.4f", str, newval); +} + +static INT32 slider_ntsc_y_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_y), 0.01f, "%1.4f", str, newval); +} + +static INT32 slider_ntsc_i_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_i), 0.01f, "%1.4f", str, newval); +} + +static INT32 slider_ntsc_q_value(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_q), 0.01f, "%1.4f", str, newval); +} + +static INT32 slider_ntsc_scan_time(running_machine &machine, void *arg, std::string *str, INT32 newval) +{ + ((hlsl_options*)arg)->params_dirty = true; + return slider_set(&(((hlsl_options*)arg)->yiq_scan_time), 0.01f, "%1.2f", str, newval); +} + hlsl_options shaders::last_options = { false }; shaders::slider_desc shaders::s_sliders[] = @@ -2796,21 +2883,22 @@ shaders::slider_desc shaders::s_sliders[] = { "Scanline Indiv. Height", 1, 20, 80, 1, 5, slider_scanline_height }, { "Scanline Brightness", 0, 20, 40, 1, 5, slider_scanline_bright_scale }, { "Scanline Brightness Overdrive", 0, 0, 20, 1, 5, slider_scanline_bright_offset }, - { "Scanline Jitter", 0, 0, 40, 1, 5, slider_scanline_offset }, - { "Defocus X", 0, 0, 20, 1, 7, slider_defocus_x }, - { "Defocus Y", 0, 0, 20, 1, 7, slider_defocus_y }, - { "Red Position Offset X", -1500, 0, 1500, 1, 7, slider_red_converge_x }, - { "Red Position Offset Y", -1500, 0, 1500, 1, 7, slider_red_converge_y }, - { "Green Position Offset X", -1500, 0, 1500, 1, 7, slider_green_converge_x }, - { "Green Position Offset Y", -1500, 0, 1500, 1, 7, slider_green_converge_y }, - { "Blue Position Offset X", -1500, 0, 1500, 1, 7, slider_blue_converge_x }, - { "Blue Position Offset Y", -1500, 0, 1500, 1, 7, slider_blue_converge_y }, - { "Red Convergence X", -1500, 0, 1500, 1, 7, slider_red_radial_converge_x }, - { "Red Convergence Y", -1500, 0, 1500, 1, 7, slider_red_radial_converge_y }, - { "Green Convergence X", -1500, 0, 1500, 1, 7, slider_green_radial_converge_x }, - { "Green Convergence Y", -1500, 0, 1500, 1, 7, slider_green_radial_converge_y }, - { "Blue Convergence X", -1500, 0, 1500, 1, 7, slider_blue_radial_converge_x }, - { "Blue Convergence Y", -1500, 0, 1500, 1, 7, slider_blue_radial_converge_y }, + { "Scanline Jitter", 0, 0, 100, 1, 5, slider_scanline_jitter }, + { "Hum Bar Darkness", 0, 0, 100, 1, 5, slider_hum_bar_alpha }, + { "Defocus X", 0, 0, 100, 1, 7, slider_defocus_x }, + { "Defocus Y", 0, 0, 100, 1, 7, slider_defocus_y }, + { "Red Position Offset X", -100, 0, 100, 1, 7, slider_red_converge_x }, + { "Red Position Offset Y", -100, 0, 100, 1, 7, slider_red_converge_y }, + { "Green Position Offset X", -100, 0, 100, 1, 7, slider_green_converge_x }, + { "Green Position Offset Y", -100, 0, 100, 1, 7, slider_green_converge_y }, + { "Blue Position Offset X", -100, 0, 100, 1, 7, slider_blue_converge_x }, + { "Blue Position Offset Y", -100, 0, 100, 1, 7, slider_blue_converge_y }, + { "Red Convergence X", -100, 0, 100, 1, 7, slider_red_radial_converge_x }, + { "Red Convergence Y", -100, 0, 100, 1, 7, slider_red_radial_converge_y }, + { "Green Convergence X", -100, 0, 100, 1, 7, slider_green_radial_converge_x }, + { "Green Convergence Y", -100, 0, 100, 1, 7, slider_green_radial_converge_y }, + { "Blue Convergence X", -100, 0, 100, 1, 7, slider_blue_radial_converge_x }, + { "Blue Convergence Y", -100, 0, 100, 1, 7, slider_blue_radial_converge_y }, { "Red Output from Red Input", -400, 0, 400, 5, 7, slider_red_from_r }, { "Red Output from Green Input", -400, 0, 400, 5, 7, slider_red_from_g }, { "Red Output from Blue Input", -400, 0, 400, 5, 7, slider_red_from_b }, @@ -2852,6 +2940,19 @@ shaders::slider_desc shaders::s_sliders[] = { "Bloom Level 8 Scale", 0, 0, 100, 1, 7, slider_bloom_lvl8_scale }, { "Bloom Level 9 Scale", 0, 0, 100, 1, 7, slider_bloom_lvl9_scale }, { "Bloom Level 10 Scale", 0, 0, 100, 1, 7, slider_bloom_lvl10_scale }, + { "NTSC processing", 0, 0, 1, 1, 5, slider_ntsc_enable }, + { "Signal Jitter", 0, 0, 100, 1, 5, slider_ntsc_jitter }, + { "A Value", -100, 50, 100, 1, 5, slider_ntsc_a_value }, + { "B Value", -100, 50, 100, 1, 5, slider_ntsc_b_value }, + { "Incoming Pixel Clock Scaling", -300, 100, 300, 1, 5, slider_ntsc_p_value }, + { "Outgoing Color Carrier Phase", -300, 0, 300, 1, 5, slider_ntsc_o_value }, + { "Color Carrier Frequency", 0, 35795, 60000, 5, 5, slider_ntsc_cc_value }, + { "Y Notch", 0, 100, 600, 5, 5, slider_ntsc_n_value }, + { "Y Frequency", 0, 600, 600, 5, 5, slider_ntsc_y_value }, + { "I Frequency", 0, 120, 600, 5, 5, slider_ntsc_i_value }, + { "Q Frequency", 0, 60, 600, 5, 5, slider_ntsc_q_value }, + { "Scanline Duration", 0, 5260, 10000, 1, 5, slider_ntsc_scan_time }, + // { "Phase Count", 1, 2, 3, 1, 5, slider_ntsc_phase_count }, { NULL, 0, 0, 0, 0, 0, NULL }, }; @@ -2956,37 +3057,67 @@ void uniform::update() } case CU_SOURCE_DIMS: { - vec2f sourcedims = shadersys->curr_texture->get_rawdims(); - m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); + if (shadersys->curr_texture != NULL) + { + vec2f sourcedims = shadersys->curr_texture->get_rawdims(); + m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); + } + break; } case CU_SOURCE_RECT: { - vec2f delta = shadersys->curr_texture->get_uvstop() - shadersys->curr_texture->get_uvstart(); - m_shader->set_vector("SourceRect", 2, &delta.c.x); + bool prepare_vector = + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + + if (prepare_vector) + { + float delta[2] = { 1.0f, 1.0f }; + m_shader->set_vector("SourceRect", 2, delta); + break; + } + + if (shadersys->curr_texture != NULL) + { + vec2f delta = shadersys->curr_texture->get_uvstop() - shadersys->curr_texture->get_uvstart(); + m_shader->set_vector("SourceRect", 2, &delta.c.x); + break; + } + break; } case CU_TARGET_DIMS: { - if (shadersys->curr_render_target == NULL) + if (shadersys->curr_render_target != NULL) { - float targetdims[2] = { 0.0f, 0.0f }; - m_shader->set_vector("TargetDims", 2, targetdims); - } - else - { - float targetdims[2] = { static_cast<float>(shadersys->curr_render_target->target_width), static_cast<float>(shadersys->curr_render_target->target_height) }; + float targetdims[2] = { + static_cast<float>(shadersys->curr_render_target->target_width), + static_cast<float>(shadersys->curr_render_target->target_height) }; m_shader->set_vector("TargetDims", 2, targetdims); } break; } case CU_QUAD_DIMS: { - float quaddims[2] = { shadersys->curr_poly->get_prim_width(), shadersys->curr_poly->get_prim_height() }; - m_shader->set_vector("QuadDims", 2, quaddims); + if (shadersys->curr_poly != NULL) + { + float quaddims[2] = { + shadersys->curr_poly->get_prim_width(), + shadersys->curr_poly->get_prim_height() }; + m_shader->set_vector("QuadDims", 2, quaddims); + } break; } + case CU_SWAP_XY: + { + bool orientation_swap_xy = + (d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; + bool rotation_swap_xy = + (d3d->window().target()->orientation() & ROT90) == ROT90 || + (d3d->window().target()->orientation() & ROT270) == ROT270; + m_shader->set_bool("SwapXY", orientation_swap_xy ^ rotation_swap_xy); + } case CU_ORIENTATION_SWAP: { bool orientation_swap_xy = @@ -3162,28 +3293,6 @@ void uniform::update() case CU_POST_FLOOR: m_shader->set_vector("Floor", 3, options->floor); break; - - case CU_BLOOM_RESCALE: - m_shader->set_float("BloomRescale", options->bloom_scale); - break; - case CU_BLOOM_LVL0123_WEIGHTS: - { - float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, options->bloom_level2_weight, options->bloom_level3_weight }; - m_shader->set_vector("Level0123Weight", 4, weight0123); - break; - } - case CU_BLOOM_LVL4567_WEIGHTS: - { - float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, options->bloom_level6_weight, options->bloom_level7_weight }; - m_shader->set_vector("Level4567Weight", 4, weight4567); - break; - } - case CU_BLOOM_LVL89A_WEIGHTS: - { - float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight, options->bloom_level10_weight }; - m_shader->set_vector("Level89AWeight", 3, weight89A); - break; - } } } diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index b8bb5ac6f89..d949c1417c8 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -50,6 +50,7 @@ public: CU_TARGET_DIMS, CU_QUAD_DIMS, + CU_SWAP_XY, CU_ORIENTATION_SWAP, CU_ROTATION_SWAP, CU_ROTATION_TYPE, @@ -101,11 +102,6 @@ public: CU_POST_POWER, CU_POST_FLOOR, - CU_BLOOM_RESCALE, - CU_BLOOM_LVL0123_WEIGHTS, - CU_BLOOM_LVL4567_WEIGHTS, - CU_BLOOM_LVL89A_WEIGHTS, - CU_COUNT }; @@ -214,7 +210,8 @@ struct hlsl_options float scanline_height; float scanline_bright_scale; float scanline_bright_offset; - float scanline_offset; + float scanline_jitter; + float hum_bar_alpha; float defocus[2]; float converge_x[3]; float converge_y[3]; @@ -232,6 +229,7 @@ struct hlsl_options // NTSC bool yiq_enable; + float yiq_jitter; float yiq_cc; float yiq_a; float yiq_b; @@ -431,8 +429,7 @@ private: effect * phosphor_effect; // pointer to the phosphor-effect object effect * deconverge_effect; // pointer to the deconvergence-effect object effect * color_effect; // pointer to the color-effect object - effect * yiq_encode_effect; // pointer to the YIQ encoder effect object - effect * yiq_decode_effect; // pointer to the YIQ decoder effect object + effect * ntsc_effect; // pointer to the NTSC effect object effect * bloom_effect; // pointer to the bloom composite effect effect * downsample_effect; // pointer to the bloom downsample effect effect * vector_effect; // pointer to the vector-effect object diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index d72b2df7f38..b8730696a54 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -2734,20 +2734,6 @@ void texture_info::prescale() cache_target::~cache_target() { - for (int index = 0; index < 11; index++) - { - if (bloom_texture[index] != NULL) - { - (*d3dintf->texture.release)(bloom_texture[index]); - bloom_texture[index] = NULL; - } - if (bloom_target[index] != NULL) - { - (*d3dintf->surface.release)(bloom_target[index]); - bloom_target[index] = NULL; - } - } - if (last_texture != NULL) { (*d3dintf->texture.release)(last_texture); @@ -2767,25 +2753,6 @@ cache_target::~cache_target() bool cache_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y) { - int bloom_index = 0; - int bloom_size = (width < height) ? width : height; - int bloom_width = width; - int bloom_height = height; - for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) - { - bloom_width >>= 1; - bloom_height >>= 1; - - HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]); - if (result != D3D_OK) - { - return false; - } - (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]); - - bloom_index++; - } - HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture); if (result != D3D_OK) { diff --git a/src/osd/modules/render/drawd3d.h b/src/osd/modules/render/drawd3d.h index ab5385914b5..906bd7711b8 100644 --- a/src/osd/modules/render/drawd3d.h +++ b/src/osd/modules/render/drawd3d.h @@ -53,9 +53,6 @@ public: cache_target *next; cache_target *prev; - - surface *bloom_target[11]; - texture *bloom_texture[11]; }; /* render_target is the information about a Direct3D render target chain */ diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index d1d944a2146..2a14281f7fc 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -303,12 +303,13 @@ const options_entry windows_options::s_option_entries[] = { WINOPTION_REFLECTION";fs_ref(0.0-1.0)", "0.0", OPTION_FLOAT, "screen reflection amount" }, { WINOPTION_VIGNETTING";fs_vig(0.0-1.0)", "0.0", OPTION_FLOAT, "image vignetting amount" }, /* Beam-related values below this line*/ - { WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)", "1.0", OPTION_FLOAT, "overall alpha scaling value for scanlines" }, + { WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)", "0.0", OPTION_FLOAT, "overall alpha scaling value for scanlines" }, { WINOPTION_SCANLINE_SCALE";fs_scansc(0.0-4.0)", "1.0", OPTION_FLOAT, "overall height scaling value for scanlines" }, { WINOPTION_SCANLINE_HEIGHT";fs_scanh(0.0-4.0)", "1.0", OPTION_FLOAT, "individual height scaling value for scanlines" }, { WINOPTION_SCANLINE_BRIGHT_SCALE";fs_scanbs(0.0-2.0)", "1.0", OPTION_FLOAT, "overall brightness scaling value for scanlines (multiplicative)" }, { WINOPTION_SCANLINE_BRIGHT_OFFSET";fs_scanbo(0.0-1.0)", "0.0", OPTION_FLOAT, "overall brightness offset value for scanlines (additive)" }, - { WINOPTION_SCANLINE_OFFSET";fs_scanjt(0.0-4.0)", "0.0", OPTION_FLOAT, "overall interlace jitter scaling value for scanlines" }, + { WINOPTION_SCANLINE_JITTER";fs_scanjt(0.0-4.0)", "0.0", OPTION_FLOAT, "overall interlace jitter scaling value for scanlines" }, + { WINOPTION_HUM_BAR_ALPHA";fs_humba(0.0-1.0)", "0.0", OPTION_FLOAT, "overall alpha scaling value for hum bar" }, { WINOPTION_DEFOCUS";fs_focus", "1.0,0.0", OPTION_STRING, "overall defocus value in screen-relative coords" }, { WINOPTION_CONVERGE_X";fs_convx", "0.25,0.00,-0.25", OPTION_STRING, "convergence in screen-relative X direction" }, { WINOPTION_CONVERGE_Y";fs_convy", "0.0,0.25,-0.25", OPTION_STRING, "convergence in screen-relative Y direction" }, @@ -327,10 +328,11 @@ const options_entry windows_options::s_option_entries[] = /* NTSC simulation below this line */ { NULL, NULL, OPTION_HEADER, "NTSC POST-PROCESSING OPTIONS" }, { WINOPTION_YIQ_ENABLE";yiq", "0", OPTION_BOOLEAN, "enables YIQ-space HLSL post-processing" }, - { WINOPTION_YIQ_CCVALUE";yiqcc", "3.59754545", OPTION_FLOAT, "Color Carrier frequency for NTSC signal processing" }, + { WINOPTION_YIQ_JITTER";yiqj", "0.0", OPTION_FLOAT, "Jitter for the NTSC signal processing" }, + { WINOPTION_YIQ_CCVALUE";yiqcc", "3.57954545", 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", "0.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 +340,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" }, diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 53f9e137604..a9f7066bf90 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -55,7 +55,8 @@ #define WINOPTION_SCANLINE_HEIGHT "scanline_height" #define WINOPTION_SCANLINE_BRIGHT_SCALE "scanline_bright_scale" #define WINOPTION_SCANLINE_BRIGHT_OFFSET "scanline_bright_offset" -#define WINOPTION_SCANLINE_OFFSET "scanline_jitter" +#define WINOPTION_SCANLINE_JITTER "scanline_jitter" +#define WINOPTION_HUM_BAR_ALPHA "hum_bar_alpha" #define WINOPTION_DEFOCUS "defocus" #define WINOPTION_CONVERGE_X "converge_x" #define WINOPTION_CONVERGE_Y "converge_y" @@ -71,6 +72,7 @@ #define WINOPTION_PHOSPHOR "phosphor_life" #define WINOPTION_SATURATION "saturation" #define WINOPTION_YIQ_ENABLE "yiq_enable" +#define WINOPTION_YIQ_JITTER "yiq_jitter" #define WINOPTION_YIQ_CCVALUE "yiq_cc" #define WINOPTION_YIQ_AVALUE "yiq_a" #define WINOPTION_YIQ_BVALUE "yiq_b" @@ -154,7 +156,8 @@ public: float screen_scanline_height() const { return float_value(WINOPTION_SCANLINE_HEIGHT); } float screen_scanline_bright_scale() const { return float_value(WINOPTION_SCANLINE_BRIGHT_SCALE); } float screen_scanline_bright_offset() const { return float_value(WINOPTION_SCANLINE_BRIGHT_OFFSET); } - float screen_scanline_offset() const { return float_value(WINOPTION_SCANLINE_OFFSET); } + float screen_scanline_jitter() const { return float_value(WINOPTION_SCANLINE_JITTER); } + float screen_hum_bar_alpha() const { return float_value(WINOPTION_HUM_BAR_ALPHA); } float screen_reflection() const { return float_value(WINOPTION_REFLECTION); } float screen_curvature() const { return float_value(WINOPTION_CURVATURE); } float screen_round_corner() const { return float_value(WINOPTION_ROUND_CORNER); } @@ -169,6 +172,7 @@ public: const char *screen_grn_ratio() const { return value(WINOPTION_GRN_RATIO); } const char *screen_blu_ratio() const { return value(WINOPTION_BLU_RATIO); } bool screen_yiq_enable() const { return bool_value(WINOPTION_YIQ_ENABLE); } + float screen_yiq_jitter() const { return float_value(WINOPTION_YIQ_JITTER); } float screen_yiq_cc() const { return float_value(WINOPTION_YIQ_CCVALUE); } float screen_yiq_a() const { return float_value(WINOPTION_YIQ_AVALUE); } float screen_yiq_b() const { return float_value(WINOPTION_YIQ_BVALUE); } |