summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2015-11-17 19:37:56 +0100
committer ImJezze <jezze@gmx.net>2015-11-17 19:37:56 +0100
commit8be53c28f0266af433076a6f5c1f1fa0abc70867 (patch)
tree5167ec845cdb853dddcbbafd84749308d3888095
parent5200f15ace282ad246bd38af900472db353ba241 (diff)
Changed screen adjustment for HLSL
- screen adjustment (scale, offset) can now be handled by the respective render API itself (default behavior is as before) - D3D (if HLSL) is activated handles screen adjustment by itself within the shader, which fixes the odd behavior of some effects (e.g. round corners) when screen scale and offset is used
-rw-r--r--hlsl/artwork_support/post.fx52
-rw-r--r--hlsl/post.fx32
-rw-r--r--src/emu/render.cpp14
-rw-r--r--src/emu/render.h4
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.cpp17
-rw-r--r--src/osd/modules/render/drawd3d.cpp5
6 files changed, 114 insertions, 10 deletions
diff --git a/hlsl/artwork_support/post.fx b/hlsl/artwork_support/post.fx
index f3d49d4dbaf..5fb864c3ef2 100644
--- a/hlsl/artwork_support/post.fx
+++ b/hlsl/artwork_support/post.fx
@@ -152,6 +152,9 @@ VS_OUTPUT vs_main(VS_INPUT Input)
// Post-Processing Pixel Shader
//-----------------------------------------------------------------------------
+uniform float2 ScreenScale = float2(1.0f, 1.0f);
+uniform float2 ScreenOffset = float2(0.0f, 0.0f);
+
uniform float ScanlineAlpha = 1.0f;
uniform float ScanlineScale = 1.0f;
uniform float ScanlineBrightScale = 1.0f;
@@ -334,6 +337,34 @@ float2 GetCoords(float2 coord, float2 centerOffset, float distortionAmount)
return coord;
}
+float2 GetAdjustedCoords(float2 coord, float2 centerOffset, float distortionAmount)
+{
+ float2 RatioCorrection = GetRatioCorrection();
+
+ // center coordinates
+ coord -= centerOffset;
+
+ // apply ratio difference between screen and quad
+ coord /= RatioCorrection;
+
+ // applay screen scale
+ coord /= ScreenScale;
+
+ // distort coordinates
+ coord = GetDistortedCoords(coord, distortionAmount);
+
+ // revert ratio difference between screen and quad
+ coord *= RatioCorrection;
+
+ // un-center coordinates
+ coord += centerOffset;
+
+ // apply screen offset
+ coord += (centerOffset * 2.0) * ScreenOffset;
+
+ return coord;
+}
+
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 ScreenTexelDims = 1.0f / ScreenDims;
@@ -345,8 +376,14 @@ float4 ps_main(PS_INPUT Input) : COLOR
float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
ScreenCoord = GetCoords(ScreenCoord, float2(0.5f, 0.5f), CurvatureAmount);
+ float2 DistortionCoord = Input.TexCoord;
+ DistortionCoord = GetCoords(DistortionCoord, HalfSourceRect, CurvatureAmount);
+
float2 BaseCoord = Input.TexCoord;
- BaseCoord = GetCoords(BaseCoord, HalfSourceRect, CurvatureAmount);
+ BaseCoord = GetAdjustedCoords(BaseCoord, HalfSourceRect, CurvatureAmount);
+
+ float2 DistortionCoordCentered = DistortionCoord;
+ DistortionCoordCentered -= HalfSourceRect;
float2 BaseCoordCentered = BaseCoord;
BaseCoordCentered -= HalfSourceRect;
@@ -354,6 +391,11 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
BaseColor.a = 1.0f;
+ if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f)
+ {
+ BaseColor.rgb = 0.0f;
+ }
+
// Mask Simulation (may not affect bloom)
if (!PrepareBloom)
{
@@ -431,7 +473,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
// Vignetting Simulation (may not affect bloom)
if (!PrepareBloom)
{
- float2 VignetteCoord = BaseCoordCentered;
+ float2 VignetteCoord = DistortionCoordCentered;
float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount);
Output.rgb *= VignetteFactor;
@@ -442,8 +484,8 @@ float4 ps_main(PS_INPUT Input) : COLOR
{
float3 LightColor = float3(1.0f, 0.90f, 0.80f);
- float2 SpotCoord = BaseCoordCentered;
- float2 NoiseCoord = BaseCoordCentered;
+ float2 SpotCoord = DistortionCoordCentered;
+ float2 NoiseCoord = DistortionCoordCentered;
float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount);
float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord));
@@ -451,7 +493,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
}
// Round Corners Simulation (may affect bloom)
- float2 RoundCornerCoord = BaseCoordCentered;
+ float2 RoundCornerCoord = DistortionCoordCentered;
float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount);
Output.rgb *= roundCornerFactor;
diff --git a/hlsl/post.fx b/hlsl/post.fx
index b457b9687e2..7ab09b45ddb 100644
--- a/hlsl/post.fx
+++ b/hlsl/post.fx
@@ -77,6 +77,7 @@ bool xor(bool a, bool b)
uniform float2 ScreenDims; // size of the window or fullscreen
uniform float2 SourceDims; // size of the texture in power-of-two size
+uniform float2 SourceRect; // size of the uv rectangle
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)
@@ -124,6 +125,9 @@ VS_OUTPUT vs_main(VS_INPUT Input)
// Post-Processing Pixel Shader
//-----------------------------------------------------------------------------
+uniform float2 ScreenScale = float2(1.0f, 1.0f);
+uniform float2 ScreenOffset = float2(0.0f, 0.0f);
+
uniform float ScanlineAlpha = 1.0f;
uniform float ScanlineScale = 1.0f;
uniform float ScanlineBrightScale = 1.0f;
@@ -138,17 +142,43 @@ uniform float2 ShadowUV = float2(0.25f, 0.25f);
uniform float3 Power = float3(1.0f, 1.0f, 1.0f);
uniform float3 Floor = float3(0.0f, 0.0f, 0.0f);
+float2 GetAdjustedCoords(float2 coord, float2 centerOffset)
+{
+ // center coordinates
+ coord -= centerOffset;
+
+ // apply screen scale
+ coord /= ScreenScale;
+
+ // un-center coordinates
+ coord += centerOffset;
+
+ // apply screen offset
+ coord += (centerOffset * 2.0) * ScreenOffset;
+
+ return coord;
+}
+
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 ScreenTexelDims = 1.0f / ScreenDims;
+ float2 HalfSourceRect = PrepareVector
+ ? float2(0.5f, 0.5f)
+ : SourceRect * 0.5f;
+
float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
- float2 BaseCoord = Input.TexCoord;
+ float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect);
// Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
BaseColor.a = 1.0f;
+ if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f)
+ {
+ BaseColor.rgb = 0.0f;
+ }
+
// Mask Simulation (may not affect bloom)
if (!PrepareBloom)
{
diff --git a/src/emu/render.cpp b/src/emu/render.cpp
index c86b3f914c5..e823f1fb7cf 100644
--- a/src/emu/render.cpp
+++ b/src/emu/render.cpp
@@ -924,7 +924,9 @@ render_target::render_target(render_manager &manager, const char *layoutfile, UI
m_base_view(NULL),
m_base_orientation(ROT0),
m_maxtexwidth(65536),
- m_maxtexheight(65536)
+ m_maxtexheight(65536),
+ m_scale_primitives(true),
+ m_offset_primitives(true)
{
// determine the base layer configuration based on options
m_base_layerconfig.set_backdrops_enabled(manager.machine().options().use_backdrops());
@@ -1659,6 +1661,16 @@ void render_target::add_container_primitives(render_primitive_list &list, const
float yoffs = (container_xform.orientation & ORIENTATION_SWAP_XY) ? container.xoffset() : container.yoffset();
if (container_xform.orientation & ORIENTATION_FLIP_X) xoffs = -xoffs;
if (container_xform.orientation & ORIENTATION_FLIP_Y) yoffs = -yoffs;
+ if (!m_scale_primitives)
+ {
+ xscale = 1.0f;
+ yscale = 1.0f;
+ }
+ if (!m_offset_primitives)
+ {
+ xoffs = 0.0f;
+ yoffs = 0.0f;
+ }
container_xform.xscale = xform.xscale * xscale;
container_xform.yscale = xform.yscale * yscale;
if (xform.no_center)
diff --git a/src/emu/render.h b/src/emu/render.h
index f3b37fb9aed..ad1bd7af4a9 100644
--- a/src/emu/render.h
+++ b/src/emu/render.h
@@ -898,6 +898,8 @@ public:
void set_orientation(int orientation) { m_orientation = orientation; }
void set_view(int viewindex);
void set_max_texture_size(int maxwidth, int maxheight);
+ void set_scale_primitives(bool enable) { m_scale_primitives = enable; }
+ void set_offset_primitives(bool enable) { m_offset_primitives = enable; }
// layer config getters
bool backdrops_enabled() const { return m_layerconfig.backdrops_enabled(); }
@@ -996,6 +998,8 @@ private:
simple_list<render_container> m_debug_containers; // list of debug containers
INT32 m_clear_extent_count; // number of clear extents
INT32 m_clear_extents[MAX_CLEAR_EXTENTS]; // array of clear extents
+ bool m_scale_primitives; // determines if the primitive shall be scaled/offset by screen settings,
+ bool m_offset_primitives; // otherwise the respective render API will handle it (default is true)
static render_screen_list s_empty_screen_list;
};
diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp
index 8c099c23dbf..a4c63f6380a 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.cpp
+++ b/src/osd/modules/render/d3d/d3dhlsl.cpp
@@ -964,8 +964,7 @@ int shaders::create_resources(bool reset)
color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION);
prescale_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
- prescale_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_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);
@@ -988,7 +987,7 @@ int shaders::create_resources(bool reset)
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); // backward compatibility
+ 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
@@ -1371,10 +1370,22 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int
? 3
: 0;
+ render_container &screen_container = machine->first_screen()->container();
+
+ float xscale = screen_container.xscale();
+ float yscale = screen_container.yscale();
+ float xoffset = -screen_container.xoffset();
+ float yoffset = -screen_container.yoffset();
+
+ float screen_scale[2] = { xscale, yscale };
+ float screen_offset[2] = { xoffset, yoffset };
+
curr_effect = post_effect;
curr_effect->update_uniforms();
curr_effect->set_texture("ShadowTexture", shadow_texture == NULL ? NULL : shadow_texture->get_finaltex());
curr_effect->set_texture("DiffuseTexture", rt->prescale_texture[next_index]);
+ 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);
diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp
index c10e539dd31..62012247463 100644
--- a/src/osd/modules/render/drawd3d.cpp
+++ b/src/osd/modules/render/drawd3d.cpp
@@ -245,6 +245,11 @@ render_primitive_list *d3d::renderer::get_primitives()
window().target()->set_bounds(rect_width(&client), rect_height(&client), window().aspect());
window().target()->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh());
}
+ if (m_shaders != NULL)
+ {
+ window().target()->set_scale_primitives(!m_shaders->enabled());
+ window().target()->set_offset_primitives(!m_shaders->enabled());
+ }
return &window().target()->get_primitives();
}