summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author therealmogminer@gmail.com <therealmogminer@gmail.com>2016-03-15 05:17:38 +0100
committer therealmogminer@gmail.com <therealmogminer@gmail.com>2016-03-15 05:17:38 +0100
commitb212e5dc2ef472f3ac449377fd00c6b7b824de85 (patch)
treeb204e93d83ca3a362d57c302e00621916c8a10fd /src
parent9c33c40b824b7db5a484d1c2633ecadbd6d48a03 (diff)
Add most of the rest of the D3D HLSL chain, nw
Diffstat (limited to 'src')
-rw-r--r--src/osd/modules/lib/osdobj_common.cpp7
-rw-r--r--src/osd/modules/lib/osdobj_common.h2
-rw-r--r--src/osd/modules/osdwindow.h1
-rw-r--r--src/osd/modules/render/bgfx/chain.cpp28
-rw-r--r--src/osd/modules/render/bgfx/chain.h1
-rw-r--r--src/osd/modules/render/bgfx/chainentry.cpp29
-rw-r--r--src/osd/modules/render/bgfx/chainentryreader.cpp19
-rw-r--r--src/osd/modules/render/bgfx/chainentryreader.h3
-rw-r--r--src/osd/modules/render/bgfx/chainmanager.cpp2
-rw-r--r--src/osd/modules/render/bgfx/chainreader.cpp6
-rw-r--r--src/osd/modules/render/bgfx/chainreader.h2
-rw-r--r--src/osd/modules/render/bgfx/frameparameter.cpp3
-rw-r--r--src/osd/modules/render/bgfx/frameparameter.h3
-rw-r--r--src/osd/modules/render/bgfx/fs_defocus.sc52
-rw-r--r--src/osd/modules/render/bgfx/fs_distortion.sc239
-rw-r--r--src/osd/modules/render/bgfx/fs_ntsc_decode.sc20
-rw-r--r--src/osd/modules/render/bgfx/fs_ntsc_encode.sc14
-rw-r--r--src/osd/modules/render/bgfx/fs_phosphor.sc10
-rw-r--r--src/osd/modules/render/bgfx/fs_post.sc156
-rw-r--r--src/osd/modules/render/bgfx/inputpair.cpp10
-rw-r--r--src/osd/modules/render/bgfx/inputpair.h2
-rw-r--r--src/osd/modules/render/bgfx/parameter.h5
-rw-r--r--src/osd/modules/render/bgfx/paramreader.cpp29
-rw-r--r--src/osd/modules/render/bgfx/paramreader.h2
-rw-r--r--src/osd/modules/render/bgfx/sliderreader.cpp17
-rw-r--r--src/osd/modules/render/bgfx/sliderreader.h2
-rw-r--r--src/osd/modules/render/bgfx/timeparameter.cpp33
-rw-r--r--src/osd/modules/render/bgfx/timeparameter.h34
-rw-r--r--src/osd/modules/render/bgfx/vs_deconverge.sc8
-rw-r--r--src/osd/modules/render/bgfx/vs_defocus.sc14
-rw-r--r--src/osd/modules/render/bgfx/vs_distortion.sc14
-rw-r--r--src/osd/modules/render/bgfx/vs_post.sc19
-rw-r--r--src/osd/modules/render/bgfx/windowparameter.h2
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.cpp9
-rw-r--r--src/osd/modules/render/drawbgfx.cpp1
-rw-r--r--src/osd/modules/render/drawbgfx.h7
-rw-r--r--src/osd/windows/window.cpp16
-rw-r--r--src/osd/windows/winmain.h2
38 files changed, 727 insertions, 96 deletions
diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp
index 8a0d0f86107..b8dddb8b9fa 100644
--- a/src/osd/modules/lib/osdobj_common.cpp
+++ b/src/osd/modules/lib/osdobj_common.cpp
@@ -141,9 +141,10 @@ const options_entry osd_options::s_option_entries[] =
{ OSDOPTION_AUDIO_EFFECT "9", OSDOPTVAL_NONE, OPTION_STRING, "AudioUnit effect 9" },
#endif
- { nullptr, nullptr, OPTION_HEADER, "BGFX POST-PROCESSING OPTIONS" },
- { OSDOPTION_BGFX_PATH, "bgfx", OPTION_STRING, "path to BGFX-related files" },
- { OSDOPTION_BGFX_SCREEN_CHAIN, "hlsl", OPTION_STRING, "screen chain JSON file to use" },
+ { nullptr, nullptr, OPTION_HEADER, "BGFX POST-PROCESSING OPTIONS" },
+ { OSDOPTION_BGFX_PATH, "bgfx", OPTION_STRING, "path to BGFX-related files" },
+ { OSDOPTION_BGFX_SCREEN_CHAIN, "hlsl", OPTION_STRING, "screen chain JSON file to use" },
+ { OSDOPTION_BGFX_SHADOW_MASK, "shadow-mask.png", OPTION_STRING, "shadow mask texture name" },
// End of list
{ nullptr }
diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h
index 652ae8d6cfc..573a658afa1 100644
--- a/src/osd/modules/lib/osdobj_common.h
+++ b/src/osd/modules/lib/osdobj_common.h
@@ -80,6 +80,7 @@
#define OSDOPTION_BGFX_PATH "bgfx_path"
#define OSDOPTION_BGFX_SCREEN_CHAIN "screen_chain"
+#define OSDOPTION_BGFX_SHADOW_MASK "bgfx_shadow_mask"
//============================================================
// TYPE DEFINITIONS
@@ -153,6 +154,7 @@ public:
// BGFX specific options
const char *bgfx_path() const { return value(OSDOPTION_BGFX_PATH); }
const char *bgfx_screen_chain() const { return value(OSDOPTION_BGFX_SCREEN_CHAIN); }
+ const char *bgfx_shadow_mask() const { return value(OSDOPTION_BGFX_SHADOW_MASK); }
private:
static const options_entry s_option_entries[];
diff --git a/src/osd/modules/osdwindow.h b/src/osd/modules/osdwindow.h
index 6081d47c010..3d46a273569 100644
--- a/src/osd/modules/osdwindow.h
+++ b/src/osd/modules/osdwindow.h
@@ -235,6 +235,7 @@ public:
virtual void record() { };
virtual void toggle_fsfx() { };
virtual bool sliders_dirty() { return m_sliders_dirty; }
+ virtual bool multi_window_sliders() { return false; }
static osd_renderer* make_for_type(int mode, osd_window *window, int extra_flags = FLAG_NONE);
diff --git a/src/osd/modules/render/bgfx/chain.cpp b/src/osd/modules/render/bgfx/chain.cpp
index 4534dbbf9f9..721ee9147aa 100644
--- a/src/osd/modules/render/bgfx/chain.cpp
+++ b/src/osd/modules/render/bgfx/chain.cpp
@@ -8,6 +8,8 @@
#include "emu.h"
+#include <bx/timer.h>
+
#include "slider.h"
#include "parameter.h"
#include "entryuniform.h"
@@ -23,6 +25,7 @@ bgfx_chain::bgfx_chain(std::string name, std::string author, std::vector<bgfx_sl
, m_params(params)
, m_entries(entries)
, m_output(output)
+ , m_current_time(0)
{
for (bgfx_slider* slider : m_sliders)
{
@@ -49,22 +52,35 @@ bgfx_chain::~bgfx_chain()
void bgfx_chain::process(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend)
{
int current_view = view;
- for (int index = 0; index < m_entries.size(); index++)
+ for (bgfx_chain_entry* entry : m_entries)
{
- if (!m_entries[index]->skip())
+ if (!entry->skip())
{
- m_entries[index]->submit(prim, current_view, textures, screen_width, screen_height, blend);
+ entry->submit(prim, current_view, textures, screen_width, screen_height, blend);
current_view++;
}
}
+
+ m_current_time = bx::getHPCounter();
+ static int64_t last = m_current_time;
+ const int64_t frameTime = m_current_time - last;
+ last = m_current_time;
+ const double freq = double(bx::getHPFrequency());
+ const double toMs = 1000.0 / freq;
+ const double frameTimeInSeconds = (double)frameTime / 1000000.0;
+
+ for (bgfx_parameter* param : m_params)
+ {
+ param->tick(frameTimeInSeconds* toMs);
+ }
}
uint32_t bgfx_chain::applicable_passes()
{
int applicable_passes = 0;
- for (int index = 0; index < m_entries.size(); index++)
- {
- if (!m_entries[index]->skip())
+ for (bgfx_chain_entry* entry : m_entries)
+ {
+ if (!entry->skip())
{
applicable_passes++;
}
diff --git a/src/osd/modules/render/bgfx/chain.h b/src/osd/modules/render/bgfx/chain.h
index aa5187e3a74..6eb4db71f4c 100644
--- a/src/osd/modules/render/bgfx/chain.h
+++ b/src/osd/modules/render/bgfx/chain.h
@@ -43,6 +43,7 @@ private:
std::vector<bgfx_chain_entry*> m_entries;
std::map<std::string, bgfx_slider*> m_slider_map;
std::string m_output;
+ int64_t m_current_time;
};
#endif // __DRAWBGFX_CHAIN__
diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp
index 9b7d1674fb6..ceec50f2706 100644
--- a/src/osd/modules/render/bgfx/chainentry.cpp
+++ b/src/osd/modules/render/bgfx/chainentry.cpp
@@ -58,8 +58,9 @@ void bgfx_chain_entry::submit(render_primitive* prim, int view, texture_manager&
put_screen_buffer(prim, &buffer);
bgfx::setVertexBuffer(&buffer);
- bgfx_uniform* screen_rect = m_effect->uniform("u_screenrect");
- if (screen_rect != nullptr)
+ bgfx_uniform* inv_screen_dims = m_effect->uniform("u_inv_screen_dims");
+ bgfx_uniform* screen_dims = m_effect->uniform("u_screen_dims");
+ if (screen_dims != nullptr || inv_screen_dims != nullptr)
{
float values[2];
float width = screen_width;
@@ -69,9 +70,18 @@ void bgfx_chain_entry::submit(render_primitive* prim, int view, texture_manager&
width = float(textures.provider(m_inputs[0].texture())->width());
height = float(textures.provider(m_inputs[0].texture())->height());
}
+
values[0] = 1.0f / width;
values[1] = 1.0f / height;
- screen_rect->set(values, sizeof(float) * 2);
+ if (inv_screen_dims != nullptr) {
+ inv_screen_dims->set(values, sizeof(float) * 2);
+ }
+
+ values[0] = width;
+ values[1] = height;
+ if (screen_dims != nullptr) {
+ screen_dims->set(values, sizeof(float) * 2);
+ }
}
bgfx_uniform* quad_dims = m_effect->uniform("u_quad_dims");
@@ -83,13 +93,16 @@ void bgfx_chain_entry::submit(render_primitive* prim, int view, texture_manager&
quad_dims->set(values, sizeof(float) * 2);
}
- bgfx_uniform* guest_dims = m_effect->uniform("u_guest_dims");
- if (guest_dims != nullptr)
+ bgfx_uniform* source_dims = m_effect->uniform("u_source_dims");
+ if (source_dims != nullptr)
{
float values[2];
- values[0] = 1.0f / float(prim->texture.width);
- values[1] = 1.0f / float(prim->texture.height);
- guest_dims->set(values, sizeof(float) * 2);
+ values[0] = float(prim->texture.width);
+ values[1] = float(prim->texture.height);
+ if (source_dims != nullptr)
+ {
+ source_dims->set(values, sizeof(float) * 2);
+ }
}
for (bgfx_entry_uniform* uniform : m_uniforms)
{
diff --git a/src/osd/modules/render/bgfx/chainentryreader.cpp b/src/osd/modules/render/bgfx/chainentryreader.cpp
index 5e4c9b2de9d..ce056b01900 100644
--- a/src/osd/modules/render/bgfx/chainentryreader.cpp
+++ b/src/osd/modules/render/bgfx/chainentryreader.cpp
@@ -9,6 +9,9 @@
#include <string>
#include "emu.h"
+#include "rendutil.h"
+
+#include <modules/lib/osdobj_common.h>
#include "chainentryreader.h"
@@ -23,7 +26,7 @@
#include "suppressor.h"
#include "suppressorreader.h"
-bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
+bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
{
validate_parameters(value);
@@ -64,6 +67,20 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, textur
}
}
+ if (value.HasMember("textures"))
+ {
+ assert(value["textures"].IsArray());
+ const Value& texture_array = value["textures"];
+ for (UINT32 i = 0; i < texture_array.Size(); i++)
+ {
+ char texture_name[2048];
+ bitmap_argb32 bitmap;
+ emu_file file(options.bgfx_shadow_mask(), OPEN_FLAG_READ);
+ strcpy(texture_name, options.bgfx_shadow_mask());
+ render_load_png(bitmap, file, nullptr, texture_name);
+ }
+ }
+
std::string output_name = value["output"].GetString();
if (output_name != std::string("backbuffer"))
{
diff --git a/src/osd/modules/render/bgfx/chainentryreader.h b/src/osd/modules/render/bgfx/chainentryreader.h
index bb2501bf039..caf35f2e6bc 100644
--- a/src/osd/modules/render/bgfx/chainentryreader.h
+++ b/src/osd/modules/render/bgfx/chainentryreader.h
@@ -15,6 +15,7 @@
#include "statereader.h"
+class osd_options;
class bgfx_chain_entry;
class texture_manager;
class target_manager;
@@ -25,7 +26,7 @@ class bgfx_parameter;
class chain_entry_reader : public state_reader
{
public:
- static bgfx_chain_entry* read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
+ static bgfx_chain_entry* read_from_value(const Value& value, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
private:
static void validate_parameters(const Value& value);
diff --git a/src/osd/modules/render/bgfx/chainmanager.cpp b/src/osd/modules/render/bgfx/chainmanager.cpp
index cea272c0049..f8053e83e77 100644
--- a/src/osd/modules/render/bgfx/chainmanager.cpp
+++ b/src/osd/modules/render/bgfx/chainmanager.cpp
@@ -58,7 +58,7 @@ bgfx_chain* chain_manager::load_chain(std::string name, running_machine& machine
Document document;
document.Parse<0>(data);
- bgfx_chain* chain = chain_reader::read_from_value(document, machine, window_index, m_textures, m_targets, m_effects, m_width, m_height);
+ bgfx_chain* chain = chain_reader::read_from_value(document, m_options, machine, window_index, m_textures, m_targets, m_effects, m_width, m_height);
m_chains[name + std::to_string(window_index)] = chain;
diff --git a/src/osd/modules/render/bgfx/chainreader.cpp b/src/osd/modules/render/bgfx/chainreader.cpp
index 84868e19237..d3632174516 100644
--- a/src/osd/modules/render/bgfx/chainreader.cpp
+++ b/src/osd/modules/render/bgfx/chainreader.cpp
@@ -28,7 +28,7 @@ const chain_reader::string_to_enum chain_reader::STYLE_NAMES[chain_reader::STYLE
{ "custom", TARGET_STYLE_CUSTOM }
};
-bgfx_chain* chain_reader::read_from_value(const Value& value, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
+bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
{
validate_parameters(value);
@@ -42,7 +42,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, running_machine& m
const Value& slider_array = value["sliders"];
for (UINT32 i = 0; i < slider_array.Size(); i++)
{
- std::vector<bgfx_slider*> expanded_sliders = slider_reader::read_from_value(slider_array[i], machine);
+ std::vector<bgfx_slider*> expanded_sliders = slider_reader::read_from_value(slider_array[i], machine, window_index);
for (bgfx_slider* slider : expanded_sliders)
{
sliders.push_back(slider);
@@ -129,7 +129,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, running_machine& m
const Value& entry_array = value["passes"];
for (UINT32 i = 0; i < entry_array.Size(); i++)
{
- entries.push_back(chain_entry_reader::read_from_value(entry_array[i], textures, targets, effects, slider_map, param_map));
+ entries.push_back(chain_entry_reader::read_from_value(entry_array[i], options, textures, targets, effects, slider_map, param_map));
}
}
diff --git a/src/osd/modules/render/bgfx/chainreader.h b/src/osd/modules/render/bgfx/chainreader.h
index 76c696868cb..c7db0c0e07d 100644
--- a/src/osd/modules/render/bgfx/chainreader.h
+++ b/src/osd/modules/render/bgfx/chainreader.h
@@ -21,7 +21,7 @@ class effect_manager;
class chain_reader : public state_reader
{
public:
- static bgfx_chain* read_from_value(const Value& value, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
+ static bgfx_chain* read_from_value(const Value& value, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
private:
static void validate_parameters(const Value& value);
diff --git a/src/osd/modules/render/bgfx/frameparameter.cpp b/src/osd/modules/render/bgfx/frameparameter.cpp
index 9febb7ae128..a354664cfce 100644
--- a/src/osd/modules/render/bgfx/frameparameter.cpp
+++ b/src/osd/modules/render/bgfx/frameparameter.cpp
@@ -10,6 +10,7 @@
bgfx_frame_parameter::bgfx_frame_parameter(std::string name, parameter_type type, uint32_t period)
: bgfx_parameter(name, type)
+ , m_current_frame(0)
, m_period(period)
{
}
@@ -19,7 +20,7 @@ float bgfx_frame_parameter::value()
return float(m_current_frame);
}
-void bgfx_frame_parameter::tick(float /*delta*/)
+void bgfx_frame_parameter::tick(double /*delta*/)
{
m_current_frame++;
m_current_frame %= m_period;
diff --git a/src/osd/modules/render/bgfx/frameparameter.h b/src/osd/modules/render/bgfx/frameparameter.h
index f1ec9d64abc..022a6f2065b 100644
--- a/src/osd/modules/render/bgfx/frameparameter.h
+++ b/src/osd/modules/render/bgfx/frameparameter.h
@@ -1,3 +1,4 @@
+
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
@@ -24,7 +25,7 @@ public:
virtual ~bgfx_frame_parameter() { }
virtual float value() override;
- virtual void tick(float delta) override;
+ virtual void tick(double delta) override;
private:
uint32_t m_current_frame;
diff --git a/src/osd/modules/render/bgfx/fs_defocus.sc b/src/osd/modules/render/bgfx/fs_defocus.sc
new file mode 100644
index 00000000000..acd0a715557
--- /dev/null
+++ b/src/osd/modules/render/bgfx/fs_defocus.sc
@@ -0,0 +1,52 @@
+$input v_color0, v_texcoord0
+
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz,ImJezze
+//-----------------------------------------------------------------------------
+// Defocus Effect
+//-----------------------------------------------------------------------------
+
+#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
+
+uniform vec4 u_screenrect;
+
+uniform vec4 u_defocus;
+
+uniform vec4 u_swap_xy;
+uniform vec4 u_screen_dims;
+
+SAMPLER2D(DiffuseSampler, 0);
+
+//-----------------------------------------------------------------------------
+// Constants
+//-----------------------------------------------------------------------------
+
+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);
+
+ vec2 QuadRatio = vec2(1.0, (u_swap_xy.x > 0.0) ? u_screen_dims.y / u_screen_dims.x : u_screen_dims.x / u_screen_dims.y);
+
+ vec2 DefocusTexelDims = u_defocus.xy / u_screen_dims.xy;
+
+ vec4 d0 = texture2D(DiffuseSampler, v_texcoord0);
+ vec4 d1 = texture2D(DiffuseSampler, v_texcoord0 + Coord1Offset * DefocusTexelDims);
+ vec4 d2 = texture2D(DiffuseSampler, v_texcoord0 + Coord2Offset * DefocusTexelDims);
+ vec4 d3 = texture2D(DiffuseSampler, v_texcoord0 + Coord3Offset * DefocusTexelDims);
+ vec4 d4 = texture2D(DiffuseSampler, v_texcoord0 + Coord4Offset * DefocusTexelDims);
+ vec4 d5 = texture2D(DiffuseSampler, v_texcoord0 + Coord5Offset * DefocusTexelDims);
+ vec4 d6 = texture2D(DiffuseSampler, v_texcoord0 + Coord6Offset * DefocusTexelDims);
+ vec4 d7 = texture2D(DiffuseSampler, v_texcoord0 + Coord7Offset * DefocusTexelDims);
+ vec4 d8 = texture2D(DiffuseSampler, v_texcoord0 + Coord8Offset * DefocusTexelDims);
+
+ vec4 blurred = (d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8) / 9.0;
+
+ gl_FragColor = vec4(blurred.xyz, 1.0) * v_color0;
+}
diff --git a/src/osd/modules/render/bgfx/fs_distortion.sc b/src/osd/modules/render/bgfx/fs_distortion.sc
new file mode 100644
index 00000000000..3875c785e8d
--- /dev/null
+++ b/src/osd/modules/render/bgfx/fs_distortion.sc
@@ -0,0 +1,239 @@
+$input v_color0, v_texcoord0
+
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz,ImJezze
+//-----------------------------------------------------------------------------
+// Defocus Effect
+//-----------------------------------------------------------------------------
+
+#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
+
+//-----------------------------------------------------------------------------
+// Constants
+//-----------------------------------------------------------------------------
+
+SAMPLER2D(DiffuseSampler, 0);
+
+//-----------------------------------------------------------------------------
+// Uniforms
+//-----------------------------------------------------------------------------
+
+uniform vec4 u_screen_dims;
+
+uniform vec4 u_curvature;
+uniform vec4 u_round_corner;
+uniform vec4 u_smooth_border;
+uniform vec4 u_vignetting;
+uniform vec4 u_reflection;
+
+uniform vec4 u_rotation_type; // TODO
+
+#define CurvatureAmount u_curvature.x
+#define RoundCornerAmount u_round_corner.x
+#define SmoothBorderAmount u_smooth_border.x
+#define VignettingAmount u_vignetting.x
+#define ReflectionAmount u_reflection.x
+
+#define RotationType u_rotation_type.x // TODO
+
+//-----------------------------------------------------------------------------
+// Functions
+//-----------------------------------------------------------------------------
+
+// Holy fuck the number of functions...
+
+// www.stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader/
+float rand(vec2 seed)
+{
+ // irrationals for pseudo randomness
+ vec2 i = vec2(23.140692, 2.6651442); // e^pi (Gelfond constant), 2^sqrt(2) (Gelfond-Schneider constant)
+
+ return fract(cos(dot(seed, i)) * 123456.0);
+}
+
+// www.dinodini.wordpress.com/2010/04/05/normalized-tunable-sigmoid-functions/
+float normalizedSigmoid(float n, float k)
+{
+ // valid for n and k in range of -1.0 and 1.0
+ return (n - n * k) / (k - abs(n) * 2.0 * k + 1.0);
+}
+
+// www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
+float roundBox(vec2 p, vec2 b, float r)
+{
+ return length(max(abs(p) - b + r, 0.0)) - r;
+}
+
+vec2 GetRatioCorrection()
+{
+ float ScreenQuadRatio = 1.0;
+
+ return ScreenQuadRatio > 1.0f
+ ? vec2(1.0, 1.0f / ScreenQuadRatio)
+ : vec2(ScreenQuadRatio, 1.0);
+}
+
+float GetNoiseFactor(float n, float random)
+{
+ // smaller n become more noisy
+ return 1.0 + random * max(0.0, 0.25 * pow(2.7182817, -8.0 * n));
+}
+
+float GetVignetteFactor(vec2 coord, float amount)
+{
+ vec2 VignetteCoord = coord;
+
+ float VignetteLength = length(VignetteCoord);
+ float VignetteBlur = (amount * 0.75) + 0.25;
+
+ // 0.5 full screen fitting circle
+ float VignetteRadius = 1.0 - (amount * 0.25);
+ float Vignette = smoothstep(VignetteRadius, VignetteRadius - VignetteBlur, VignetteLength);
+
+ return saturate(Vignette);
+}
+
+float GetSpotAddend(vec2 coord, float amount)
+{
+ vec2 RatioCorrection = GetRatioCorrection();
+
+ // normalized screen quad ratio
+ vec2 QuadRatio = vec2(1.0, u_screen_dims.y / u_screen_dims.x);
+
+ // normalized screen quad ratio
+ // upper right quadrant
+ vec2 spotOffset = vec2(-0.25, 0.25); // 0 degrees
+ if (RotationType == 1.0)
+ spotOffset = vec2(-0.25, -0.25); // 90 degrees
+ if (RotationType == 2.0)
+ spotOffset = vec2(0.25, -0.25); // 180 degrees
+ if (RotationType == 3.0)
+ spotOffset = vec2(0.25, 0.25); // 270 degrees
+
+ vec2 SpotCoord = (coord + spotOffset * RatioCorrection) / RatioCorrection;
+
+ float SpotBlur = amount;
+
+ // 0.5 full screen fitting circle
+ float SpotRadius = amount * 0.75;
+ float Spot = smoothstep(SpotRadius, SpotRadius - SpotBlur, length(SpotCoord));
+
+ float SigmoidSpot = amount * normalizedSigmoid(Spot, 0.75);
+
+ // increase strength by 100%
+ SigmoidSpot = SigmoidSpot * 2.0;
+
+ return saturate(SigmoidSpot);
+}
+
+float GetRoundCornerFactor(vec2 coord, float radiusAmount, float smoothAmount)
+{
+ vec2 RatioCorrection = GetRatioCorrection();
+
+ // reduce smooth amount down to radius amount
+ smoothAmount = min(smoothAmount, radiusAmount);
+
+ float range = min(u_screen_dims.x, u_screen_dims.y) * 0.5;
+ float radius = range * max(radiusAmount, 0.0025);
+ float smooth_val = 1.0 / (range * max(smoothAmount, 0.0025));
+
+ // compute box
+ float box = roundBox(u_screen_dims.xy * (coord * 2.0f), u_screen_dims.xy * RatioCorrection, radius);
+
+ // apply smooth
+ box *= smooth_val;
+ box += 1.0 - pow(smooth_val * 0.5, 0.5);
+
+ float border = smoothstep(1.0, 0.0, box);
+
+ return saturate(border);
+}
+
+// www.francois-tarlier.com/blog/cubic-lens-distortion-shader/
+vec2 GetDistortedCoords(vec2 centerCoord, float amount)
+{
+ // lens distortion coefficient
+ float k = amount;
+
+ // cubic distortion value
+ float kcube = amount * 2.0;
+
+ // compute cubic distortion factor
+ float r2 = centerCoord.x * centerCoord.x + centerCoord.y * centerCoord.y;
+ float f = kcube == 0.0 ? 1.0 + r2 * k : 1.0 + r2 * (k + kcube * sqrt(r2));
+
+ // fit screen bounds
+ f /= 1.0 + amount * 0.5;
+
+ // apply cubic distortion factor
+ centerCoord *= f;
+
+ return centerCoord;
+}
+
+vec2 GetCoords(vec2 coord, float distortionAmount)
+{
+ vec2 RatioCorrection = GetRatioCorrection();
+
+ // center coordinates
+ coord -= 0.5;
+
+ // apply ratio difference between screen and quad
+ coord /= RatioCorrection;
+
+ // distort coordinates
+ coord = GetDistortedCoords(coord, distortionAmount);
+
+ // revert ratio difference between screen and quad
+ coord *= RatioCorrection;
+
+ // un-center coordinates
+ coord += 0.5;
+
+ return coord;
+}
+
+//-----------------------------------------------------------------------------
+// Distortion Pixel Shader
+//-----------------------------------------------------------------------------
+
+void main()
+{
+ // Screen Curvature
+ vec2 BaseCoord = GetCoords(v_texcoord0, CurvatureAmount * 0.25); // reduced amount
+
+ vec2 BaseCoordCentered = BaseCoord;
+ BaseCoordCentered -= 0.5;
+
+ // Color
+ vec4 BaseColor = texture2D(DiffuseSampler, BaseCoord);
+ BaseColor.a = 1.0;
+
+ // Clamp
+ if (BaseCoord.x > 1.0 || BaseCoord.y > 1.0 || BaseCoord.x < 0.0 || BaseCoord.y < 0.0)
+ BaseColor.rgb = vec3(0.0, 0.0, 0.0);
+
+ // Vignetting Simulation
+ vec2 VignetteCoord = BaseCoordCentered;
+
+ float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount);
+ BaseColor.rgb *= VignetteFactor;
+
+ // Light Reflection Simulation
+ vec3 LightColor = vec3(1.0, 0.90, 0.80); // color temperature 5.000 Kelvin
+
+ vec2 SpotCoord = BaseCoordCentered;
+ vec2 NoiseCoord = BaseCoordCentered;
+
+ float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount);
+ float NoiseFactor = GetNoiseFactor(SpotAddend, rand(NoiseCoord));
+ BaseColor.rgb += SpotAddend * NoiseFactor * LightColor;
+
+ // Round Corners Simulation
+ vec2 RoundCornerCoord = BaseCoordCentered;
+
+ float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount);
+ BaseColor.rgb *= roundCornerFactor;
+
+ gl_FragColor = BaseColor;
+}
diff --git a/src/osd/modules/render/bgfx/fs_ntsc_decode.sc b/src/osd/modules/render/bgfx/fs_ntsc_decode.sc
index 8479377817c..41807a1cf6f 100644
--- a/src/osd/modules/render/bgfx/fs_ntsc_decode.sc
+++ b/src/osd/modules/render/bgfx/fs_ntsc_decode.sc
@@ -22,8 +22,7 @@ uniform vec4 u_q_freq_response;
uniform vec4 u_jitter_amount;
uniform vec4 u_jitter_offset;
-uniform vec4 u_texsize;
-uniform vec4 u_screenrect;
+uniform vec4 u_source_dims;
SAMPLER2D(DiffuseSampler, 0);
@@ -35,16 +34,13 @@ void main()
{
vec4 BaseTexel = texture2D(DiffuseSampler, v_texcoord0.xy);
- vec2 SourceTexelDims = u_texsize.xy;
- vec2 SourceRes = (1.0 / u_texsize.xy) * u_screenrect.xy;
-
vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
vec4 quarter = vec4(0.25, 0.25, 0.25, 0.25);
vec4 onehalf = vec4(0.5, 0.5, 0.5, 0.5);
vec4 one = vec4(1.0, 1.0, 1.0, 1.0);
vec4 two = vec4(2.0, 2.0, 2.0, 2.0);
vec4 four = vec4(4.0, 4.0, 4.0, 4.0);
- vec4 TimePerSample = u_scan_time.xxxx / (SourceRes.xxxx * four);
+ vec4 TimePerSample = u_scan_time.xxxx / (u_source_dims.xxxx * four);
vec4 Fc_y1 = (u_cc_value.xxxx - u_notch_width.xxxx * onehalf) * TimePerSample;
vec4 Fc_y2 = (u_cc_value.xxxx + u_notch_width.xxxx * onehalf) * TimePerSample;
@@ -61,27 +57,23 @@ void main()
vec4 WoPI = W / PI;
vec4 HOffset = (u_b_value.xxxx + u_jitter_amount.xxxx * u_jitter_offset.xxxx) / WoPI;
- vec4 VScale = (u_a_value.xxxx * SourceRes.yyyy) / WoPI;
+ vec4 VScale = (u_a_value.xxxx * u_source_dims.yyyy) / WoPI;
vec4 YAccum = zero;
vec4 IAccum = zero;
vec4 QAccum = zero;
- vec4 Cy = v_texcoord0.yyyy;
- vec4 VPosition = vec4(Cy / u_screenrect.y);
-
for (int index = 0; index < 64; index = index + 4)
{
float n = float(index);
vec4 n4 = vec4(n, n, n, n) + vec4(0.0, 1.0, 2.0, 3.0);
- vec4 Cx = v_texcoord0.xxxx + SourceTexelDims.xxxx * (n4 * quarter);
- vec4 HPosition = Cx / u_screenrect.xxxx;
+ vec4 Cx = v_texcoord0.xxxx + u_source_dims.xxxx * (n4 * quarter);
// theory: What if we put white in the input of the NTSC decode shader?
- vec4 C = texture2D(DiffuseSampler, vec2(Cx.x, Cy.x));
+ vec4 C = texture2D(DiffuseSampler, vec2(Cx.x, v_texcoord0.y));
- vec4 T = HPosition + HOffset + VPosition * VScale;
+ vec4 T = Cx + HOffset + v_texcoord0.yyyy * VScale;
vec4 WT = W * T + u_o_value.xxxx;
vec4 SincKernel = vec4(0.54, 0.54, 0.54, 0.54) + vec4(0.46, 0.46, 0.46, 0.46) * cos((PI2 / 1.0) * n4);
diff --git a/src/osd/modules/render/bgfx/fs_ntsc_encode.sc b/src/osd/modules/render/bgfx/fs_ntsc_encode.sc
index 5812b01a8a0..2a16d225183 100644
--- a/src/osd/modules/render/bgfx/fs_ntsc_encode.sc
+++ b/src/osd/modules/render/bgfx/fs_ntsc_encode.sc
@@ -18,8 +18,7 @@ uniform vec4 u_scan_time;
uniform vec4 u_jitter_amount;
uniform vec4 u_jitter_offset;
-uniform vec4 u_texsize;
-uniform vec4 u_screenrect;
+uniform vec4 u_source_dims;
SAMPLER2D(DiffuseSampler, 0);
@@ -29,9 +28,7 @@ SAMPLER2D(DiffuseSampler, 0);
void main()
{
- vec2 SourceRes = (1.0 / u_texsize.xy) * u_screenrect.xy;
-
- vec2 PValueSourceTexel = vec2(u_p_value.x, 0.0) * u_texsize.xy;
+ vec2 PValueSourceTexel = vec2(u_p_value.x, 0.0) * u_source_dims.xy;
vec2 C0 = v_texcoord0 + PValueSourceTexel * vec2(0.0, 0.0);
vec2 C1 = v_texcoord0 + PValueSourceTexel * vec2(0.25, 0.0);
@@ -44,9 +41,6 @@ void main()
vec4 Texel2 = texture2D(DiffuseSampler, C2);
vec4 Texel3 = texture2D(DiffuseSampler, C3);
- vec4 HPosition = Cx / u_screenrect.xxxx;
- vec4 VPosition = Cy / u_screenrect.yyyy;
-
const vec4 YDot = vec4(0.299, 0.587, 0.114, 0.0);
const vec4 IDot = vec4(0.595716, -0.274453, -0.321263, 0.0);
const vec4 QDot = vec4(0.211456, -0.522591, 0.311135, 0.0);
@@ -60,9 +54,9 @@ void main()
vec4 WoPI = W / PI;
vec4 HOffset = (u_b_value.xxxx + u_jitter_amount.xxxx * u_jitter_offset.xxxx) / WoPI;
- vec4 VScale = (u_a_value.xxxx * SourceRes.yyyy) / WoPI;
+ vec4 VScale = (u_a_value.xxxx * u_source_dims.yyyy) / WoPI;
- vec4 T = HPosition + HOffset + VPosition * VScale;
+ vec4 T = Cx + HOffset + Cy * VScale;
vec4 TW = T * W;
vec4 output_rgb = Y + I * cos(TW) + Q * sin(TW);
diff --git a/src/osd/modules/render/bgfx/fs_phosphor.sc b/src/osd/modules/render/bgfx/fs_phosphor.sc
index 2df6b3f827d..90c69746822 100644
--- a/src/osd/modules/render/bgfx/fs_phosphor.sc
+++ b/src/osd/modules/render/bgfx/fs_phosphor.sc
@@ -13,8 +13,10 @@ SAMPLER2D(s_prev, 1);
void main()
{
- vec4 curr = texture2D(s_tex, v_texcoord0);
- vec4 prev = texture2D(s_prev, v_texcoord0);
- vec4 phosphored = vec4(max(curr.r, prev.r * u_phosphor.r), max(curr.g, prev.g * u_phosphor.g), max(curr.b, prev.b * u_phosphor.b), curr.a);
- gl_FragColor = mix(phosphored, curr, u_passthrough.x) * v_color0;
+ vec4 curr = texture2D(s_tex, v_texcoord0);
+ vec3 prev = texture2D(s_prev, v_texcoord0).rgb * u_phosphor.rgb;
+
+ vec3 maxed = max(curr.rgb, prev);
+
+ gl_FragColor = u_passthrough.x > 0.0 ? curr : vec4(maxed, curr.a);
}
diff --git a/src/osd/modules/render/bgfx/fs_post.sc b/src/osd/modules/render/bgfx/fs_post.sc
new file mode 100644
index 00000000000..0072ecfc525
--- /dev/null
+++ b/src/osd/modules/render/bgfx/fs_post.sc
@@ -0,0 +1,156 @@
+$input v_color0, v_texcoord0, v_texcoord1
+
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz,ImJezze
+//-----------------------------------------------------------------------------
+// Defocus Effect
+//-----------------------------------------------------------------------------
+
+#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
+
+uniform vec4 u_swap_xy;
+
+uniform vec4 u_inv_screen_dims; // size of the window or fullscreen
+uniform vec4 u_source_dims; // size of the source texture
+
+uniform vec4 u_shadow_dims; // size of the shadow texture (extended to power-of-two size - not necessarily in bgfx)
+uniform vec4 u_shadow_uv_offset;
+
+uniform vec4 u_prepare_bloom; // disables some effects for rendering bloom textures
+uniform vec4 u_prepare_vector;
+
+uniform vec4 u_humbar_hertz_rate; // 60.0f / 59.94f - 1.0f; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC)
+uniform vec4 u_humbar_alpha; // 0.0f;
+
+uniform vec4 u_time; // 0.0f;
+
+uniform vec4 u_screen_scale; // TODO: ScreenScale
+uniform vec4 u_screen_offset; // TODO: ScreenOffset
+
+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_jitter_amount;
+uniform vec4 u_scanline_height;
+
+uniform vec4 u_back_color; // TODO: Unused in current implementation, mostly
+
+uniform vec4 u_shadow_tile_mode; // ShadowTileMode = 0; // 0 based on screen dimension, 1 based on source dimension
+uniform vec4 u_shadow_alpha; // ShadowAlpha = 0.0f;
+uniform vec4 u_shadow_count; // ShadowCount = float2(6.0f, 6.0f);
+uniform vec4 u_shadow_uv; // ShadowUV = float2(0.25f, 0.25f);
+
+uniform vec4 u_power; // Power = float3(1.0f, 1.0f, 1.0f);
+uniform vec4 u_floor; // Floor = float3(0.0f, 0.0f, 0.0f);
+
+SAMPLER2D(DiffuseSampler, 0);
+SAMPLER2D(ShadowSampler, 1);
+
+//-----------------------------------------------------------------------------
+// Scanline & Shadowmask Pixel Shader
+//-----------------------------------------------------------------------------
+
+vec2 GetAdjustedCoords(vec2 coord, vec2 center_offset)
+{
+ // center coordinates
+ coord -= center_offset;
+
+ // apply screen scale
+ //coord /= u_screen_scale.xy;
+
+ // un-center coordinates
+ coord += center_offset;
+
+ // apply screen offset
+ coord += (center_offset * 2.0) * u_screen_offset.xy;
+
+ return coord;
+}
+
+void main()
+{
+ vec2 ScreenTexelDims = u_inv_screen_dims.xy;
+ vec2 SourceTexelDims = vec2(1.0, 1.0) / u_source_dims.xy;
+ vec2 SourceRes = u_source_dims.xy;
+
+ vec2 HalfSourceRect = vec2(0.5, 0.5);
+
+ vec2 ScreenCoord = v_texcoord1 / u_inv_screen_dims.xy;
+ vec2 BaseCoord = GetAdjustedCoords(v_texcoord0, HalfSourceRect);
+
+ // Color
+ vec4 BaseColor = texture2D(DiffuseSampler, BaseCoord);
+ BaseColor.a = 1.0;
+
+ if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0)
+ {
+ BaseColor.rgb = vec3(0.0, 0.0, 0.0);
+ }
+
+ // Mask Simulation (may not affect bloom)
+ if (u_prepare_bloom.x == 0.0 && u_shadow_alpha.x > 0.0)
+ {
+ vec2 shadowDims = u_swap_xy.x > 0.0 ? u_shadow_dims.yx : u_shadow_dims.xy;
+ vec2 screenCoord = u_shadow_tile_mode.x == 0.0 ? ScreenCoord : BaseCoord;
+ screenCoord = u_swap_xy.x > 0.0 ? screenCoord.yx : screenCoord.xy;
+
+ vec2 shadowCount = u_swap_xy.x > 0.0 ? u_shadow_count.yx : u_shadow_count.xy;
+ vec2 shadowTile = ((u_shadow_tile_mode.x == 0.0 ? ScreenTexelDims : SourceTexelDims) * shadowCount);
+ shadowTile = u_swap_xy.x > 0.0 ? shadowTile.yx : shadowTile.xy;
+
+ vec2 ShadowFrac = fract(screenCoord / shadowTile);
+ vec2 ShadowCoord = (ShadowFrac * u_shadow_uv.xy);
+
+ vec4 ShadowColor = texture2D(ShadowSampler, ShadowCoord);
+ vec3 ShadowMaskColor = mix(vec3(1.0, 1.0, 1.0), ShadowColor.rgb, u_shadow_alpha.xxx);
+ float ShadowMaskClear = (1.0 - ShadowColor.a) * u_shadow_alpha.x;
+
+ // apply shadow mask color
+ BaseColor.rgb *= ShadowMaskColor;
+ // clear shadow mask by background color
+ BaseColor.rgb = mix(BaseColor.rgb, u_back_color.rgb, ShadowMaskClear);
+ }
+
+ // Color Compression (may not affect bloom)
+ if (u_prepare_bloom.x == 0.0)
+ {
+ // increasing the floor of the signal without affecting the ceiling
+ BaseColor.rgb = u_floor.rgb + (vec3(1.0, 1.0, 1.0) - u_floor.rgb) * BaseColor.rgb;
+ }
+
+ // Color Power (may affect bloom)
+ BaseColor.r = pow(BaseColor.r, u_power.r);
+ BaseColor.g = pow(BaseColor.g, u_power.g);
+ BaseColor.b = pow(BaseColor.b, u_power.b);
+
+ // Scanline Simulation (may not affect bloom)
+ if (u_prepare_bloom.x == 0.0)
+ {
+ // Scanline Simulation (may not affect vector screen)
+ if (u_prepare_vector.x == 0.0 && u_scanline_alpha.x > 0.0f)
+ {
+ float ScanCoord = v_texcoord0.y * u_source_dims.y * u_scanline_scale.x * 3.1415927;
+ float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.618034;
+ float ScanSine = sin(ScanCoord + ScanCoordJitter);
+ float ScanSineScaled = pow(ScanSine * ScanSine, 1.0);//u_scanline_height.x);
+ float ScanBrightness = (ScanSineScaled * u_scanline_bright_scale.x + 1.0 + u_scanline_bright_offset.x) * 0.5;
+
+ BaseColor.rgb *= mix(vec3(1.0, 1.0, 1.0), vec3(ScanBrightness, ScanBrightness, ScanBrightness), u_scanline_alpha.xxx);
+ }
+
+ // Hum Bar Simulation (may not affect vector screen)
+ if (u_prepare_vector.x == 0.0 && u_humbar_alpha.x > 0.0f)
+ {
+ float HumTimeStep = fract(u_time.x * 0.001);
+ float HumBrightness = 1.0 - fract(BaseCoord.y + HumTimeStep) * u_humbar_alpha.x;
+ BaseColor.rgb *= HumBrightness;
+ }
+ }
+
+ vec4 Output = u_prepare_vector.x > 0.0 ? BaseColor * (v_color0 + vec4(1.0, 1.0, 1.0, 0.0)) : BaseColor * v_color0;
+ Output.a = 1.0;
+
+ gl_FragColor = Output;
+}
diff --git a/src/osd/modules/render/bgfx/inputpair.cpp b/src/osd/modules/render/bgfx/inputpair.cpp
index 5f5dc80221d..38845a67ea5 100644
--- a/src/osd/modules/render/bgfx/inputpair.cpp
+++ b/src/osd/modules/render/bgfx/inputpair.cpp
@@ -23,15 +23,7 @@ bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string tex
{
}
-void bgfx_input_pair::bind(bgfx_effect *effect, texture_manager& textures)
+void bgfx_input_pair::bind(bgfx_effect *effect, texture_manager& textures) const
{
bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), textures.handle(m_texture));
- bgfx_uniform *size_uniform = effect->uniform("u_texsize");
- if (size_uniform != nullptr)
- {
- float width = float(textures.provider(m_texture)->width());
- float height = float(textures.provider(m_texture)->height());
- float size[4] = { 1.0f / width, 1.0f / height, 0.0f, 0.0f };
- size_uniform->set(reinterpret_cast<void *>(size), sizeof(float) * 4);
- }
}
diff --git a/src/osd/modules/render/bgfx/inputpair.h b/src/osd/modules/render/bgfx/inputpair.h
index f03dfe8200d..53a249c9693 100644
--- a/src/osd/modules/render/bgfx/inputpair.h
+++ b/src/osd/modules/render/bgfx/inputpair.h
@@ -24,7 +24,7 @@ class bgfx_input_pair
public:
bgfx_input_pair(int index, std::string sampler, std::string texture);
- void bind(bgfx_effect *effect, texture_manager& textures);
+ void bind(bgfx_effect *effect, texture_manager& textures) const;
// Getters
std::string sampler() const { return m_sampler; }
diff --git a/src/osd/modules/render/bgfx/parameter.h b/src/osd/modules/render/bgfx/parameter.h
index 4cfbc5880c8..6a74efd887c 100644
--- a/src/osd/modules/render/bgfx/parameter.h
+++ b/src/osd/modules/render/bgfx/parameter.h
@@ -23,13 +23,14 @@ public:
enum parameter_type
{
PARAM_FRAME,
- PARAM_WINDOW
+ PARAM_WINDOW,
+ PARAM_TIME
};
bgfx_parameter(std::string name, parameter_type type) : m_name(name), m_type(type) { }
virtual ~bgfx_parameter() { }
- virtual void tick(float delta) = 0;
+ virtual void tick(double delta) = 0;
// Getters
virtual float value() = 0;
diff --git a/src/osd/modules/render/bgfx/paramreader.cpp b/src/osd/modules/render/bgfx/paramreader.cpp
index c10d447c190..040730e2c4b 100644
--- a/src/osd/modules/render/bgfx/paramreader.cpp
+++ b/src/osd/modules/render/bgfx/paramreader.cpp
@@ -13,10 +13,12 @@
#include "parameter.h"
#include "frameparameter.h"
#include "windowparameter.h"
+#include "timeparameter.h"
const parameter_reader::string_to_enum parameter_reader::TYPE_NAMES[parameter_reader::TYPE_COUNT] = {
{ "frame", bgfx_parameter::parameter_type::PARAM_FRAME },
- { "window", bgfx_parameter::parameter_type::PARAM_WINDOW }
+ { "window", bgfx_parameter::parameter_type::PARAM_WINDOW },
+ { "time", bgfx_parameter::parameter_type::PARAM_TIME }
};
bgfx_parameter* parameter_reader::read_from_value(const Value& value, uint32_t window_index)
@@ -31,11 +33,16 @@ bgfx_parameter* parameter_reader::read_from_value(const Value& value, uint32_t w
uint32_t period = int(value["period"].GetDouble());
return new bgfx_frame_parameter(name, type, period);
}
- else if (type == bgfx_parameter::parameter_type::PARAM_WINDOW)
- {
- return new bgfx_window_parameter(name, type, window_index);
- }
- else
+ else if (type == bgfx_parameter::parameter_type::PARAM_WINDOW)
+ {
+ return new bgfx_window_parameter(name, type, window_index);
+ }
+ else if (type == bgfx_parameter::parameter_type::PARAM_TIME)
+ {
+ float limit = float(value["limit"].GetDouble());
+ return new bgfx_time_parameter(name, type, limit);
+ }
+ else
{
assert(false);
}
@@ -49,6 +56,12 @@ void parameter_reader::validate_parameters(const Value& value)
assert(value["name"].IsString());
assert(value.HasMember("type"));
assert(value["type"].IsString());
- assert(value.HasMember("period"));
- assert(value["period"].IsNumber());
+ if (value.HasMember("period"))
+ {
+ assert(value["period"].IsNumber());
+ }
+ if (value.HasMember("limit"))
+ {
+ assert(value["limit"].IsNumber());
+ }
}
diff --git a/src/osd/modules/render/bgfx/paramreader.h b/src/osd/modules/render/bgfx/paramreader.h
index 14ab9cecf02..bcdacd089e0 100644
--- a/src/osd/modules/render/bgfx/paramreader.h
+++ b/src/osd/modules/render/bgfx/paramreader.h
@@ -23,7 +23,7 @@ public:
private:
static void validate_parameters(const Value& value);
- static const int TYPE_COUNT = 2;
+ static const int TYPE_COUNT = 3;
static const string_to_enum TYPE_NAMES[TYPE_COUNT];
};
diff --git a/src/osd/modules/render/bgfx/sliderreader.cpp b/src/osd/modules/render/bgfx/sliderreader.cpp
index dd59f308220..261961445ab 100644
--- a/src/osd/modules/render/bgfx/sliderreader.cpp
+++ b/src/osd/modules/render/bgfx/sliderreader.cpp
@@ -33,7 +33,7 @@ const slider_reader::string_to_enum slider_reader::SCREEN_NAMES[slider_reader::S
{ "all", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_ANY) }
};
-std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, running_machine& machine)
+std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, running_machine& machine, uint32_t window_index)
{
validate_parameters(value);
@@ -86,21 +86,20 @@ std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, run
for (int index = 0; index < slider_count; index++)
{
std::string desc;
- char full_name[1024]; // arbitrary
- snprintf(full_name, 1024, "%s%d", name.c_str(), index);
+ std::string full_name = name + std::to_string(index);
switch (index)
{
case 0:
- desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "X" : "Red");
+ desc = "Window " + std::to_string(window_index) + ", " + description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "X" : "Red");
break;
case 1:
- desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Y" : "Green");
+ desc = "Window " + std::to_string(window_index) + ", " + description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Y" : "Green");
break;
case 2:
- desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Invalid" : "Blue");
+ desc = "Window " + std::to_string(window_index) + ", " + description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Invalid" : "Blue");
break;
default:
- desc = description + "Invalid";
+ desc = "Window " + std::to_string(window_index) + ", " + description + "Invalid";
break;
}
sliders.push_back(new bgfx_slider(machine, full_name, min[index], defaults[index], max[index], step, type, screen_type, scale, format, desc, strings));
@@ -111,7 +110,7 @@ std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, run
int min = get_int(value, "min", 0);
int def = get_int(value, "default", 0);
int max = get_int(value, "max", 100);
- sliders.push_back(new bgfx_slider(machine, name + "0", min, def, max, step, type, screen_type, scale, format, description, strings));
+ sliders.push_back(new bgfx_slider(machine, name + "0", min, def, max, step, type, screen_type, scale, format, "Window " + std::to_string(window_index) + ", " + description, strings));
}
return sliders;
}
@@ -121,7 +120,7 @@ void slider_reader::get_values(const Value& value, std::string name, int* values
const char* name_str = name.c_str();
assert(value.HasMember(name_str));
assert(value[name_str].IsArray());
-
+
const Value& value_array = value[name_str];
for (UINT32 i = 0; i < value_array.Size() && i < count; i++)
{
diff --git a/src/osd/modules/render/bgfx/sliderreader.h b/src/osd/modules/render/bgfx/sliderreader.h
index f9a9c595c0f..c2e254d1056 100644
--- a/src/osd/modules/render/bgfx/sliderreader.h
+++ b/src/osd/modules/render/bgfx/sliderreader.h
@@ -21,7 +21,7 @@ class running_machine;
class slider_reader : public state_reader
{
public:
- static std::vector<bgfx_slider*> read_from_value(const Value& value, running_machine& machine);
+ static std::vector<bgfx_slider*> read_from_value(const Value& value, running_machine& machine, uint32_t window_index);
private:
static void get_values(const Value& value, std::string name, int* values, const int count);
diff --git a/src/osd/modules/render/bgfx/timeparameter.cpp b/src/osd/modules/render/bgfx/timeparameter.cpp
new file mode 100644
index 00000000000..f1f10ce700b
--- /dev/null
+++ b/src/osd/modules/render/bgfx/timeparameter.cpp
@@ -0,0 +1,33 @@
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz
+//============================================================
+//
+// timeparameter.cpp - Time-based dynamic shader param
+//
+//============================================================
+
+#include "timeparameter.h"
+
+bgfx_time_parameter::bgfx_time_parameter(std::string name, parameter_type type, double limit)
+ : bgfx_parameter(name, type)
+ , m_current_time(0)
+ , m_limit(limit)
+{
+}
+
+float bgfx_time_parameter::value()
+{
+ return float(m_current_time * 1000.0 * 1000.0);
+}
+
+void bgfx_time_parameter::tick(double delta)
+{
+ m_current_time += delta;
+ if (m_limit != 0)
+ {
+ while (m_current_time >= m_limit)
+ {
+ m_current_time -= m_limit;
+ }
+ }
+}
diff --git a/src/osd/modules/render/bgfx/timeparameter.h b/src/osd/modules/render/bgfx/timeparameter.h
new file mode 100644
index 00000000000..6a05be4fc03
--- /dev/null
+++ b/src/osd/modules/render/bgfx/timeparameter.h
@@ -0,0 +1,34 @@
+// license:BSD-3-Clause
+// copyright-holders:Ryan Holtz
+//============================================================
+//
+// timeparameter.cpp - Time-based dynamic shader param
+//
+//============================================================
+
+#pragma once
+
+#ifndef __DRAWBGFX_TIME_PARAMETER__
+#define __DRAWBGFX_TIME_PARAMETER__
+
+#include <bgfx/bgfx.h>
+
+#include <string>
+
+#include "parameter.h"
+
+class bgfx_time_parameter : public bgfx_parameter
+{
+public:
+ bgfx_time_parameter(std::string name, parameter_type type, double limit);
+ virtual ~bgfx_time_parameter() { }
+
+ virtual float value() override;
+ virtual void tick(double delta) override;
+
+private:
+ double m_current_time;
+ double m_limit;
+};
+
+#endif // __DRAWBGFX_TIME_PARAMETER__
diff --git a/src/osd/modules/render/bgfx/vs_deconverge.sc b/src/osd/modules/render/bgfx/vs_deconverge.sc
index 60603ae8dbe..21db02c490f 100644
--- a/src/osd/modules/render/bgfx/vs_deconverge.sc
+++ b/src/osd/modules/render/bgfx/vs_deconverge.sc
@@ -19,7 +19,7 @@ uniform vec4 u_radial_converge_red;
uniform vec4 u_radial_converge_green;
uniform vec4 u_radial_converge_blue;
-uniform vec4 u_guest_dims;
+uniform vec4 u_source_dims;
void main()
{
@@ -32,9 +32,9 @@ void main()
// radial converge offset to "translate" the most outer pixel as thay would be translated by the linar converge with the same amount
vec2 radialConvergeOffset = 2.0 * u_screenrect.xy;
- v_texcoord0 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_red.xy * radialConvergeOffset) + HalfSourceRect + u_converge_red.xy * u_guest_dims.xy;
- v_texcoord1 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_green.xy * radialConvergeOffset) + HalfSourceRect + u_converge_green.xy * u_guest_dims.xy;
- v_texcoord2 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_blue.xy * radialConvergeOffset) + HalfSourceRect + u_converge_blue.xy * u_guest_dims.xy;
+ v_texcoord0 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_red.xy * radialConvergeOffset) + HalfSourceRect + u_converge_red.xy * (vec2(1.0, 1.0) / u_source_dims.xy);
+ v_texcoord1 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_green.xy * radialConvergeOffset) + HalfSourceRect + u_converge_green.xy * (vec2(1.0, 1.0) / u_source_dims.xy);
+ v_texcoord2 = (a_texcoord0 - HalfSourceRect) * (1.0 + u_radial_converge_blue.xy * radialConvergeOffset) + HalfSourceRect + u_converge_blue.xy * (vec2(1.0, 1.0) / u_source_dims.xy);
v_color0 = a_color0;
}
diff --git a/src/osd/modules/render/bgfx/vs_defocus.sc b/src/osd/modules/render/bgfx/vs_defocus.sc
new file mode 100644
index 00000000000..c3699f6fbd9
--- /dev/null
+++ b/src/osd/modules/render/bgfx/vs_defocus.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 "../../../../../3rdparty/bgfx/examples/common/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/bgfx/vs_distortion.sc b/src/osd/modules/render/bgfx/vs_distortion.sc
new file mode 100644
index 00000000000..c3699f6fbd9
--- /dev/null
+++ b/src/osd/modules/render/bgfx/vs_distortion.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 "../../../../../3rdparty/bgfx/examples/common/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/bgfx/vs_post.sc b/src/osd/modules/render/bgfx/vs_post.sc
new file mode 100644
index 00000000000..12b4931a1ae
--- /dev/null
+++ b/src/osd/modules/render/bgfx/vs_post.sc
@@ -0,0 +1,19 @@
+$input a_position, a_texcoord0, a_color0
+$output v_texcoord0, v_texcoord1, v_color0
+
+// license:BSD-3-Clause
+// copyright-holders:Dario Manesku
+
+#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
+
+uniform vec4 u_swap_xy;
+
+uniform vec4 u_shadow_uv_offset;
+
+void main()
+{
+ gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
+ v_texcoord0 = a_texcoord0;
+ v_texcoord1 = a_position.xy + ((u_swap_xy.x != 0.0) ? u_shadow_uv_offset.yx : u_shadow_uv_offset.xy);
+ v_color0 = a_color0;
+}
diff --git a/src/osd/modules/render/bgfx/windowparameter.h b/src/osd/modules/render/bgfx/windowparameter.h
index f4763647c32..83afdb220b7 100644
--- a/src/osd/modules/render/bgfx/windowparameter.h
+++ b/src/osd/modules/render/bgfx/windowparameter.h
@@ -24,7 +24,7 @@ public:
virtual ~bgfx_window_parameter() { }
virtual float value() override { return float(m_index); }
- virtual void tick(float delta) override { };
+ virtual void tick(double delta) override { };
private:
uint32_t m_index;
diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp
index 7080800773c..133f946c3e8 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.cpp
+++ b/src/osd/modules/render/d3d/d3dhlsl.cpp
@@ -1701,10 +1701,10 @@ void shaders::render_quad(poly_info *poly, int vertnum)
int next_index = 0;
- 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 = 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 = defocus_pass(rt, next_index, poly, vertnum); // 1st pass
next_index = defocus_pass(rt, next_index, poly, vertnum); // 2nd pass
next_index = phosphor_pass(rt, ct, next_index, poly, vertnum);
@@ -2704,6 +2704,7 @@ void uniform::update()
shadersys->curr_poly->get_prim_width(),
shadersys->curr_poly->get_prim_height() };
m_shader->set_vector("QuadDims", 2, quaddims);
+ printf("Quad Dims: %f, %f\n", quaddims[0], quaddims[1]);
}
break;
}
diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp
index 76ae3dd800b..539c9ee4d14 100644
--- a/src/osd/modules/render/drawbgfx.cpp
+++ b/src/osd/modules/render/drawbgfx.cpp
@@ -55,6 +55,7 @@
const uint16_t renderer_bgfx::CACHE_SIZE = 1024;
const uint32_t renderer_bgfx::PACKABLE_SIZE = 128;
const uint32_t renderer_bgfx::WHITE_HASH = 0x87654321;
+const char* renderer_bgfx::WINDOW_PREFIX = "Window 0, ";
//============================================================
// MACROS
diff --git a/src/osd/modules/render/drawbgfx.h b/src/osd/modules/render/drawbgfx.h
index c64c189688a..999bf852923 100644
--- a/src/osd/modules/render/drawbgfx.h
+++ b/src/osd/modules/render/drawbgfx.h
@@ -39,7 +39,9 @@ public:
virtual int create() override;
virtual slider_state* get_slider_list() override;
+ virtual bool multi_window_sliders() { return true; }
virtual int draw(const int update) override;
+
#ifdef OSD_SDL
virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) override;
#else
@@ -47,13 +49,16 @@ public:
virtual void record() override { }
virtual void toggle_fsfx() override { }
#endif
- virtual render_primitive_list *get_primitives() override
+
+ virtual render_primitive_list *get_primitives() override
{
osd_dim wdim = window().get_size();
window().target()->set_bounds(wdim.width(), wdim.height(), window().aspect());
return &window().target()->get_primitives();
}
+ static const char* WINDOW_PREFIX;
+
private:
int handle_screen_chains();
diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp
index 326e8248bab..638c2eb14cb 100644
--- a/src/osd/windows/window.cpp
+++ b/src/osd/windows/window.cpp
@@ -289,13 +289,24 @@ void windows_osd_interface::update_slider_list()
}
}
+int windows_osd_interface::window_count()
+{
+ int count = 0;
+ for (win_window_info *info = win_window_list; info != nullptr; info = info->m_next)
+ {
+ count++;
+ }
+ return count;
+}
+
void windows_osd_interface::build_slider_list()
{
m_sliders = nullptr;
slider_state *curr = m_sliders;
+ int index = 0;
for (win_window_info *info = win_window_list; info != nullptr; info = info->m_next)
{
- slider_state *window_sliders = info->m_renderer->get_slider_list();
+ slider_state *window_sliders = info->m_renderer->get_slider_list();
if (window_sliders != nullptr)
{
if (m_sliders == nullptr)
@@ -310,6 +321,7 @@ void windows_osd_interface::build_slider_list()
}
curr->next = window_sliders;
}
+ index++;
}
}
}
@@ -841,7 +853,9 @@ void win_window_info::create(running_machine &machine, int index, osd_monitor_in
}
}
else
+ {
window->m_init_state = window->complete_create() ? -1 : 1;
+ }
// handle error conditions
if (window->m_init_state == -1)
diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h
index 9869f3bfecf..8855e191b90 100644
--- a/src/osd/windows/winmain.h
+++ b/src/osd/windows/winmain.h
@@ -296,6 +296,8 @@ public:
windows_options &options() { return m_options; }
+ int window_count();
+
private:
virtual void osd_exit() override;
void build_slider_list();