diff options
Diffstat (limited to 'src/osd/modules')
-rw-r--r-- | src/osd/modules/render/bgfx/chain.cpp | 9 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/chainentry.cpp | 32 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/chainentry.h | 6 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/chainmanager.cpp | 4 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc | 68 | ||||
-rw-r--r-- | src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc | 14 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.cpp | 72 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.h | 2 | ||||
-rw-r--r-- | src/osd/modules/render/drawd3d.cpp | 37 |
9 files changed, 168 insertions, 76 deletions
diff --git a/src/osd/modules/render/bgfx/chain.cpp b/src/osd/modules/render/bgfx/chain.cpp index 5806c3ce042..352bb6f918c 100644 --- a/src/osd/modules/render/bgfx/chain.cpp +++ b/src/osd/modules/render/bgfx/chain.cpp @@ -77,9 +77,9 @@ void bgfx_chain::process(render_primitive* prim, int view, int screen, texture_m screen_device_iterator screen_iterator(window.machine().root_device()); screen_device* screen_device = screen_iterator.byindex(screen); - 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)); + uint16_t screen_count(window.target()->current_view()->screens().count()); + uint16_t screen_width(floor(prim->get_quad_width() + 0.5f)); + uint16_t screen_height(floor(prim->get_quad_height() + 0.5f)); uint32_t rotation_type = (window.target()->orientation() & ROT90) == ROT90 ? 1 : (window.target()->orientation() & ROT180) == ROT180 ? 2 : @@ -101,11 +101,12 @@ void bgfx_chain::process(render_primitive* prim, int view, int screen, texture_m screen_offset_y = -screen_container.yoffset(); } + int current_view = view; for (bgfx_chain_entry* entry : m_entries) { if (!entry->skip()) { - 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); + entry->submit(current_view, prim, textures, screen_count, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, blend, screen); current_view++; } } diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp index ec802e83699..ab18b4029fa 100644 --- a/src/osd/modules/render/bgfx/chainentry.cpp +++ b/src/osd/modules/render/bgfx/chainentry.cpp @@ -55,7 +55,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, 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) +void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_count, 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); @@ -73,7 +73,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, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, screen); + setup_auto_uniforms(prim, textures, screen_count, 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) { @@ -137,6 +137,16 @@ void bgfx_chain_entry::setup_screenoffset_uniforms(float screen_offset_x, float } } +void bgfx_chain_entry::setup_screencount_uniforms(uint16_t screen_count) +{ + bgfx_uniform* u_screen_count = m_effect->uniform("u_screen_count"); + if (u_screen_count != nullptr) + { + float values[1] = { float(screen_count) }; + u_screen_count->set(values, sizeof(float)); + } +} + void bgfx_chain_entry::setup_sourcesize_uniform(render_primitive* prim) const { bgfx_uniform* source_dims = m_effect->uniform("u_source_dims"); @@ -161,6 +171,20 @@ void bgfx_chain_entry::setup_targetsize_uniform(int32_t screen) const } } +void bgfx_chain_entry::setup_targetscale_uniform(int32_t screen) const +{ + bgfx_uniform* target_scale = m_effect->uniform("u_target_scale"); + if (target_scale != nullptr) + { + bgfx_target* output = m_targets.target(screen, m_output); + if (output != nullptr) + { + float values[2] = { float(output->scale()), float(output->scale()) }; + target_scale->set(values, sizeof(float) * 2); + } + } +} + void bgfx_chain_entry::setup_rotationtype_uniform(uint32_t rotation_type) const { bgfx_uniform* rotation_type_uniform = m_effect->uniform("u_rotation_type"); @@ -201,13 +225,15 @@ 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, 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 bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_count, 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_screencount_uniforms(screen_count); setup_sourcesize_uniform(prim); setup_targetsize_uniform(screen); + setup_targetscale_uniform(screen); setup_rotationtype_uniform(rotation_type); setup_swapxy_uniform(swap_xy); setup_quaddims_uniform(prim); diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h index 4f4bede5327..64130c5c93e 100644 --- a/src/osd/modules/render/bgfx/chainentry.h +++ b/src/osd/modules/render/bgfx/chainentry.h @@ -37,7 +37,7 @@ 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, 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); + void submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_count, 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; } @@ -45,12 +45,14 @@ public: bool skip(); private: - 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_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_count, 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_screencount_uniforms(uint16_t screen_count); void setup_sourcesize_uniform(render_primitive* prim) const; void setup_targetsize_uniform(int32_t screen) const; + void setup_targetscale_uniform(int32_t screen) const; void setup_rotationtype_uniform(uint32_t rotation_type) const; void setup_swapxy_uniform(bool swap_xy) const; void setup_quaddims_uniform(render_primitive* prim) const; diff --git a/src/osd/modules/render/bgfx/chainmanager.cpp b/src/osd/modules/render/bgfx/chainmanager.cpp index 444d3c05348..b58e555862c 100644 --- a/src/osd/modules/render/bgfx/chainmanager.cpp +++ b/src/osd/modules/render/bgfx/chainmanager.cpp @@ -435,8 +435,8 @@ uint32_t chain_manager::handle_screen_chains(uint32_t view, render_primitive *st continue; } - 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)); + uint16_t screen_width(floor(prim->get_full_quad_width() + 0.5f)); + uint16_t screen_height(floor(prim->get_full_quad_height() + 0.5f)); if (window.swap_xy()) { std::swap(screen_width, screen_height); diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc index 449294978b0..dda16f150e6 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc @@ -11,7 +11,9 @@ $input v_color0, v_texcoord0 // Autos uniform vec4 u_swap_xy; uniform vec4 u_screen_dims; +uniform vec4 u_screen_count; uniform vec4 u_target_dims; +uniform vec4 u_target_scale; uniform vec4 u_quad_dims; // User-supplied @@ -97,7 +99,7 @@ float GetSpotAddend(vec2 coord, float amount) return saturate(SigmoidSpot); } -float GetRoundCornerFactor(vec2 coord, vec2 bounds, float radiusAmount, float smoothAmount) +float GetBoundsFactor(vec2 coord, vec2 bounds, float radiusAmount, float smoothAmount) { // reduce smooth amount down to radius amount smoothAmount = min(smoothAmount, radiusAmount); @@ -141,7 +143,7 @@ vec2 GetDistortedCoords(vec2 centerCoord, float amount, float amountCube) return centerCoord; } -vec2 GetCoords(vec2 coord, float distortionAmount, float cubicDistortionAmount) +vec2 GetTextureCoords(vec2 coord, float distortionAmount, float cubicDistortionAmount) { // center coordinates coord -= 0.5; @@ -155,6 +157,27 @@ vec2 GetCoords(vec2 coord, float distortionAmount, float cubicDistortionAmount) return coord; } +vec2 GetQuadCoords(vec2 coord, float distortionAmount, float cubicDistortionAmount) +{ + // center coordinates + coord -= 0.5; + + // keep coords inside of the quad bounds of a single screen + if (u_screen_count.x > 0.0 && u_screen_count.x < 2.0) + { + // base-target dimensions (without oversampling) + vec2 BaseTargetDims = u_target_dims.xy / u_target_scale.xy; + + // apply base-target/quad difference + coord *= BaseTargetDims / ((u_swap_xy.x > 0.0) ? u_quad_dims.yx : u_quad_dims.xy); + } + + // distort coordinates + coord = GetDistortedCoords(coord, distortionAmount, cubicDistortionAmount); + + return coord; +} + // Shader void main() @@ -164,18 +187,22 @@ void main() ? u_cubic_distortion.x * 1.1 // cubic distortion need to be a little higher to compensate the quartic distortion : u_cubic_distortion.x * 1.2; // negativ values even more + // corner distortion at least by the amount of the image distorition + float distortCornerAmount = max(u_distort_corner.x, u_distortion.x + u_cubic_distortion.x); + + float roundCornerAmount = u_round_corner.x * 0.5; + float smoothBorderAmount = u_smooth_border.x * 0.5; + vec2 TexelDims = vec2(1.0 / u_target_dims.x, 1.0 / u_target_dims.y); - // Screen Curvature - vec2 BaseCoord = GetCoords(v_texcoord0, distortionAmount, cubicDistortionAmount); + // base-target dimensions (without oversampling) + vec2 BaseTargetDims = u_target_dims.xy / u_target_scale.xy; - // Corner Curvature - vec2 CornerCoord = GetCoords(v_texcoord0, u_distort_corner.x, 0.0); + // Screen Texture Curvature + vec2 BaseCoord = GetTextureCoords(v_texcoord0, distortionAmount, cubicDistortionAmount); - vec2 BaseCoordCentered = BaseCoord; - BaseCoordCentered -= 0.5; - vec2 CornerCoordCentered = CornerCoord; - CornerCoordCentered -= 0.5; + // Screen Quad Curvature + vec2 QuadCoord = GetQuadCoords(v_texcoord0, distortCornerAmount, 0.0); // Color vec4 BaseColor = texture2D(s_tex, BaseCoord); @@ -188,7 +215,7 @@ void main() else { // Vignetting Simulation - vec2 VignetteCoord = CornerCoordCentered; + vec2 VignetteCoord = QuadCoord; float VignetteFactor = GetVignetteFactor(VignetteCoord, u_vignetting.x); BaseColor.rgb *= VignetteFactor; @@ -196,20 +223,23 @@ void main() // Light Reflection Simulation vec4 LightColor = vec4(1.0, 0.90, 0.80, 1.0); // color temperature 5.000 Kelvin - vec2 SpotCoord = CornerCoordCentered; - vec2 NoiseCoord = CornerCoordCentered; + vec2 SpotCoord = QuadCoord; + vec2 NoiseCoord = QuadCoord; float SpotAddend = GetSpotAddend(SpotCoord, u_reflection.x); float NoiseFactor = GetNoiseFactor(SpotAddend, rand(NoiseCoord)); BaseColor += SpotAddend * NoiseFactor * LightColor; // Round Corners Simulation - vec2 RoundCornerCoord = CornerCoordCentered; - vec2 RoundCornerBounds = (u_swap_xy.x > 0.0) - ? u_quad_dims.yx - : u_quad_dims.xy; - - float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerBounds, u_round_corner.x * 0.5f, u_smooth_border.x * 0.5f); + vec2 RoundCornerCoord = QuadCoord; + vec2 RoundCornerBounds = (u_screen_count.x > 0.0 && u_screen_count.x < 2.0) + ? u_quad_dims.xy // align corners to screen quad bounds + : BaseTargetDims; // align corners to target texture bounds + RoundCornerBounds = (u_swap_xy.x > 0.0) + ? RoundCornerBounds.yx + : RoundCornerBounds.xy; + + float roundCornerFactor = GetBoundsFactor(RoundCornerCoord, RoundCornerBounds, roundCornerAmount, smoothBorderAmount); BaseColor.rgb *= roundCornerFactor; gl_FragColor = BaseColor; 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 63800bb61d3..beba1f1743f 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 @@ -11,6 +11,8 @@ $input v_color0, v_texcoord0 // Autos 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; @@ -63,13 +65,19 @@ vec2 GetAdjustedCoords(vec2 coord) return coord; } -vec2 GetShadowCoord(vec2 QuadCoord, vec2 SourceCoord) +vec2 GetShadowCoord(vec2 TargetCoord, vec2 SourceCoord) { + // base-target dimensions (remove oversampling) + vec2 BaseTargetDims = u_target_dims.xy / u_target_scale.xy; + BaseTargetDims = u_swap_xy.x > 0.0 + ? BaseTargetDims.yx + : BaseTargetDims.xy; + vec2 canvasCoord = u_shadow_tile_mode.x == 0.0 - ? QuadCoord + u_shadow_uv_offset.xy / u_quad_dims.xy + ? TargetCoord + u_shadow_uv_offset.xy / BaseTargetDims : SourceCoord + u_shadow_uv_offset.xy / u_source_dims.xy; vec2 canvasTexelDims = u_shadow_tile_mode.x == 0.0 - ? vec2(1.0, 1.0) / u_quad_dims.xy + ? vec2(1.0, 1.0) / BaseTargetDims : vec2(1.0, 1.0) / u_source_dims.xy; vec2 shadowUV = u_shadow_uv.xy; diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 105313cb308..837e599b904 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -787,7 +787,9 @@ int shaders::create_resources() { effects[i]->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); effects[i]->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); + effects[i]->add_uniform("TargetScale", uniform::UT_FLOAT, uniform::CU_TARGET_SCALE); effects[i]->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); + effects[i]->add_uniform("ScreenCount", uniform::UT_INT, uniform::CU_SCREEN_COUNT); effects[i]->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); effects[i]->add_uniform("SwapXY", uniform::UT_BOOL, uniform::CU_SWAP_XY); effects[i]->add_uniform("VectorScreen", uniform::UT_BOOL, uniform::CU_VECTOR_SCREEN); @@ -1018,9 +1020,9 @@ rgb_t shaders::apply_color_convolution(rgb_t color) { // this function uses the same algorithm as the color convolution shader pass - float r = static_cast<float>(color.r()) / 255.0f; - float g = static_cast<float>(color.g()) / 255.0f; - float b = static_cast<float>(color.b()) / 255.0f; + float r = float(color.r()) / 255.0f; + float g = float(color.g()) / 255.0f; + float b = float(color.b()) / 255.0f; float *rRatio = options->red_ratio; float *gRatio = options->grn_ratio; @@ -1049,9 +1051,9 @@ rgb_t shaders::apply_color_convolution(rgb_t color) b = chroma[2] * saturation + luma; return rgb_t( - std::max(0, std::min(255, static_cast<int>(r * 255.0f))), - std::max(0, std::min(255, static_cast<int>(g * 255.0f))), - std::max(0, std::min(255, static_cast<int>(b * 255.0f)))); + std::max(0, std::min(255, int(r * 255.0f))), + std::max(0, std::min(255, int(g * 255.0f))), + std::max(0, std::min(255, int(b * 255.0f)))); } int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum) @@ -1161,6 +1163,8 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, { int next_index = source_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(); @@ -1177,9 +1181,9 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, : rgb_t(0, 0, 0); back_color_rgb = apply_color_convolution(back_color_rgb); float back_color[3] = { - static_cast<float>(back_color_rgb.r()) / 255.0f, - static_cast<float>(back_color_rgb.g()) / 255.0f, - static_cast<float>(back_color_rgb.b()) / 255.0f }; + float(back_color_rgb.r()) / 255.0f, + float(back_color_rgb.g()) / 255.0f, + float(back_color_rgb.b()) / 255.0f }; curr_effect = post_effect; curr_effect->update_uniforms(); @@ -1582,8 +1586,8 @@ d3d_render_target* shaders::get_texture_target(render_primitive *prim, texture_i auto win = d3d->assert_window(); - int target_width = int(prim->get_quad_width() + 0.5f); - int target_height = int(prim->get_quad_height() + 0.5f); + int target_width = int(prim->get_full_quad_width() + 0.5f); + int target_height = int(prim->get_full_quad_height() + 0.5f); target_width *= oversampling_enable ? 2 : 1; target_height *= oversampling_enable ? 2 : 1; if (win->swap_xy()) @@ -1618,11 +1622,10 @@ d3d_render_target* shaders::get_vector_target(render_primitive *prim) auto win = d3d->assert_window(); - // source and target size are the same for vector targets int source_width = int(prim->get_quad_width() + 0.5f); int source_height = int(prim->get_quad_height() + 0.5f); - int target_width = source_width; - int target_height = source_height; + int target_width = int(prim->get_full_quad_width() + 0.5f); + int target_height = int(prim->get_full_quad_height() + 0.5f); target_width *= oversampling_enable ? 2 : 1; target_height *= oversampling_enable ? 2 : 1; if (win->swap_xy()) @@ -1658,11 +1661,10 @@ bool shaders::create_vector_target(render_primitive *prim) auto win = d3d->assert_window(); - // source and target size are the same for vector targets int source_width = int(prim->get_quad_width() + 0.5f); int source_height = int(prim->get_quad_height() + 0.5f); - int target_width = source_width; - int target_height = source_height; + int target_width = int(prim->get_full_quad_width() + 0.5f); + int target_height = int(prim->get_full_quad_height() + 0.5f); target_width *= oversampling_enable ? 2 : 1; target_height *= oversampling_enable ? 2 : 1; if (win->swap_xy()) @@ -1748,8 +1750,8 @@ bool shaders::register_texture(render_primitive *prim, texture_info *texture) int source_width = texture->get_width(); int source_height = texture->get_height(); - int target_width = int(prim->get_quad_width() + 0.5f); - int target_height = int(prim->get_quad_height() + 0.5f); + int target_width = int(prim->get_full_quad_width() + 0.5f); + int target_height = int(prim->get_full_quad_height() + 0.5f); target_width *= oversampling_enable ? 2 : 1; target_height *= oversampling_enable ? 2 : 1; if (win->swap_xy()) @@ -2339,6 +2341,12 @@ void uniform::update() m_shader->set_vector("ScreenDims", 2, &screendims.c.x); break; } + case CU_SCREEN_COUNT: + { + int screen_count = win->target()->current_view()->screens().count(); + m_shader->set_int("ScreenCount", screen_count); + break; + } case CU_SOURCE_DIMS: { if (vector_screen) @@ -2347,8 +2355,8 @@ void uniform::update() { // vector screen has no source texture, so take the source dimensions of the render target float sourcedims[2] = { - static_cast<float>(shadersys->curr_render_target->width), - static_cast<float>(shadersys->curr_render_target->height) }; + float(shadersys->curr_render_target->width), + float(shadersys->curr_render_target->height) }; m_shader->set_vector("SourceDims", 2, sourcedims); } } @@ -2367,20 +2375,30 @@ void uniform::update() if (shadersys->curr_render_target) { float targetdims[2] = { - static_cast<float>(shadersys->curr_render_target->target_width), - static_cast<float>(shadersys->curr_render_target->target_height) }; + float(shadersys->curr_render_target->target_width), + float(shadersys->curr_render_target->target_height) }; m_shader->set_vector("TargetDims", 2, targetdims); } break; } + case CU_TARGET_SCALE: + { + if (shadersys->curr_render_target) + { + float targetscale[2] = { + shadersys->oversampling_enable ? 2.0f : 1.0f, + shadersys->oversampling_enable ? 2.0f : 1.0f }; + m_shader->set_vector("TargetScale", 2, targetscale); + } + break; + } case CU_QUAD_DIMS: { if (shadersys->curr_poly) { float quaddims[2] = { - // round - static_cast<float>(static_cast<int>(shadersys->curr_poly->prim_width() + 0.5f)), - static_cast<float>(static_cast<int>(shadersys->curr_poly->prim_height() + 0.5f)) }; + floor(shadersys->curr_poly->prim_width() + 0.5f), + floor(shadersys->curr_poly->prim_height() + 0.5f) }; m_shader->set_vector("QuadDims", 2, quaddims); } break; @@ -2497,7 +2515,7 @@ void uniform::update() break; case CU_POST_SHADOW_COUNT: { - float shadowcount[2] = { static_cast<float>(options->shadow_mask_count_x), static_cast<float>(options->shadow_mask_count_y) }; + float shadowcount[2] = { float(options->shadow_mask_count_x), float(options->shadow_mask_count_y) }; m_shader->set_vector("ShadowCount", 2, shadowcount); break; } diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index 8256421c4ad..cd99f4dd7ba 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -42,8 +42,10 @@ public: enum { CU_SCREEN_DIMS = 0, + CU_SCREEN_COUNT, CU_SOURCE_DIMS, CU_TARGET_DIMS, + CU_TARGET_SCALE, CU_QUAD_DIMS, CU_SWAP_XY, diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index 61371a05184..aca3fb779ca 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -1423,6 +1423,8 @@ void renderer_d3d9::batch_vectors(int vector_count) float quad_width = 0.0f; float quad_height = 0.0f; + float target_width = 0.0f; + float target_height = 0.0f; int vertex_count = vector_count * 6; int triangle_count = vector_count * 2; @@ -1445,8 +1447,10 @@ void renderer_d3d9::batch_vectors(int vector_count) case render_primitive::QUAD: if (PRIMFLAG_GET_VECTORBUF(prim.flags)) { - quad_width = prim.bounds.x1 - prim.bounds.x0; - quad_height = prim.bounds.y1 - prim.bounds.y0; + quad_width = prim.get_quad_width(); + quad_height = prim.get_quad_height(); + target_width = prim.get_full_quad_width(); + target_height = prim.get_full_quad_height(); } break; @@ -1476,18 +1480,18 @@ void renderer_d3d9::batch_vectors(int vector_count) ((rotation_0 || rotation_90) && orientation_swap_xy) || ((rotation_180 || rotation_90) && !orientation_swap_xy); - float screen_width = static_cast<float>(this->get_width()); - float screen_height = static_cast<float>(this->get_height()); + float screen_width = float(this->get_width()); + float screen_height = float(this->get_height()); float half_screen_width = screen_width * 0.5f; float half_screen_height = screen_height * 0.5f; float screen_swap_x_factor = 1.0f / screen_width * screen_height; float screen_swap_y_factor = 1.0f / screen_height * screen_width; - float screen_quad_ratio_x = screen_width / quad_width; - float screen_quad_ratio_y = screen_height / quad_height; + float screen_target_ratio_x = screen_width / target_width; + float screen_target_ratio_y = screen_height / target_height; if (swap_xy) { - std::swap(screen_quad_ratio_x, screen_quad_ratio_y); + std::swap(screen_target_ratio_x, screen_target_ratio_y); } for (int batchindex = 0; batchindex < m_batchindex; batchindex++) @@ -1513,9 +1517,9 @@ void renderer_d3d9::batch_vectors(int vector_count) m_vectorbatch[batchindex].x -= half_screen_width; m_vectorbatch[batchindex].y -= half_screen_height; - // correct screen/quad ratio (vectors are created in screen coordinates and have to be adjusted for texture corrdinates of the quad) - m_vectorbatch[batchindex].x *= screen_quad_ratio_x; - m_vectorbatch[batchindex].y *= screen_quad_ratio_y; + // correct screen/target ratio (vectors are created in screen coordinates and have to be adjusted for texture corrdinates of the target) + m_vectorbatch[batchindex].x *= screen_target_ratio_x; + m_vectorbatch[batchindex].y *= screen_target_ratio_y; // un-center m_vectorbatch[batchindex].x += half_screen_width; @@ -1668,10 +1672,10 @@ void renderer_d3d9::draw_line(const render_primitive &prim) vertex[0].u0 = start.c.x; vertex[0].v0 = start.c.y; - vertex[2].u0 = stop.c.x; - vertex[2].v0 = start.c.y; vertex[1].u0 = start.c.x; vertex[1].v0 = stop.c.y; + vertex[2].u0 = stop.c.x; + vertex[2].v0 = start.c.y; vertex[3].u0 = stop.c.x; vertex[3].v0 = stop.c.y; @@ -1703,7 +1707,6 @@ void renderer_d3d9::draw_line(const render_primitive &prim) void renderer_d3d9::draw_quad(const render_primitive &prim) { texture_info *texture = m_texture_manager->find_texinfo(&prim.texture, prim.flags); - if (texture == nullptr) { texture = get_default_texture(); @@ -1712,7 +1715,9 @@ void renderer_d3d9::draw_quad(const render_primitive &prim) // get a pointer to the vertex buffer vertex *vertex = mesh_alloc(4); if (vertex == nullptr) + { return; + } // fill in the vertexes clockwise vertex[0].x = prim.bounds.x0; @@ -1723,8 +1728,8 @@ void renderer_d3d9::draw_quad(const render_primitive &prim) vertex[2].y = prim.bounds.y1; vertex[3].x = prim.bounds.x1; vertex[3].y = prim.bounds.y1; - float width = prim.bounds.x1 - prim.bounds.x0; - float height = prim.bounds.y1 - prim.bounds.y0; + float quad_width = prim.get_quad_width(); + float quad_height = prim.get_quad_height(); // set the texture coordinates if (texture != nullptr) @@ -1761,7 +1766,7 @@ void renderer_d3d9::draw_quad(const render_primitive &prim) } // now add a polygon entry - m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim.flags, texture, D3DTOP_MODULATE, width, height); + m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim.flags, texture, D3DTOP_MODULATE, quad_width, quad_height); m_numpolys++; } |