diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx index 709628bcff9..17cb4b6a9e6 100644 --- a/hlsl/distortion.fx +++ b/hlsl/distortion.fx @@ -114,7 +114,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) uniform float CurvatureAmount = 0.0f; uniform float RoundCornerAmount = 0.0f; -uniform float SmoothBorderAmount = 0.5f; +uniform float SmoothBorderAmount = 0.0f; uniform float VignettingAmount = 0.0f; uniform float ReflectionAmount = 0.0f; @@ -122,7 +122,7 @@ uniform bool OrientationSwapXY = false; // false landscape, true portrait for de 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 GetRatioCorrecton() +float2 GetRatioCorrection() { float ScreenRatio = ScreenDims.x / ScreenDims.y; float QuadRatio = QuadDims.x / QuadDims.y; @@ -155,7 +155,7 @@ float GetVignetteFactor(float2 coord, float amount) float GetSpotAddend(float2 coord, float amount) { - float2 RatioCorrection = GetRatioCorrecton(); + float2 RatioCorrection = GetRatioCorrection(); // normalized screen quad ratio float2 QuadRatio = float2 (1.0f, QuadDims.y / QuadDims.x); @@ -191,19 +191,17 @@ float GetSpotAddend(float2 coord, float amount) float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount) { - float2 RatioCorrection = GetRatioCorrecton(); + float2 RatioCorrection = GetRatioCorrection(); + // reduce smooth amount down to radius amount smoothAmount = min(smoothAmount, radiusAmount); - float2 RoundCornerCoord = coord * 2; - - float MinScreenDims = min(ScreenDims.x, ScreenDims.y); - - float radius = MinScreenDims * 0.5 * max(radiusAmount, 0.01f); - float smooth = 1.0 / (MinScreenDims * 0.25 * max(smoothAmount, 0.01f)); + float range = min(ScreenDims.x, ScreenDims.y) * 0.5; + float radius = range * max(radiusAmount, 0.01f); + float smooth = 1.0 / (range * max(smoothAmount, 0.01f)); // compute box - float box = roundBox(ScreenDims * RoundCornerCoord, ScreenDims * RatioCorrection, radius); + float box = roundBox(ScreenDims * (coord * 2.0f), ScreenDims * RatioCorrection, radius); // apply smooth box *= smooth; @@ -215,17 +213,10 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount) } // www.francois-tarlier.com/blog/cubic-lens-distortion-shader/ -float2 GetDistortedCoords(float2 coord, float amount) +float2 GetDistortedCoords(float2 centerCoord, float amount) { amount *= 0.25f; // reduced amount - float2 RatioCorrection = GetRatioCorrecton(); - - // center coordinates - coord -= 0.5f; - - coord /= RatioCorrection; - // lens distortion coefficient float k = amount; @@ -233,20 +224,37 @@ float2 GetDistortedCoords(float2 coord, float amount) float kcube = amount * 2.0f; // compute cubic distortion factor - float r2 = coord.x * coord.x + coord.y * coord.y; + float r2 = centerCoord.x * centerCoord.x + centerCoord.y * centerCoord.y; float f = kcube == 0.0f - ? 1 + r2 * k - : 1 + r2 * (k + kcube * sqrt(r2)); + ? 1.0f + r2 * k + : 1.0f + r2 * (k + kcube * sqrt(r2)); - // correct zoom + // fit screen bounds f /= 1.0f + amount * 0.5f; // apply cubic distortion factor - coord *= f; + centerCoord *= f; + return centerCoord; +} + +float2 GetCoords(float2 coord, float distortionAmount) +{ + float2 RatioCorrection = GetRatioCorrection(); + + // center coordinates + coord -= 0.5f; + + // apply ratio difference between screen and quad + coord /= RatioCorrection; + + // distort coordinates + coord = GetDistortedCoords(coord, distortionAmount); + + // revert ratio difference between screen and quad coord *= RatioCorrection; - // uncenter coordinates + // un-center coordinates coord += 0.5f; return coord; @@ -257,22 +265,12 @@ float4 ps_main(PS_INPUT Input) : COLOR float2 TexCoord = Input.TexCoord; float2 BaseCoord = TexCoord; - // // test code - // // BaseCoord.x += (TexCoord.x > 0.5f ? -0.5f : 0.0f); - // BaseCoord.y += (TexCoord.y > 0.5f ? -0.5f : 0.0f); - // BaseCoord.y *= 2.0f; - // Screen Curvature - BaseCoord = GetDistortedCoords(BaseCoord, CurvatureAmount); + BaseCoord = GetCoords(BaseCoord, CurvatureAmount); float2 BaseCoordCentered = BaseCoord; BaseCoordCentered -= 0.5f; - // // test code - // BaseCoord.y /= 2.0f; - // // BaseCoord.x += (TexCoord.x > 0.5f ? +0.5f : 0.0f); - // BaseCoord.y += (TexCoord.y > 0.5 ? +0.5f : 0.0f); - // Color float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); BaseColor.a = 1.0f; @@ -284,7 +282,7 @@ float4 ps_main(PS_INPUT Input) : COLOR BaseColor.rgb *= VignetteFactor; // Light Reflection Simulation - float3 LightColor = float3(1.0f, 0.90f, 0.80f); + float3 LightColor = float3(1.0f, 0.90f, 0.80f); // color temperature 5.000 Kelvin float2 SpotCoord = BaseCoordCentered; float2 NoiseCoord = BaseCoordCentered; @@ -299,10 +297,6 @@ float4 ps_main(PS_INPUT Input) : COLOR float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount); BaseColor.rgb *= roundCornerFactor; - // // test code - // BaseColor.rgb = BaseCoord.x * BaseCoord.y; - // BaseColor.rgb = TexCoord.y > 0.5f ? 1.0f : 0.5f; - return BaseColor; } diff --git a/src/osd/modules/render/d3d/d3dcomm.h b/src/osd/modules/render/d3d/d3dcomm.h index daaa4bde9ac..58a51eaf1cf 100644 --- a/src/osd/modules/render/d3d/d3dcomm.h +++ b/src/osd/modules/render/d3d/d3dcomm.h @@ -146,11 +146,10 @@ public: vec2f & get_uvstop() { return m_stop; } vec2f & get_rawdims() { return m_rawdims; } - static void compute_size_subroutine(texture_manager* texture_manager, int texwidth, int texheight, int* p_width, int* p_height); - private: void prescale(); void compute_size(int texwidth, int texheight); + void compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height); texture_manager * m_texture_manager; // texture manager pointer diff --git a/src/osd/modules/render/d3d/d3dhlsl.c b/src/osd/modules/render/d3d/d3dhlsl.c index 2a42c8f9a0e..771a30b930c 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.c +++ b/src/osd/modules/render/d3d/d3dhlsl.c @@ -1609,7 +1609,8 @@ int shaders::distortion_pass(render_target *rt, int source_index, poly_info *pol if (options->reflection == 0 && options->vignetting == 0 && options->curvature == 0 && - options->round_corner == 0) + options->round_corner == 0 && + options->smooth_border == 0) { return next_index; } @@ -2765,11 +2766,11 @@ shaders::slider_desc shaders::s_sliders[] = { "Shadow Mask Pixel Count Y", 1, 6, 64, 1, slider_shadow_mask_vsize }, { "Shadow Mask Offset X", -100, 0, 100, 1, slider_shadow_mask_uoffset }, { "Shadow Mask Offset Y", -100, 0, 100, 1, slider_shadow_mask_voffset }, - { "Screen Curvature", 0, 3, 100, 1, slider_curvature }, - { "Screen Round Corner", 0, 3, 100, 1, slider_round_corner }, - { "Screen Smooth Border", 0, 3, 100, 1, slider_smooth_border }, - { "Screen Reflection", 0, 3, 100, 1, slider_reflection }, - { "Image Vignetting", 0, 3, 100, 1, slider_vignetting }, + { "Screen Curvature", 0, 0, 100, 1, slider_curvature }, + { "Screen Round Corner", 0, 0, 100, 1, slider_round_corner }, + { "Screen Smooth Border", 0, 0, 100, 1, slider_smooth_border }, + { "Screen Reflection", 0, 0, 100, 1, slider_reflection }, + { "Image Vignetting", 0, 0, 100, 1, slider_vignetting }, { "Scanline Darkness", 0, 100, 100, 1, slider_scanline_alpha }, { "Scanline Screen Height", 1, 20, 80, 1, slider_scanline_scale }, { "Scanline Indiv. Height", 1, 20, 80, 1, slider_scanline_height }, @@ -2922,7 +2923,7 @@ void uniform::update() } case CU_SOURCE_DIMS: { - vec2f& sourcedims = shadersys->curr_texture->get_rawdims(); + vec2f sourcedims = shadersys->curr_texture->get_rawdims(); m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); break; } diff --git a/src/osd/modules/render/drawd3d.c b/src/osd/modules/render/drawd3d.c index 2beeb16b663..12e4403fec1 100644 --- a/src/osd/modules/render/drawd3d.c +++ b/src/osd/modules/render/drawd3d.c @@ -2074,13 +2074,13 @@ error: // texture_info::compute_size_subroutine //============================================================ -void texture_info::compute_size_subroutine(texture_manager* texture_manager, int texwidth, int texheight, int* p_width, int* p_height) +void texture_info::compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height) { int finalheight = texheight; int finalwidth = texwidth; // round width/height up to nearest power of 2 if we need to - if (!(texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) + if (!(m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) { // first the width if (finalwidth & (finalwidth - 1)) @@ -2104,7 +2104,7 @@ void texture_info::compute_size_subroutine(texture_manager* texture_manager, int } // round up to square if we need to - if (texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) + if (m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) { if (finalwidth < finalheight) finalwidth = finalheight; @@ -2113,11 +2113,11 @@ void texture_info::compute_size_subroutine(texture_manager* texture_manager, int } // adjust the aspect ratio if we need to - while (finalwidth < finalheight && finalheight / finalwidth > texture_manager->get_max_texture_aspect()) + while (finalwidth < finalheight && finalheight / finalwidth > m_texture_manager->get_max_texture_aspect()) { finalwidth *= 2; } - while (finalheight < finalwidth && finalwidth / finalheight > texture_manager->get_max_texture_aspect()) + while (finalheight < finalwidth && finalwidth / finalheight > m_texture_manager->get_max_texture_aspect()) { finalheight *= 2; } @@ -2151,7 +2151,7 @@ void texture_info::compute_size(int texwidth, int texheight) finalwidth += 2 * m_xborderpix; finalheight += 2 * m_yborderpix; - texture_info::compute_size_subroutine(m_texture_manager, finalwidth, finalheight, &finalwidth, &finalheight); + compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight); // if we added pixels for the border, and that just barely pushed us over, take it back if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height()) @@ -2162,7 +2162,7 @@ void texture_info::compute_size(int texwidth, int texheight) m_xborderpix = 0; m_yborderpix = 0; - texture_info::compute_size_subroutine(m_texture_manager, finalwidth, finalheight, &finalwidth, &finalheight); + compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight); } // if we're above the max width/height, do what? diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index f06b5204dc0..1a7fe7fc6a3 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -302,11 +302,11 @@ const options_entry windows_options::s_option_entries[] = { WINOPTION_SHADOW_MASK_VSIZE";fs_shadwv(0.0-1.0)", "0.1875", OPTION_FLOAT, "shadow mask texture size in V direction" }, { WINOPTION_SHADOW_MASK_UOFFSET";fs_shadwou(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in U direction" }, { WINOPTION_SHADOW_MASK_VOFFSET";fs_shadwov(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in V direction" }, - { WINOPTION_CURVATURE";fs_curv(0.0-1.0)", "0.03", OPTION_FLOAT, "screen curvature amount" }, - { WINOPTION_ROUND_CORNER";fs_rndc(0.0-1.0)", "0.03", OPTION_FLOAT, "screen round corner amount" }, - { WINOPTION_SMOOTH_BORDER";fs_smob(0.0-1.0)", "0.03", OPTION_FLOAT, "screen smooth border amount" }, - { WINOPTION_REFLECTION";fs_ref(0.0-1.0)", "0.03", OPTION_FLOAT, "screen reflection amount" }, - { WINOPTION_VIGNETTING";fs_vig(0.0-1.0)", "0.03", OPTION_FLOAT, "image vignetting amount" }, + { WINOPTION_CURVATURE";fs_curv(0.0-1.0)", "0.0", OPTION_FLOAT, "screen curvature amount" }, + { WINOPTION_ROUND_CORNER";fs_rndc(0.0-1.0)", "0.0", OPTION_FLOAT, "screen round corner amount" }, + { WINOPTION_SMOOTH_BORDER";fs_smob(0.0-1.0)", "0.0", OPTION_FLOAT, "screen smooth border amount" }, + { 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_SCALE";fs_scansc(0.0-4.0)", "1.0", OPTION_FLOAT, "overall height scaling value for scanlines" },