Refactored color converge

- color converge is now independent from ratio
- the radial converge now "translates" the most outer pixel as thay
would be translated by the linar converge with the same amount
- color converge is now limited to a maximum of 10
- added color converge pass to vector rendering
This commit is contained in:
ImJezze 2016-01-09 16:15:45 +01:00
parent 1cacb7d040
commit 37b596b7b4
2 changed files with 69 additions and 56 deletions

View file

@ -1,5 +1,5 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// Deconvergence Effect
//-----------------------------------------------------------------------------
@ -29,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
@ -42,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;
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);
Output.TexCoordX = TexCoord.xxx;
Output.TexCoordY = TexCoord.yyy;
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;
// center coordinates
Output.TexCoordX -= HalfSourceRect.xxx;
Output.TexCoordY -= HalfSourceRect.yyy;
// 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;
// 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;
}
@ -107,12 +120,11 @@ 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);
}
//-----------------------------------------------------------------------------

View file

@ -1797,6 +1797,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);
@ -2424,13 +2425,13 @@ static INT32 slider_scanline_offset(running_machine &machine, void *arg, std::st
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)
@ -2798,20 +2799,20 @@ shaders::slider_desc shaders::s_sliders[] =
{ "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 },
{ "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 },