diff --git a/bgfx/chains/hlsl.json b/bgfx/chains/hlsl.json index ea94200dfc3..a3499dc7283 100644 --- a/bgfx/chains/hlsl.json +++ b/bgfx/chains/hlsl.json @@ -84,7 +84,7 @@ { "type": "vec2", "name": "radial_converge_green", "text": "Green Radial Convergence, ", "default": [ 0.0, 0.0 ], "max": [ 10.0, 10.0 ], "min": [ -10.0, -10.0 ], "step": 0.1, "format": "%2.1f", "screen": "raster" }, { "type": "vec2", "name": "radial_converge_blue", "text": "Blue Radial Convergence, ", "default": [ 0.0, 0.0 ], "max": [ 10.0, 10.0 ], "min": [ -10.0, -10.0 ], "step": 0.1, "format": "%2.1f", "screen": "raster" }, - { "type": "vec2", "name": "defocus", "text": "Defocus, ", "default": [ 0.5, 0.5 ], "max": [ 10.0, 10.0 ], "min": [ 0.0, 0.0 ], "step": 0.1, "format": "%2.1f", "screen": "crt" }, + { "type": "vec2", "name": "defocus", "text": "Defocus, ", "default": [ 0.5, 0.5 ], "max": [ 2.0, 2.0 ], "min": [ 0.0, 0.0 ], "step": 0.1, "format": "%1.1f", "screen": "crt" }, { "type": "color", "name": "phosphor", "text": "Phosphor Persistence, ", "default": [ 0.45, 0.45, 0.45 ], "max": [ 1.00, 1.00, 1.00 ], "min": [ 0.00, 0.00, 0.00 ], "step": 0.01, "format": "%1.2f", "screen": "crt" }, @@ -391,21 +391,7 @@ "output": "internal" }, { "effect": "hlsl/defocus", - "name": "Defocus Pass 1", - "disablewhen": [ - { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, - { "type": "slider", "condition": "equal", "combine": "or", "name": "defocus", "value": [ 0, 0 ] } - ], - "uniforms": [ - { "uniform": "u_defocus", "slider": "defocus" } - ], - "input": [ - { "sampler": "s_tex", "target": "internal" } - ], - "output": "internal" - }, - { "effect": "hlsl/defocus", - "name": "Defocus Pass 2", + "name": "Defocus Pass", "disablewhen": [ { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, { "type": "slider", "condition": "equal", "combine": "or", "name": "defocus", "value": [ 0, 0 ] } diff --git a/bgfx/shaders/dx11/chains/hlsl/fs_defocus.bin b/bgfx/shaders/dx11/chains/hlsl/fs_defocus.bin index 1636abdef10..7459dabdcac 100644 Binary files a/bgfx/shaders/dx11/chains/hlsl/fs_defocus.bin and b/bgfx/shaders/dx11/chains/hlsl/fs_defocus.bin differ diff --git a/bgfx/shaders/dx9/chains/hlsl/fs_defocus.bin b/bgfx/shaders/dx9/chains/hlsl/fs_defocus.bin index 12ed2624d0b..c14f1574af3 100644 Binary files a/bgfx/shaders/dx9/chains/hlsl/fs_defocus.bin and b/bgfx/shaders/dx9/chains/hlsl/fs_defocus.bin differ diff --git a/bgfx/shaders/gles/chains/hlsl/fs_defocus.bin b/bgfx/shaders/gles/chains/hlsl/fs_defocus.bin index 5d29797339f..ce6684682f7 100644 Binary files a/bgfx/shaders/gles/chains/hlsl/fs_defocus.bin and b/bgfx/shaders/gles/chains/hlsl/fs_defocus.bin differ diff --git a/bgfx/shaders/glsl/chains/hlsl/fs_defocus.bin b/bgfx/shaders/glsl/chains/hlsl/fs_defocus.bin index 27765612664..238e85969c2 100644 Binary files a/bgfx/shaders/glsl/chains/hlsl/fs_defocus.bin and b/bgfx/shaders/glsl/chains/hlsl/fs_defocus.bin differ diff --git a/bgfx/shaders/metal/chains/hlsl/fs_defocus.bin b/bgfx/shaders/metal/chains/hlsl/fs_defocus.bin index ab14379b016..90bf785e554 100644 Binary files a/bgfx/shaders/metal/chains/hlsl/fs_defocus.bin and b/bgfx/shaders/metal/chains/hlsl/fs_defocus.bin differ diff --git a/hlsl/focus.fx b/hlsl/focus.fx index 138ad0eea6d..6758d51fdc3 100644 --- a/hlsl/focus.fx +++ b/hlsl/focus.fx @@ -78,36 +78,38 @@ VS_OUTPUT vs_main(VS_INPUT Input) uniform float2 Defocus = float2(0.0f, 0.0f); -static const float2 Coord1Offset = float2( 0.75f, 0.50f); -static const float2 Coord2Offset = float2( 0.25f, 1.00f); -static const float2 Coord3Offset = float2(-0.50f, 0.75f); -static const float2 Coord4Offset = float2(-1.00f, 0.25f); -static const float2 Coord5Offset = float2(-0.75f, -0.50f); -static const float2 Coord6Offset = float2(-0.25f, -1.00f); -static const float2 Coord7Offset = float2( 0.50f, -0.75f); -static const float2 Coord8Offset = float2( 1.00f, -0.25f); +// previously this pass was applied two times with offsets of 0.25, 0.5, 0.75, 1.0 +// now this pass is applied only once with offsets of 0.25, 0.55, 1.0, 1.6 to achieve the same appearance as before till a maximum defocus of 2.0 +static const float2 CoordOffset8[8] = +{ + // 0.075x² + 0.225x + 0.25 + float2(-1.60f, 0.25f), + float2(-1.00f, -0.55f), + float2(-0.55f, 1.00f), + float2(-0.25f, -1.60f), + float2( 0.25f, 1.60f), + float2( 0.55f, -1.00f), + float2( 1.00f, 0.55f), + float2( 1.60f, -0.25f), +}; float4 ps_main(PS_INPUT Input) : COLOR { - // imaginary texel dimensions independed from screen dimension, but ratio - float2 TexelDims = (1.0f / 1024); + // imaginary texel dimensions independed from source and target dimension + float2 TexelDims = (1.0f / 1024.0f); float2 DefocusTexelDims = Defocus * TexelDims; - 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 texel = tex2D(DiffuseSampler, Input.TexCoord).rgb; + float samples = 1.0f; - float3 blurred = (d.rgb + d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8) / 9.0f; - blurred = lerp(d.rgb, blurred, 1.0f); + for (int i = 0; i < 8; i++) + { + texel += tex2D(DiffuseSampler, Input.TexCoord + CoordOffset8[i] * DefocusTexelDims).rgb; + samples += 1.0f; + } - return float4(blurred, d.a); + return float4(texel / samples, 1.0f); } //----------------------------------------------------------------------------- @@ -120,7 +122,7 @@ technique DefaultTechnique { Lighting = FALSE; - VertexShader = compile vs_2_0 vs_main(); - PixelShader = compile ps_2_0 ps_main(); + VertexShader = compile vs_3_0 vs_main(); + PixelShader = compile ps_3_0 ps_main(); } } diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_defocus.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_defocus.sc index 77130d98d13..cfb7b487596 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_defocus.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_defocus.sc @@ -23,17 +23,23 @@ SAMPLER2D(s_tex, 0); void main() { - const vec2 Coord1Offset = vec2( 0.75, 0.50); - const vec2 Coord2Offset = vec2( 0.25, 1.00); - const vec2 Coord3Offset = vec2(-0.50, 0.75); - const vec2 Coord4Offset = vec2(-1.00, 0.25); - const vec2 Coord5Offset = vec2(-0.75, -0.50); - const vec2 Coord6Offset = vec2(-0.25, -1.00); - const vec2 Coord7Offset = vec2( 0.50, -0.75); - const vec2 Coord8Offset = vec2( 1.00, -0.25); + // previously this pass was applied two times with offsets of 0.25, 0.5, 0.75, 1.0 + // now this pass is applied only once with offsets of 0.25, 0.55, 1.0, 1.6 to achieve the same appearance as before till a maximum defocus of 2.0 + // 0.075x² + 0.225x + 0.25 + const vec2 Coord1Offset = vec2(-1.60, 0.25); + const vec2 Coord2Offset = vec2(-1.00, -0.55); + const vec2 Coord3Offset = vec2(-0.55, 1.00); + const vec2 Coord4Offset = vec2(-0.25, -1.60); + const vec2 Coord5Offset = vec2( 0.25, 1.60); + const vec2 Coord6Offset = vec2( 0.55, -1.00); + const vec2 Coord7Offset = vec2( 1.00, 0.55); + const vec2 Coord8Offset = vec2( 1.60, -0.25); + + // imaginary texel dimensions independed from source and target dimension + vec2 TexelDims = vec2_splat(1.0 / 1024.0); + + vec2 DefocusTexelDims = u_defocus.xy * TexelDims.xy; - vec2 DefocusTexelDims = u_defocus.xy / u_tex_size0.xy; - vec4 d0 = texture2D(s_tex, v_texcoord0); vec4 d1 = texture2D(s_tex, v_texcoord0 + Coord1Offset * DefocusTexelDims); vec4 d2 = texture2D(s_tex, v_texcoord0 + Coord2Offset * DefocusTexelDims); diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 3ea23ba5b04..cf454b92ecb 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -1350,8 +1350,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) next_index = color_convolution_pass(rt, next_index, poly, vertnum); // handled in bgfx next_index = prescale_pass(rt, next_index, poly, vertnum); // handled in bgfx next_index = deconverge_pass(rt, next_index, poly, vertnum); // handled in bgfx - next_index = defocus_pass(rt, next_index, poly, vertnum); // 1st pass - next_index = defocus_pass(rt, next_index, poly, vertnum); // 2nd pass + next_index = defocus_pass(rt, next_index, poly, vertnum); next_index = phosphor_pass(rt, next_index, poly, vertnum); // create bloom textures @@ -1430,8 +1429,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) 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 = defocus_pass(rt, next_index, poly, vertnum); next_index = phosphor_pass(rt, next_index, poly, vertnum); // create bloom textures @@ -2004,7 +2002,7 @@ slider_desc shaders::s_sliders[] = { "Scanline Brightness Offset", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_BRIGHT_OFFSET, 0.01f, "%1.2f", {} }, { "Scanline Jitter Amount", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_JITTER, 0.01f, "%1.2f", {} }, { "Hum Bar Amount", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_HUM_BAR_ALPHA, 0.01f, "%2.2f", {} }, - { "Defocus", 0, 0, 100, 1, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_DEFOCUS, 0.1f, "%2.1f", {} }, + { "Defocus", 0, 0, 20, 1, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_DEFOCUS, 0.1f, "%1.1f", {} }, { "Linear Convergence X,", -100, 0, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_CONVERGE_X, 0.1f, "%3.1f",{} }, { "Linear Convergence Y,", -100, 0, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_CONVERGE_Y, 0.1f, "%3.1f", {} }, { "Radial Convergence X,", -100, 0, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_RADIAL_CONVERGE_X, 0.1f, "%3.1f", {} },