Refactoring

- replaced shader parameters OrientationSwapXY xor RotationSwapXY by
SwapXY
- made shader parameters SourceDims, SourceRect, TargetDims, ScreenDims,
QuadDims and SwapXY available for all shaders
- color convolution, defocus and phosphor pass will now be skipped if
all influencing parameters are 0
- removed unused bloom_texture and bloom_target arrays from cache_target
class
- fixed half texel offset in prescale.fx
This commit is contained in:
ImJezze 2015-12-31 16:59:23 +01:00
parent eea40fd0e4
commit a2c7b61daa
9 changed files with 131 additions and 180 deletions

View File

@ -74,11 +74,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)
{
@ -114,8 +109,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
@ -126,7 +121,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;
@ -227,7 +222,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);
@ -240,7 +235,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);
@ -272,7 +267,7 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount)
float2 CanvasDims = PrepareVector
? ScreenDims
: xor(OrientationSwapXY, RotationSwapXY)
: SwapXY
? QuadDims.yx / SourceRect
: QuadDims.xy / SourceRect;
@ -375,9 +370,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
@ -406,34 +399,34 @@ float4 ps_main(PS_INPUT Input) : COLOR
if (!PrepareBloom)
{
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;

View File

@ -59,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)
{
@ -122,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()

View File

@ -45,15 +45,6 @@ struct PS_INPUT
float2 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
bool xor(bool a, bool b)
{
return (a || b) && !(a && b);
}
//-----------------------------------------------------------------------------
// Defocus Vertex Shader
//-----------------------------------------------------------------------------
@ -98,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;

View File

@ -66,15 +66,6 @@ struct PS_INPUT
static const float PI = 3.1415927f;
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
bool xor(bool a, bool b)
{
return (a || b) && !(a && b);
}
//-----------------------------------------------------------------------------
// Scanline & Shadowmask Vertex Shader
//-----------------------------------------------------------------------------
@ -87,8 +78,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;
@ -98,7 +88,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;
@ -170,9 +160,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;
float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect);
@ -190,34 +178,34 @@ float4 ps_main(PS_INPUT Input) : COLOR
if (!PrepareBloom)
{
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;

View File

@ -49,6 +49,7 @@ struct PS_INPUT
//-----------------------------------------------------------------------------
uniform float2 ScreenDims;
uniform float2 TargetDims;
VS_OUTPUT vs_main(VS_INPUT Input)
{
@ -56,11 +57,12 @@ 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;
}

View File

@ -940,9 +940,33 @@ 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);
effect *effects[14] = {
default_effect,
post_effect,
distortion_effect,
prescale_effect,
phosphor_effect,
focus_effect,
deconverge_effect,
color_effect,
yiq_encode_effect,
yiq_decode_effect,
color_effect,
bloom_effect,
downsample_effect,
vector_effect
};
for (int i = 0; i < 14; 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);
}
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);
@ -953,9 +977,6 @@ int shaders::create_resources(bool reset)
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);
@ -967,9 +988,6 @@ int shaders::create_resources(bool reset)
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);
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);
color_effect->add_uniform("BluRatios", uniform::UT_VEC3, uniform::CU_COLOR_BLU_RATIOS);
@ -977,39 +995,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 +1024,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;
@ -1359,6 +1340,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]);
@ -1373,11 +1363,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;
}
@ -1396,6 +1383,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]);
@ -1421,8 +1414,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;
@ -1459,7 +1450,7 @@ 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_offset);
curr_effect->set_bool("PrepareBloom", prepare_bloom);
curr_effect->set_bool("PrepareVector", prepare_vector);
@ -1473,16 +1464,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);
@ -1519,10 +1509,8 @@ 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;
}
@ -1558,7 +1546,7 @@ int shaders::bloom_pass(render_target *rt, int source_index, poly_info *poly, in
curr_effect->set_vector("LevelASize", 2, bloom_dims[10]);
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]);
@ -1755,7 +1743,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);
@ -2960,38 +2948,68 @@ void uniform::update()
break;
}
case CU_SOURCE_DIMS:
{
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:
{
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() };
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 =

View File

@ -50,6 +50,7 @@ public:
CU_TARGET_DIMS,
CU_QUAD_DIMS,
CU_SWAP_XY,
CU_ORIENTATION_SWAP,
CU_ROTATION_SWAP,
CU_ROTATION_TYPE,

View File

@ -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)
{

View File

@ -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 */