Implemented handling for u_screen_scale and u_screen_offset (nw)

master
ImJezze 2016-04-21 07:52:29 +02:00
parent a72ad0c4fe
commit b1c06acb61
20 changed files with 110 additions and 48 deletions

View File

@ -14,6 +14,9 @@
// type: string
"author": "Ryan Holtz & ImJezze",
// transform (optional): This value determines whether the screen container is transformed the chain's shaders, otherwise the core renderer will handle the transformation (scale, offset).
"transform": true,
// sliders (optional): The list of sliders used by all of the entries in this chain. Can be omitted if no entries use any sliders.
"sliders": [
// type (required): The sliders's conceptual type. Is it a list of string selections? Is it a single floating-point value? Does it require RGB values, or XY values?

View File

@ -8,34 +8,34 @@
//============================================================
{
"blend": {
"equation": "add",
"srcColor": "srcalpha",
"dstColor": "1-srcalpha",
"srcAlpha": "srcalpha",
"dstAlpha": "1-srcalpha"
"equation": "add",
"srcColor": "srcalpha",
"dstColor": "1-srcalpha",
"srcAlpha": "srcalpha",
"dstAlpha": "1-srcalpha"
},
"depth": {
"function": "always"
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/hlsl/vs_distortion",
"fragment": "chains/hlsl/fs_distortion",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 0.0 ] },
{ "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_screen_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "s_tex", "type": "int", "values": [ 0.0 ] },
{ "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_screen_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_target_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_distortion", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_cubic_distortion", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_distort_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_round_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_smooth_border", "type": "vec4", "values": [ 0.05, 0.0, 0.0, 0.0 ] },
{ "name": "u_vignetting", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_reflection", "type": "vec4", "values": [ 0.30, 0.0, 0.0, 0.0 ] }
{ "name": "u_distort_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_round_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_smooth_border", "type": "vec4", "values": [ 0.05, 0.0, 0.0, 0.0 ] },
{ "name": "u_vignetting", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] },
{ "name": "u_reflection", "type": "vec4", "values": [ 0.30, 0.0, 0.0, 0.0 ] }
]
}

View File

@ -28,7 +28,7 @@
{ "name": "s_tex", "type": "int", "values": [ 0.0 ] },
{ "name": "s_shadow", "type": "int", "values": [ 1.0 ] },
{ "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_source_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_source_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_humbar_hertz_rate", "type": "vec4", "values": [ 0.001, 0.0, 0.0, 0.0 ] },
{ "name": "u_humbar_alpha", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },

View File

@ -147,7 +147,7 @@ float2 GetAdjustedCoords(float2 coord, float2 centerOffset)
coord -= centerOffset;
// apply screen scale
coord /= ScreenScale;
coord *= ScreenScale;
// un-center coordinates
coord += centerOffset;

View File

@ -922,7 +922,7 @@ render_target::render_target(render_manager &manager, const internal_layout *lay
m_base_orientation(ROT0),
m_maxtexwidth(65536),
m_maxtexheight(65536),
m_transform_primitives(true)
m_transform_container(true)
{
// determine the base layer configuration based on options
m_base_layerconfig.set_backdrops_enabled(manager.machine().options().use_backdrops());
@ -1766,7 +1766,7 @@ void render_target::add_container_primitives(render_primitive_list &list, const
float yoffs = (container_xform.orientation & ORIENTATION_SWAP_XY) ? container.xoffset() : container.yoffset();
if (container_xform.orientation & ORIENTATION_FLIP_X) xoffs = -xoffs;
if (container_xform.orientation & ORIENTATION_FLIP_Y) yoffs = -yoffs;
if (!m_transform_primitives)
if (!m_transform_container)
{
xscale = 1.0f;
yscale = 1.0f;

View File

@ -922,7 +922,7 @@ public:
void set_orientation(int orientation) { m_orientation = orientation; }
void set_view(int viewindex);
void set_max_texture_size(int maxwidth, int maxheight);
void set_transform_primitives(bool transform_primitives) { m_transform_primitives = transform_primitives; }
void set_transform_container(bool transform_container) { m_transform_container = transform_container; }
void set_keepaspect(bool keepaspect) { m_keepaspect = keepaspect; }
void set_scale_mode(bool scale_mode) { m_scale_mode = scale_mode; }
@ -1029,8 +1029,8 @@ private:
simple_list<render_container> m_debug_containers; // list of debug containers
INT32 m_clear_extent_count; // number of clear extents
INT32 m_clear_extents[MAX_CLEAR_EXTENTS]; // array of clear extents
bool m_transform_primitives; // determines if the primitives shall be scaled/offset by screen settings,
// otherwise the respective render API will handle it (default is true)
bool m_transform_container; // determines whether the screen container is transformed by the core renderer,
// otherwise the respective render API will handle the transformation (scale, offset)
static render_screen_list s_empty_screen_list;
};

View File

@ -21,9 +21,10 @@
#include "chain.h"
bgfx_chain::bgfx_chain(std::string name, std::string author, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, std::uint32_t screen_index)
bgfx_chain::bgfx_chain(std::string name, std::string author, bool transform, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, std::uint32_t screen_index)
: m_name(name)
, m_author(author)
, m_transform(transform)
, m_targets(targets)
, m_sliders(sliders)
, m_params(params)
@ -60,22 +61,34 @@ bgfx_chain::~bgfx_chain()
void bgfx_chain::process(render_primitive* prim, int view, int screen, texture_manager& textures, osd_window& window, uint64_t blend)
{
screen_device_iterator screen_iterator(window.machine().root_device());
screen_device* screen_device = screen_iterator.first();
for (int i = 0; i < screen; i++)
{
screen_device = screen_iterator.next();
}
render_container &screen_container = screen_device->container();
int current_view = view;
uint16_t screen_width(floor((prim->bounds.x1 - prim->bounds.x0) + 0.5f));
uint16_t screen_height(floor((prim->bounds.y1 - prim->bounds.y0) + 0.5f));
uint32_t rotation_type = (window.target()->orientation() & ROT90) == ROT90 ?
1 : (window.target()->orientation() & ROT180) == ROT180 ?
2 : (window.target()->orientation() & ROT270) == ROT270 ?
3 : 0;
uint32_t rotation_type =
(window.target()->orientation() & ROT90) == ROT90 ? 1 :
(window.target()->orientation() & ROT180) == ROT180 ? 2 :
(window.target()->orientation() & ROT270) == ROT270 ? 3 : 0;
bool orientation_swap_xy = (window.machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool rotation_swap_xy = (window.target()->orientation() & ROT90) == ROT90 || (window.target()->orientation() & ROT270) == ROT270;
bool rotation_swap_xy = (window.target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool swap_xy = orientation_swap_xy ^ rotation_swap_xy;
float screen_scale_x = 1.0f / screen_container.xscale();
float screen_scale_y = 1.0f / screen_container.yscale();
float screen_offset_x = -screen_container.xoffset();
float screen_offset_y = -screen_container.yoffset();
for (bgfx_chain_entry* entry : m_entries)
{
if (!entry->skip())
{
entry->submit(current_view, prim, textures, screen_width, screen_height, rotation_type, swap_xy, blend, screen);
entry->submit(current_view, prim, textures, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, blend, screen);
current_view++;
}
}

View File

@ -28,7 +28,7 @@ class osd_window;
class bgfx_chain
{
public:
bgfx_chain(std::string name, std::string author, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, uint32_t screen_index);
bgfx_chain(std::string name, std::string author, bool transform, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, uint32_t screen_index);
~bgfx_chain();
void process(render_primitive* prim, int view, int screen, texture_manager& textures, osd_window &window, uint64_t blend = 0L);
@ -36,10 +36,12 @@ public:
// Getters
std::vector<bgfx_slider*>& sliders() { return m_sliders; }
uint32_t applicable_passes();
bool transform() { return m_transform; }
private:
std::string m_name;
std::string m_author;
bool m_transform;
target_manager& m_targets;
std::vector<bgfx_slider*> m_sliders;
std::vector<bgfx_parameter*> m_params;

View File

@ -50,7 +50,7 @@ bgfx_chain_entry::~bgfx_chain_entry()
delete m_clear;
}
void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen)
void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen)
{
bgfx::setViewSeq(view, true);
@ -68,7 +68,7 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
put_screen_buffer(prim, &buffer);
bgfx::setVertexBuffer(&buffer);
setup_auto_uniforms(prim, textures, screen_width, screen_height, rotation_type, swap_xy, screen);
setup_auto_uniforms(prim, textures, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, screen);
for (bgfx_entry_uniform* uniform : m_uniforms)
{
@ -112,6 +112,26 @@ void bgfx_chain_entry::setup_screensize_uniforms(texture_manager& textures, uint
}
}
void bgfx_chain_entry::setup_screenscale_uniforms(float screen_scale_x, float screen_scale_y)
{
bgfx_uniform* screen_scale = m_effect->uniform("u_screen_scale");
if (screen_scale != nullptr)
{
float values[2] = { screen_scale_x, screen_scale_y };
screen_scale->set(values, sizeof(float) * 2);
}
}
void bgfx_chain_entry::setup_screenoffset_uniforms(float screen_offset_x, float screen_offset_y)
{
bgfx_uniform* screen_offset = m_effect->uniform("u_screen_offset");
if (screen_offset != nullptr)
{
float values[2] = { screen_offset_x, screen_offset_y };
screen_offset->set(values, sizeof(float) * 2);
}
}
void bgfx_chain_entry::setup_sourcesize_uniform(render_primitive* prim) const
{
bgfx_uniform* source_dims = m_effect->uniform("u_source_dims");
@ -176,9 +196,11 @@ void bgfx_chain_entry::setup_screenindex_uniform(int32_t screen) const
}
}
void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen)
void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, int32_t screen)
{
setup_screensize_uniforms(textures, screen_width, screen_height, screen);
setup_screenscale_uniforms(screen_scale_x, screen_scale_y);
setup_screenoffset_uniforms(screen_offset_x, screen_offset_y);
setup_sourcesize_uniform(prim);
setup_targetsize_uniform(screen);
setup_rotationtype_uniform(rotation_type);

View File

@ -37,15 +37,17 @@ public:
bgfx_chain_entry(std::string name, bgfx_effect* effect, clear_state* clear, std::vector<bgfx_suppressor*> suppressors, std::vector<bgfx_input_pair> inputs, std::vector<bgfx_entry_uniform*> uniforms, target_manager& targets, std::string output);
~bgfx_chain_entry();
void submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen);
void submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen);
// Getters
std::string name() const { return m_name; }
bool skip();
private:
void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen);
void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, int32_t screen);
void setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen);
void setup_screenscale_uniforms(float screen_scale_x, float screen_scale_y);
void setup_screenoffset_uniforms(float screen_offset_x, float screen_offset_y);
void setup_sourcesize_uniform(render_primitive* prim) const;
void setup_targetsize_uniform(int32_t screen) const;
void setup_rotationtype_uniform(uint32_t rotation_type) const;

View File

@ -53,6 +53,13 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, std::string prefix
}
}
// Parse whether the screen container is transformed by the chain's shaders
bool transform = false;
if (value.HasMember("transform"))
{
transform = value["transform"].GetBool();
}
// Map sliders
std::map<std::string, bgfx_slider*> slider_map;
for (bgfx_slider* slider : sliders)
@ -116,7 +123,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, std::string prefix
}
}
return new bgfx_chain(name, author, targets, sliders, parameters, entries, target_list, screen_index);
return new bgfx_chain(name, author, transform, targets, sliders, parameters, entries, target_list, screen_index);
}
bool chain_reader::validate_parameters(const Value& value, std::string prefix)

View File

@ -12,8 +12,8 @@ $input v_color0, v_texcoord0
uniform vec4 u_swap_xy;
uniform vec4 u_source_dims; // size of the guest machine
uniform vec4 u_quad_dims;
uniform vec4 u_screen_scale; // TODO: Hook up ScreenScale code-side
uniform vec4 u_screen_offset; // TODO: Hook up ScreenOffset code-side
uniform vec4 u_screen_scale;
uniform vec4 u_screen_offset;
// User-supplied
uniform vec4 u_scanline_alpha;
@ -50,7 +50,7 @@ vec2 GetAdjustedCoords(vec2 coord, vec2 center_offset)
coord -= center_offset;
// apply screen scale
//coord /= u_screen_scale.xy;
coord *= u_screen_scale.xy;
// un-center coordinates
coord += center_offset;
@ -102,7 +102,7 @@ void main()
// Color
vec4 BaseColor = texture2D(s_tex, BaseCoord);
if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0)
if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 || BaseCoord.x > 1.0 || BaseCoord.y > 1.0)
{
BaseColor.rgb = vec3(0.0, 0.0, 0.0);
}
@ -111,7 +111,7 @@ void main()
if (u_shadow_alpha.x > 0.0)
{
vec2 ShadowCoord = GetShadowCoord(v_texcoord0.xy, v_texcoord0.xy);
vec4 ShadowColor = texture2D(s_shadow, ShadowCoord);
vec3 ShadowMaskColor = mix(vec3(1.0, 1.0, 1.0), ShadowColor.rgb, u_shadow_alpha.xxx);
@ -122,7 +122,7 @@ void main()
// Color Compression
// 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
BaseColor.r = pow(BaseColor.r, u_power.r);
BaseColor.g = pow(BaseColor.g, u_power.g);
@ -136,7 +136,7 @@ void main()
float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b;
float ScanCoord = v_texcoord0.y * u_source_dims.y * u_scanline_scale.x * 3.1415927;
float ScanCoord = BaseCoord.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 ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness);

View File

@ -1379,8 +1379,8 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly,
screen_device *screen = screen_iterator.byindex(curr_screen);
render_container &screen_container = screen->container();
float xscale = screen_container.xscale();
float yscale = screen_container.yscale();
float xscale = 1.0f / screen_container.xscale();
float yscale = 1.0f / screen_container.yscale();
float xoffset = -screen_container.xoffset();
float yoffset = -screen_container.yoffset();

View File

@ -12,6 +12,8 @@
#include "binpacker.h"
#include "bgfx/vertex.h"
#include "bgfx/chain.h"
#include "bgfx/chainmanager.h"
#include "sliderdirtynotifier.h"
class texture_manager;
@ -53,8 +55,19 @@ public:
virtual render_primitive_list *get_primitives() override
{
// determines whether the screen container is transformed by the chain's shaders
bool chain_transform = false;
// check the first chain
bgfx_chain* chain = this->m_chains->screen_chain(0);
if (chain != nullptr)
{
chain_transform = chain->transform();
}
osd_dim wdim = window().get_size();
window().target()->set_bounds(wdim.width(), wdim.height(), window().pixel_aspect());
window().target()->set_transform_container(!chain_transform);
return &window().target()->get_primitives();
}

View File

@ -209,7 +209,7 @@ render_primitive_list *renderer_d3d9::get_primitives()
if (m_shaders != nullptr)
{
// do not transform primitives (scale, offset) if shaders are enabled, the shaders will handle the transformation
window().target()->set_transform_primitives(!m_shaders->enabled());
window().target()->set_transform_container(!m_shaders->enabled());
}
return &window().target()->get_primitives();
}