diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc | 39 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_scanline.sc | 101 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_scanline.sc | 14 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.cpp | 120 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.h | 2 |
5 files changed, 216 insertions, 60 deletions
diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc index beba1f1743f..4aa3719c0ab 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc @@ -13,19 +13,11 @@ uniform vec4 u_swap_xy; uniform vec4 u_source_dims; // size of the guest machine uniform vec4 u_target_dims; uniform vec4 u_target_scale; -uniform vec4 u_quad_dims; uniform vec4 u_screen_scale; uniform vec4 u_screen_offset; // uniform vec4 u_back_color; // TODO // User-supplied -uniform vec4 u_scanline_alpha; -uniform vec4 u_scanline_scale; -uniform vec4 u_scanline_bright_scale; -uniform vec4 u_scanline_bright_offset; -uniform vec4 u_scanline_jitter; -uniform vec4 u_scanline_height; -uniform vec4 u_scanline_variation; uniform vec4 u_shadow_tile_mode; uniform vec4 u_shadow_alpha; uniform vec4 u_shadow_count; @@ -38,14 +30,13 @@ uniform vec4 u_floor; // Parametric uniform vec4 u_time; // milliseconds -uniform vec4 u_jitter_amount; // Samplers SAMPLER2D(s_tex, 0); SAMPLER2D(s_shadow, 1); //----------------------------------------------------------------------------- -// Scanline & Shadowmask Pixel Shader +// Shadowmask Pixel Shader //----------------------------------------------------------------------------- vec2 GetAdjustedCoords(vec2 coord) @@ -148,34 +139,6 @@ void main() BaseColor.g = pow(BaseColor.g, u_power.g); BaseColor.b = pow(BaseColor.b, u_power.b); - // Scanline Simulation - if (u_scanline_alpha.x > 0.0f) - { - float BrightnessOffset = (u_scanline_bright_offset.x * u_scanline_alpha.x); - float BrightnessScale = (u_scanline_bright_scale.x * u_scanline_alpha.x) + (1.0 - u_scanline_alpha.x); - - float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b; - - float ScanCoord = BaseCoord.y; - ScanCoord += u_swap_xy.x > 0.0 - ? u_quad_dims.x <= u_source_dims.x * 2.0 - ? 0.5 / u_quad_dims.x // uncenter scanlines if the quad is less than twice the size of the source - : 0.0 - : u_quad_dims.y <= u_source_dims.y * 2.0 - ? 0.5 / u_quad_dims.y // uncenter scanlines if the quad is less than twice the size of the source - : 0.0; - - ScanCoord *= u_source_dims.y * u_scanline_scale.x * 3.1415927; // PI - - float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.5707963; // half PI - float ScanSine = sin(ScanCoord + ScanCoordJitter); - float ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness); - float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineWide); - float ScanBrightness = ScanSineScaled * BrightnessScale + BrightnessOffset * BrightnessScale; - - BaseColor.rgb *= mix(vec3(1.0, 1.0, 1.0), vec3(ScanBrightness, ScanBrightness, ScanBrightness), u_scanline_alpha.xxx); - } - // Hum Bar Simulation if (u_humbar_alpha.x > 0.0f) { diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_scanline.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_scanline.sc new file mode 100644 index 00000000000..5942c75bab6 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_scanline.sc @@ -0,0 +1,101 @@ +$input v_color0, v_texcoord0 + +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz,ImJezze +//----------------------------------------------------------------------------- +// Scanline Effect +//----------------------------------------------------------------------------- + +#include "common.sh" + +// Autos +uniform vec4 u_swap_xy; +uniform vec4 u_source_dims; // size of the guest machine +uniform vec4 u_target_dims; +uniform vec4 u_quad_dims; +uniform vec4 u_screen_scale; +uniform vec4 u_screen_offset; + +// User-supplied +uniform vec4 u_scanline_alpha; +uniform vec4 u_scanline_scale; +uniform vec4 u_scanline_bright_scale; +uniform vec4 u_scanline_bright_offset; +uniform vec4 u_scanline_jitter; +uniform vec4 u_scanline_height; +uniform vec4 u_scanline_variation; + +// Parametric +uniform vec4 u_time; // milliseconds +uniform vec4 u_jitter_amount; + +// Samplers +SAMPLER2D(s_tex, 0); +SAMPLER2D(s_shadow, 1); + +//----------------------------------------------------------------------------- +// Scanline Pixel Shader +//----------------------------------------------------------------------------- + +vec2 GetAdjustedCoords(vec2 coord) +{ + // center coordinates + coord -= 0.5; + + // apply screen scale + coord *= u_screen_scale.xy; + + // un-center coordinates + coord += 0.5; + + // apply screen offset + coord += u_screen_offset.xy; + + return coord; +} + +void main() +{ + vec2 BaseCoord = GetAdjustedCoords(v_texcoord0); + + // Color + vec4 BaseColor = texture2D(s_tex, BaseCoord); + + // Clamp + if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 || BaseCoord.x > 1.0 || BaseCoord.y > 1.0) + { + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + } + else + { + // Scanline Simulation + if (u_scanline_alpha.x > 0.0f) + { + float BrightnessOffset = (u_scanline_bright_offset.x * u_scanline_alpha.x); + float BrightnessScale = (u_scanline_bright_scale.x * u_scanline_alpha.x) + (1.0 - u_scanline_alpha.x); + + float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b; + + float ScanCoord = BaseCoord.y; + ScanCoord += u_swap_xy.x > 0.0 + ? u_quad_dims.x <= u_source_dims.x * 2.0 + ? 0.5 / u_quad_dims.x // uncenter scanlines if the quad is less than twice the size of the source + : 0.0 + : u_quad_dims.y <= u_source_dims.y * 2.0 + ? 0.5 / u_quad_dims.y // uncenter scanlines if the quad is less than twice the size of the source + : 0.0; + + ScanCoord *= u_source_dims.y * u_scanline_scale.x * 3.1415927; // PI + + float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.5707963; // half PI + float ScanSine = sin(ScanCoord + ScanCoordJitter); + float ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness); + float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineWide); + float ScanBrightness = ScanSineScaled * BrightnessScale + BrightnessOffset * BrightnessScale; + + BaseColor.rgb *= mix(vec3(1.0, 1.0, 1.0), vec3(ScanBrightness, ScanBrightness, ScanBrightness), u_scanline_alpha.xxx); + } + + gl_FragColor = vec4(BaseColor.rgb * v_color0.rgb, BaseColor.a); + } +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_scanline.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_scanline.sc new file mode 100644 index 00000000000..405ef8feb3b --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_scanline.sc @@ -0,0 +1,14 @@ +$input a_position, a_texcoord0, a_color0 +$output v_texcoord0, v_color0 + +// license:BSD-3-Clause +// copyright-holders:Dario Manesku + +#include "common.sh" + +void main() +{ + gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0)); + v_texcoord0 = a_texcoord0; + v_color0 = a_color0; +} diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 54f52625b6d..df5e2febea2 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -161,15 +161,46 @@ private: //============================================================ shaders::shaders() : - d3dintf(nullptr), machine(nullptr), d3d(nullptr), post_fx_enable(false), oversampling_enable(false), - num_screens(0), curr_screen(0), acc_t(0), delta_t(0), shadow_texture(nullptr), options(nullptr), - black_surface(nullptr), black_texture(nullptr), recording_movie(false), render_snap(false), - snap_copy_target(nullptr), snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr), - snap_width(0), snap_height(0), initialized(false), backbuffer(nullptr), curr_effect(nullptr), - default_effect(nullptr), prescale_effect(nullptr), post_effect(nullptr), distortion_effect(nullptr), - focus_effect(nullptr), phosphor_effect(nullptr), deconverge_effect(nullptr), color_effect(nullptr), - ntsc_effect(nullptr), bloom_effect(nullptr), downsample_effect(nullptr), vector_effect(nullptr), - curr_texture(nullptr), curr_render_target(nullptr), curr_poly(nullptr), + d3dintf(nullptr), + machine(nullptr), + d3d(nullptr), + post_fx_enable(false), + oversampling_enable(false), + num_screens(0), + curr_screen(0), + acc_t(0), + delta_t(0), + shadow_texture(nullptr), + options(nullptr), + black_surface(nullptr), + black_texture(nullptr), + recording_movie(false), + render_snap(false), + snap_copy_target(nullptr), + snap_copy_texture(nullptr), + snap_target(nullptr), + snap_texture(nullptr), + snap_width(0), + snap_height(0), + initialized(false), + backbuffer(nullptr), + curr_effect(nullptr), + default_effect(nullptr), + prescale_effect(nullptr), + post_effect(nullptr), + distortion_effect(nullptr), + scanline_effect(nullptr), + focus_effect(nullptr), + phosphor_effect(nullptr), + deconverge_effect(nullptr), + color_effect(nullptr), + ntsc_effect(nullptr), + bloom_effect(nullptr), + downsample_effect(nullptr), + vector_effect(nullptr), + curr_texture(nullptr), + curr_render_target(nullptr), + curr_poly(nullptr), d3dx_create_effect_from_file_ptr(nullptr) { } @@ -705,6 +736,7 @@ int shaders::create_resources() prescale_effect = new effect(this, d3d->get_device(), "prescale.fx", fx_dir); phosphor_effect = new effect(this, d3d->get_device(), "phosphor.fx", fx_dir); focus_effect = new effect(this, d3d->get_device(), "focus.fx", fx_dir); + scanline_effect = new effect(this, d3d->get_device(), "scanline.fx", fx_dir); deconverge_effect = new effect(this, d3d->get_device(), "deconverge.fx", fx_dir); color_effect = new effect(this, d3d->get_device(), "color.fx", fx_dir); ntsc_effect = new effect(this, d3d->get_device(), "ntsc.fx", fx_dir); @@ -718,6 +750,7 @@ int shaders::create_resources() !prescale_effect->is_valid() || !phosphor_effect->is_valid() || !focus_effect->is_valid() || + !scanline_effect->is_valid() || !deconverge_effect->is_valid() || !color_effect->is_valid() || !ntsc_effect->is_valid() || @@ -728,13 +761,16 @@ int shaders::create_resources() return 1; } - effect *effects[13] = { + const int EFFECT_COUNT = 14; + + effect *effects[EFFECT_COUNT] = { default_effect, post_effect, distortion_effect, prescale_effect, phosphor_effect, focus_effect, + scanline_effect, deconverge_effect, color_effect, ntsc_effect, @@ -779,21 +815,22 @@ int shaders::create_resources() 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); + scanline_effect->add_uniform("ScanlineAlpha", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_ALPHA); + scanline_effect->add_uniform("ScanlineScale", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_SCALE); + scanline_effect->add_uniform("ScanlineHeight", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_HEIGHT); + scanline_effect->add_uniform("ScanlineVariation", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_VARIATION); + scanline_effect->add_uniform("ScanlineBrightScale", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_SCALE); + scanline_effect->add_uniform("ScanlineBrightOffset", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_OFFSET); + focus_effect->add_uniform("Defocus", uniform::UT_VEC2, uniform::CU_FOCUS_SIZE); phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE); - post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA); + post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA); post_effect->add_uniform("ShadowCount", uniform::UT_VEC2, uniform::CU_POST_SHADOW_COUNT); post_effect->add_uniform("ShadowUV", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV); post_effect->add_uniform("ShadowUVOffset", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV_OFFSET); - post_effect->add_uniform("ShadowDims", uniform::UT_VEC2, uniform::CU_POST_SHADOW_DIMS); - post_effect->add_uniform("ScanlineAlpha", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_ALPHA); - post_effect->add_uniform("ScanlineScale", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_SCALE); - post_effect->add_uniform("ScanlineHeight", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_HEIGHT); - post_effect->add_uniform("ScanlineVariation", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_VARIATION); - post_effect->add_uniform("ScanlineBrightScale", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_SCALE); - post_effect->add_uniform("ScanlineBrightOffset", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_OFFSET); + post_effect->add_uniform("ShadowDims", uniform::UT_VEC2, uniform::CU_POST_SHADOW_DIMS); post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER); post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR); @@ -835,6 +872,7 @@ void shaders::begin_draw() prescale_effect->set_technique("DefaultTechnique"); phosphor_effect->set_technique("DefaultTechnique"); focus_effect->set_technique("DefaultTechnique"); + scanline_effect->set_technique("DefaultTechnique"); deconverge_effect->set_technique("DefaultTechnique"); color_effect->set_technique("DefaultTechnique"); ntsc_effect->set_technique("DefaultTechnique"); @@ -1040,6 +1078,38 @@ int shaders::deconverge_pass(d3d_render_target *rt, int source_index, poly_info return next_index; } +int shaders::scanline_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum) +{ + int next_index = source_index; + + // skip scanline if alpha is 0 + if (options->scanline_alpha == 0.0f) + return next_index; + + auto win = d3d->assert_window(); + screen_device_iterator screen_iterator(machine->root_device()); + screen_device *screen = screen_iterator.byindex(curr_screen); + render_container &screen_container = screen->container(); + float xscale = 1.0f / screen_container.xscale(); + float yscale = 1.0f / screen_container.yscale(); + float xoffset = -screen_container.xoffset(); + float yoffset = -screen_container.yoffset(); + float screen_scale[] = { xscale, yscale }; + float screen_offset[] = { xoffset, yoffset }; + + curr_effect = scanline_effect; + curr_effect->update_uniforms(); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); + curr_effect->set_vector("ScreenScale", 2, screen_scale); + curr_effect->set_vector("ScreenOffset", 2, screen_offset); + curr_effect->set_float("ScanlineOffset", + curr_texture->get_cur_frame() == 0 ? + 0.0f : options->scanline_jitter); + next_index = rt->next_index(next_index); + blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2); + return next_index; +} + int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum) { int next_index = source_index; @@ -1353,10 +1423,11 @@ void shaders::render_quad(poly_info *poly, int vertnum) int next_index = 0; - next_index = ntsc_pass(rt, next_index, poly, vertnum); // handled in bgfx - 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 = ntsc_pass(rt, next_index, poly, vertnum); + next_index = color_convolution_pass(rt, next_index, poly, vertnum); + next_index = prescale_pass(rt, next_index, poly, vertnum); + next_index = deconverge_pass(rt, next_index, poly, vertnum); + next_index = scanline_pass(rt, next_index, poly, vertnum); next_index = defocus_pass(rt, next_index, poly, vertnum); next_index = phosphor_pass(rt, next_index, poly, vertnum); @@ -1735,6 +1806,11 @@ void shaders::delete_resources() delete focus_effect; focus_effect = nullptr; } + if (scanline_effect != nullptr) + { + delete scanline_effect; + scanline_effect = nullptr; + } if (deconverge_effect != nullptr) { delete deconverge_effect; diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index ff4c7527a52..eae92ee5b3d 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -332,6 +332,7 @@ private: int color_convolution_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int prescale_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int deconverge_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); + int scanline_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int defocus_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int phosphor_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int post_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum, bool prepare_bloom); @@ -381,6 +382,7 @@ private: effect * prescale_effect; // pointer to the prescale-effect object effect * post_effect; // pointer to the post-effect object effect * distortion_effect; // pointer to the distortion-effect object + effect * scanline_effect; effect * focus_effect; // pointer to the focus-effect object effect * phosphor_effect; // pointer to the phosphor-effect object effect * deconverge_effect; // pointer to the deconvergence-effect object |