mirror of
https://github.com/holub/mame
synced 2025-06-05 20:33:45 +03:00
Made defocus strength equal for x/y and independent from screen size
- defocus is now independent from screen size and ratio - horizontal and vertical defocus now have the same strength - replaced asymmetric defocus kernel by a symmetric kernel - defocus is now limited to a maximum of 10 - added shader uniforms for orientation and rotation settings
This commit is contained in:
parent
4e580a77b9
commit
b1f1300517
@ -25,14 +25,7 @@ struct VS_OUTPUT
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoord0 : TEXCOORD0;
|
||||
float2 TexCoord1 : TEXCOORD1;
|
||||
float2 TexCoord2 : TEXCOORD2;
|
||||
float2 TexCoord3 : TEXCOORD3;
|
||||
float2 TexCoord4 : TEXCOORD4;
|
||||
float2 TexCoord5 : TEXCOORD5;
|
||||
float2 TexCoord6 : TEXCOORD6;
|
||||
float2 TexCoord7 : TEXCOORD7;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VS_INPUT
|
||||
@ -45,39 +38,31 @@ struct VS_INPUT
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoord0 : TEXCOORD0;
|
||||
float2 TexCoord1 : TEXCOORD1;
|
||||
float2 TexCoord2 : TEXCOORD2;
|
||||
float2 TexCoord3 : TEXCOORD3;
|
||||
float2 TexCoord4 : TEXCOORD4;
|
||||
float2 TexCoord5 : TEXCOORD5;
|
||||
float2 TexCoord6 : TEXCOORD6;
|
||||
float2 TexCoord7 : TEXCOORD7;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool xor(bool a, bool b)
|
||||
{
|
||||
return (a || b) && !(a && b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Simple Vertex Shader
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform float2 ScreenDims;
|
||||
uniform float2 TargetDims;
|
||||
|
||||
uniform float2 Defocus = float2(0.0f, 0.0f);
|
||||
|
||||
float2 Coord1Offset = float2(-0.2f, -0.6f);
|
||||
float2 Coord2Offset = float2( 0.4f, -0.4f);
|
||||
float2 Coord3Offset = float2( 0.6f, 0.2f);
|
||||
float2 Coord4Offset = float2( 0.2f, 0.6f);
|
||||
float2 Coord5Offset = float2(-0.4f, 0.6f);
|
||||
float2 Coord6Offset = float2(-0.6f, 0.2f);
|
||||
float2 Coord7Offset = float2(-0.6f, -0.4f);
|
||||
uniform float2 SourceRect;
|
||||
uniform float2 QuadDims;
|
||||
|
||||
VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
{
|
||||
VS_OUTPUT Output = (VS_OUTPUT)0;
|
||||
|
||||
float2 ScreenTexelDims = 1.0f / ScreenDims;
|
||||
|
||||
Output.Position = float4(Input.Position.xyz, 1.0f);
|
||||
Output.Position.xy /= ScreenDims;
|
||||
Output.Position.y = 1.0f - Output.Position.y; // flip y
|
||||
@ -87,15 +72,8 @@ VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
float2 TexCoord = Input.TexCoord;
|
||||
TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9)
|
||||
|
||||
Output.TexCoord0 = TexCoord;
|
||||
Output.TexCoord1 = TexCoord + Coord1Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord2 = TexCoord + Coord2Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord3 = TexCoord + Coord3Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord4 = TexCoord + Coord4Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord5 = TexCoord + Coord5Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord6 = TexCoord + Coord6Offset * ScreenTexelDims * Defocus;
|
||||
Output.TexCoord7 = TexCoord + Coord7Offset * ScreenTexelDims * Defocus;
|
||||
|
||||
Output.TexCoord = TexCoord;
|
||||
|
||||
Output.Color = Input.Color;
|
||||
|
||||
return Output;
|
||||
@ -105,21 +83,44 @@ VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
// Simple Pixel Shader
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float2 Coord1Offset = float2( 0.75f, 0.50f);
|
||||
float2 Coord2Offset = float2( 0.25f, 1.00f);
|
||||
float2 Coord3Offset = float2(-0.50f, 0.75f);
|
||||
float2 Coord4Offset = float2(-1.00f, 0.25f);
|
||||
float2 Coord5Offset = float2(-0.75f, -0.50f);
|
||||
float2 Coord6Offset = float2(-0.25f, -1.00f);
|
||||
float2 Coord7Offset = float2( 0.50f, -0.75f);
|
||||
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
|
||||
|
||||
float4 ps_main(PS_INPUT Input) : COLOR
|
||||
{
|
||||
float4 d0 = tex2D(DiffuseSampler, Input.TexCoord0);
|
||||
float3 d1 = tex2D(DiffuseSampler, Input.TexCoord1).rgb;
|
||||
float3 d2 = tex2D(DiffuseSampler, Input.TexCoord2).rgb;
|
||||
float3 d3 = tex2D(DiffuseSampler, Input.TexCoord3).rgb;
|
||||
float3 d4 = tex2D(DiffuseSampler, Input.TexCoord4).rgb;
|
||||
float3 d5 = tex2D(DiffuseSampler, Input.TexCoord5).rgb;
|
||||
float3 d6 = tex2D(DiffuseSampler, Input.TexCoord6).rgb;
|
||||
float3 d7 = tex2D(DiffuseSampler, Input.TexCoord7).rgb;
|
||||
float2 QuadRatio =
|
||||
float2(1.0f, xor(OrientationSwapXY, RotationSwapXY)
|
||||
? QuadDims.y / QuadDims.x
|
||||
: QuadDims.x / QuadDims.y);
|
||||
|
||||
float3 blurred = (d0.rgb + d1 + d2 + d3 + d4 + d5 + d6 + d7) / 8.0f;
|
||||
blurred = lerp(d0.rgb, blurred, 1.0f);
|
||||
// imaginary texel dimensions independed from quad dimensions, but dependend on quad ratio
|
||||
float2 DefocusTexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio * Defocus;
|
||||
|
||||
return float4(blurred, d0.a);
|
||||
float4 d = tex2D(DiffuseSampler, Input.TexCoord);
|
||||
float3 d1 = tex2D(DiffuseSampler, Input.TexCoord + Coord1Offset * DefocusTexelDims).rgb;
|
||||
float3 d2 = tex2D(DiffuseSampler, Input.TexCoord + Coord2Offset * DefocusTexelDims).rgb;
|
||||
float3 d3 = tex2D(DiffuseSampler, Input.TexCoord + Coord3Offset * DefocusTexelDims).rgb;
|
||||
float3 d4 = tex2D(DiffuseSampler, Input.TexCoord + Coord4Offset * DefocusTexelDims).rgb;
|
||||
float3 d5 = tex2D(DiffuseSampler, Input.TexCoord + Coord5Offset * DefocusTexelDims).rgb;
|
||||
float3 d6 = tex2D(DiffuseSampler, Input.TexCoord + Coord6Offset * DefocusTexelDims).rgb;
|
||||
float3 d7 = tex2D(DiffuseSampler, Input.TexCoord + Coord7Offset * DefocusTexelDims).rgb;
|
||||
float3 d8 = tex2D(DiffuseSampler, Input.TexCoord + Coord8Offset * DefocusTexelDims).rgb;
|
||||
|
||||
float3 blurred = (d.rgb + d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8) / 9.0f;
|
||||
blurred = lerp(d.rgb, blurred, 1.0f);
|
||||
|
||||
return float4(blurred, d.a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -988,7 +988,11 @@ int shaders::create_resources(bool reset)
|
||||
|
||||
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);
|
||||
@ -1025,6 +1029,10 @@ 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);
|
||||
@ -1035,6 +1043,10 @@ int shaders::create_resources(bool reset)
|
||||
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);
|
||||
@ -1369,19 +1381,6 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int
|
||||
(machine->first_screen()->screen_type() & SCREEN_TYPE_VECTOR) == SCREEN_TYPE_VECTOR;
|
||||
bool prepare_raster =
|
||||
(machine->first_screen()->screen_type() & SCREEN_TYPE_RASTER) == SCREEN_TYPE_RASTER;
|
||||
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;
|
||||
int rotation_type =
|
||||
(d3d->window().target()->orientation() & ROT90) == ROT90
|
||||
? 1
|
||||
: (d3d->window().target()->orientation() & ROT180) == ROT180
|
||||
? 2
|
||||
: (d3d->window().target()->orientation() & ROT270) == ROT270
|
||||
? 3
|
||||
: 0;
|
||||
|
||||
screen_device_iterator screen_iterator(machine->root_device());
|
||||
screen_device *screen = screen_iterator.first();
|
||||
@ -1406,9 +1405,6 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int
|
||||
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_bool("OrientationSwapXY", orientation_swap_xy);
|
||||
curr_effect->set_bool("RotationSwapXY", rotation_swap_xy);
|
||||
curr_effect->set_int("RotationType", rotation_type); // backward compatibility
|
||||
curr_effect->set_bool("PrepareBloom", prepare_bloom);
|
||||
curr_effect->set_bool("PrepareVector", prepare_vector);
|
||||
curr_effect->set_bool("PrepareRaster", prepare_raster);
|
||||
@ -1563,26 +1559,9 @@ int shaders::distortion_pass(render_target *rt, int source_index, poly_info *pol
|
||||
return next_index;
|
||||
}
|
||||
|
||||
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;
|
||||
int rotation_type =
|
||||
(d3d->window().target()->orientation() & ROT90) == ROT90
|
||||
? 1
|
||||
: (d3d->window().target()->orientation() & ROT180) == ROT180
|
||||
? 2
|
||||
: (d3d->window().target()->orientation() & ROT270) == ROT270
|
||||
? 3
|
||||
: 0;
|
||||
|
||||
curr_effect = distortion_effect;
|
||||
curr_effect->update_uniforms();
|
||||
curr_effect->set_texture("DiffuseTexture", rt->prescale_texture[next_index]);
|
||||
curr_effect->set_bool("OrientationSwapXY", orientation_swap_xy);
|
||||
curr_effect->set_bool("RotationSwapXY", rotation_swap_xy);
|
||||
curr_effect->set_int("RotationType", rotation_type);
|
||||
|
||||
next_index = rt->next_index(next_index);
|
||||
blit(rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count());
|
||||
@ -1766,7 +1745,8 @@ 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 = defocus_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);
|
||||
|
||||
// create bloom textures
|
||||
@ -2732,8 +2712,8 @@ shaders::slider_desc shaders::s_sliders[] =
|
||||
{ "Scanline Brightness", 0, 20, 40, 1, 1, slider_scanline_bright_scale },
|
||||
{ "Scanline Brightness Overdrive", 0, 0, 20, 1, 1, slider_scanline_bright_offset },
|
||||
{ "Scanline Jitter", 0, 0, 40, 1, 1, slider_scanline_offset },
|
||||
{ "Defocus X", 0, 0, 64, 1, 3, slider_defocus_x },
|
||||
{ "Defocus Y", 0, 0, 64, 1, 3, slider_defocus_y },
|
||||
{ "Defocus X", 0, 0, 20, 1, 3, slider_defocus_x },
|
||||
{ "Defocus Y", 0, 0, 20, 1, 3, slider_defocus_y },
|
||||
{ "Red Position Offset X", -1500, 0, 1500, 1, 3, slider_red_converge_x },
|
||||
{ "Red Position Offset Y", -1500, 0, 1500, 1, 3, slider_red_converge_y },
|
||||
{ "Green Position Offset X", -1500, 0, 1500, 1, 3, slider_green_converge_x },
|
||||
@ -2834,6 +2814,7 @@ uniform::uniform(effect *shader, const char *name, uniform_type type, int id)
|
||||
m_next = NULL;
|
||||
m_handle = m_shader->get_parameter(NULL, name);
|
||||
m_ival = 0;
|
||||
m_bval = false;
|
||||
memset(m_vec, 0, sizeof(float) * 4);
|
||||
m_mval = NULL;
|
||||
m_texture = NULL;
|
||||
@ -2841,6 +2822,7 @@ uniform::uniform(effect *shader, const char *name, uniform_type type, int id)
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case UT_BOOL:
|
||||
case UT_INT:
|
||||
case UT_FLOAT:
|
||||
case UT_MATRIX:
|
||||
@ -2919,6 +2901,33 @@ void uniform::update()
|
||||
break;
|
||||
}
|
||||
|
||||
case CU_ORIENTATION_SWAP:
|
||||
{
|
||||
bool orientation_swap_xy =
|
||||
(d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
|
||||
m_shader->set_bool("OrientationSwapXY", orientation_swap_xy);
|
||||
|
||||
}
|
||||
case CU_ROTATION_SWAP:
|
||||
{
|
||||
bool rotation_swap_xy =
|
||||
(d3d->window().target()->orientation() & ROT90) == ROT90 ||
|
||||
(d3d->window().target()->orientation() & ROT270) == ROT270;
|
||||
m_shader->set_bool("RotationSwapXY", rotation_swap_xy);
|
||||
}
|
||||
case CU_ROTATION_TYPE:
|
||||
{
|
||||
int rotation_type =
|
||||
(d3d->window().target()->orientation() & ROT90) == ROT90
|
||||
? 1
|
||||
: (d3d->window().target()->orientation() & ROT180) == ROT180
|
||||
? 2
|
||||
: (d3d->window().target()->orientation() & ROT270) == ROT270
|
||||
? 3
|
||||
: 0;
|
||||
m_shader->set_int("RotationType", rotation_type);
|
||||
}
|
||||
|
||||
case CU_NTSC_CCFREQ:
|
||||
m_shader->set_float("CCValue", options->yiq_cc);
|
||||
break;
|
||||
@ -3123,6 +3132,11 @@ void uniform::set(int x)
|
||||
m_ival = x;
|
||||
}
|
||||
|
||||
void uniform::set(bool x)
|
||||
{
|
||||
m_bval = x;
|
||||
}
|
||||
|
||||
void uniform::set(matrix *mat)
|
||||
{
|
||||
m_mval = mat;
|
||||
@ -3137,6 +3151,9 @@ void uniform::upload()
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case UT_BOOL:
|
||||
m_shader->set_bool(m_handle, m_bval);
|
||||
break;
|
||||
case UT_INT:
|
||||
m_shader->set_int(m_handle, m_ival);
|
||||
break;
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
UT_VEC2,
|
||||
UT_FLOAT,
|
||||
UT_INT,
|
||||
UT_BOOL,
|
||||
UT_MATRIX,
|
||||
UT_SAMPLER
|
||||
} uniform_type;
|
||||
@ -49,6 +50,10 @@ public:
|
||||
CU_TARGET_DIMS,
|
||||
CU_QUAD_DIMS,
|
||||
|
||||
CU_ORIENTATION_SWAP,
|
||||
CU_ROTATION_SWAP,
|
||||
CU_ROTATION_TYPE,
|
||||
|
||||
CU_NTSC_CCFREQ,
|
||||
CU_NTSC_A,
|
||||
CU_NTSC_B,
|
||||
@ -114,6 +119,7 @@ public:
|
||||
void set(float x, float y);
|
||||
void set(float x);
|
||||
void set(int x);
|
||||
void set(bool x);
|
||||
void set(matrix *mat);
|
||||
void set(texture *tex);
|
||||
|
||||
@ -125,6 +131,7 @@ protected:
|
||||
|
||||
float m_vec[4];
|
||||
int m_ival;
|
||||
bool m_bval;
|
||||
matrix *m_mval;
|
||||
texture *m_texture;
|
||||
int m_count;
|
||||
|
Loading…
Reference in New Issue
Block a user