Removed hacks for vector screens from shaders (nw)

- added handling of texture coordinates for vector screens to core render
- added handling of orientation/rotation for vector screens to D3D renderer
master
ImJezze 2016-04-13 19:21:57 +02:00
parent 6be4d8312c
commit 32f0e6efac
11 changed files with 177 additions and 135 deletions

View File

@ -278,9 +278,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.TexCoord = TexCoord.xy;
TexCoord += VectorScreen
? 0.5f / TargetDims.xy
: 0.5f / SourceDims.xy;
TexCoord += 0.5f / SourceDims;
Output.BloomCoord = TexCoord.xy;

View File

@ -89,8 +89,6 @@ uniform float2 ScreenDims; // size of the window or fullscreen
uniform float2 TargetDims; // size of the target surface
uniform float2 QuadDims; // size of the screen quad
uniform bool VectorScreen;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
@ -120,7 +118,6 @@ uniform float VignettingAmount = 0.0f;
uniform float ReflectionAmount = 0.0f;
uniform bool SwapXY = false;
uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°
float GetNoiseFactor(float3 n, float random)
{
@ -146,40 +143,16 @@ float GetSpotAddend(float2 coord, float amount)
{
float2 SpotCoord = coord;
// hack for vector screen
if (VectorScreen)
{
// upper right quadrant
float2 spotOffset =
RotationType == 1 // 90°
? float2(-0.25f, -0.25f)
: RotationType == 2 // 180°
? float2(0.25f, -0.25f)
: RotationType == 3 // 270° else 0°
? float2(0.25f, 0.25f)
: float2(-0.25f, 0.25f);
// upper right quadrant
float2 spotOffset = float2(-0.25f, 0.25f);
// normalized screen canvas ratio
float2 CanvasRatio = SwapXY
? float2(QuadDims.x / QuadDims.y, 1.0f)
: float2(1.0f, QuadDims.y / QuadDims.x);
// normalized screen canvas ratio
float2 CanvasRatio = SwapXY
? float2(1.0f, QuadDims.x / QuadDims.y)
: float2(1.0f, QuadDims.y / QuadDims.x);
SpotCoord += spotOffset;
SpotCoord *= CanvasRatio;
}
else
{
// upper right quadrant
float2 spotOffset = float2(-0.25f, 0.25f);
// normalized screen canvas ratio
float2 CanvasRatio = SwapXY
? float2(1.0f, QuadDims.x / QuadDims.y)
: float2(1.0f, QuadDims.y / QuadDims.x);
SpotCoord += spotOffset;
SpotCoord *= CanvasRatio;
}
SpotCoord += spotOffset;
SpotCoord *= CanvasRatio;
float SpotBlur = amount;
@ -201,7 +174,7 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount)
smoothAmount = min(smoothAmount, radiusAmount);
float2 quadDims = QuadDims;
quadDims = !VectorScreen && SwapXY
quadDims = SwapXY
? quadDims.yx
: quadDims.xy;

View File

@ -55,8 +55,6 @@ uniform float2 ScreenDims;
uniform float2 TargetDims;
uniform float2 QuadDims;
uniform bool VectorScreen;
static const float2 Coord0Offset = float2(-0.5f, -0.5f);
static const float2 Coord1Offset = float2( 0.5f, -0.5f);
static const float2 Coord2Offset = float2(-0.5f, 0.5f);
@ -67,9 +65,6 @@ VS_OUTPUT vs_main(VS_INPUT Input)
VS_OUTPUT Output = (VS_OUTPUT)0;
float2 HalfTargetTexelDims = 0.5f / TargetDims;
HalfTargetTexelDims *= VectorScreen
? (ScreenDims / QuadDims)
: 1.0f;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;

View File

@ -175,27 +175,22 @@ float2 GetShadowCoord(float2 QuadCoord, float2 SourceCoord)
float2 shadowUV = ShadowUV;
float2 shadowCount = ShadowCount;
// swap x/y vector and raster in screen mode (not source mode)
// swap x/y in screen mode (not source mode)
canvasCoord = ShadowTileMode == 0 && SwapXY
? canvasCoord.yx
: canvasCoord.xy;
// swap x/y vector and raster in screen mode (not source mode)
// swap x/y in screen mode (not source mode)
shadowCount = ShadowTileMode == 0 && SwapXY
? shadowCount.yx
: shadowCount.xy;
float2 shadowTile = canvasTexelDims * shadowCount;
// swap x/y vector in screen mode (not raster and not source mode)
shadowTile = VectorScreen && ShadowTileMode == 0 && SwapXY
? shadowTile.yx
: shadowTile.xy;
float2 shadowFrac = frac(canvasCoord / shadowTile);
// swap x/y raster in screen mode (not vector and not source mode)
shadowFrac = !VectorScreen && ShadowTileMode == 0 && SwapXY
// swap x/y in screen mode (not source mode)
shadowFrac = ShadowTileMode == 0 && SwapXY
? shadowFrac.yx
: shadowFrac.xy;
@ -215,12 +210,8 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 BaseColor = tex2D(DiffuseSampler, TexCoord);
BaseColor.a = 1.0f;
// keep border
if (!PrepareBloom)
{
// clip border
clip(TexCoord < 0.0f || TexCoord > 1.0f ? -1 : 1);
}
// clip border
clip(TexCoord < 0.0f || TexCoord > 1.0f ? -1 : 1);
// Mask Simulation (may not affect bloom)
if (!PrepareBloom && ShadowAlpha > 0.0f)

View File

@ -55,8 +55,6 @@ uniform float2 ScreenDims;
uniform float2 TargetDims;
uniform float2 QuadDims;
uniform bool VectorScreen;
VS_OUTPUT vs_screen_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;

View File

@ -28,7 +28,7 @@ struct PS_INPUT
{
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
float2 LineInfo : TEXCOORD1;
float2 LineInfo : TEXCOORD1; // x is the line length, y is unused
};
//-----------------------------------------------------------------------------
@ -47,9 +47,9 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y; // flip y
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.xy -= 0.5f; // center
Output.Position.xy *= 2.0f * (ScreenDims / QuadDims); // zoom
Output.Position.xy *= 2.0f; // zoom
Output.TexCoord = Input.TexCoord;

View File

@ -1880,12 +1880,6 @@ void render_target::add_container_primitives(render_primitive_list &list, const
}
else
{
if (curitem.flags() & PRIMFLAG_VECTORBUF_MASK)
{
// determine UV coordinates
prim->texcoords = oriented_texcoords[0];
}
// adjust the color for brightness/contrast/gamma
prim->color.r = container.apply_brightness_contrast_gamma_fp(prim->color.r);
prim->color.g = container.apply_brightness_contrast_gamma_fp(prim->color.g);
@ -1894,12 +1888,33 @@ void render_target::add_container_primitives(render_primitive_list &list, const
// no texture
prim->texture.base = nullptr;
// set the basic flags
prim->flags = (curitem.flags() & ~PRIMFLAG_BLENDMODE_MASK)
| PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA);
if (PRIMFLAG_GET_VECTORBUF(curitem.flags()))
{
// determine the final orientation (textures are up-side down, so flip y-axis for vectors to immitate that behavior)
int finalorient = orientation_add(ORIENTATION_FLIP_Y, container_xform.orientation);
// apply clipping
clipped = render_clip_quad(&prim->bounds, &cliprect, nullptr);
// determine UV coordinates
prim->texcoords = oriented_texcoords[finalorient];
// apply clipping
clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords);
// apply the final orientation from the quad flags and then build up the final flags
prim->flags = (curitem.flags() & ~(PRIMFLAG_TEXORIENT_MASK | PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK))
| PRIMFLAG_TEXORIENT(finalorient);
prim->flags |= blendmode != -1
? PRIMFLAG_BLENDMODE(blendmode)
: PRIMFLAG_BLENDMODE(PRIMFLAG_GET_BLENDMODE(curitem.flags()));
}
else
{
// set the basic flags
prim->flags = (curitem.flags() & ~PRIMFLAG_BLENDMODE_MASK)
| PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA);
// apply clipping
clipped = render_clip_quad(&prim->bounds, &cliprect, nullptr);
}
}
break;
}

View File

@ -134,8 +134,7 @@ public:
bool orientation_swap_xy =
(machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool rotation_swap_xy =
(target()->orientation() & ROT90) == ROT90 ||
(target()->orientation() & ROT270) == ROT270;
(target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
return orientation_swap_xy ^ rotation_swap_xy;
};

View File

@ -992,14 +992,12 @@ int shaders::create_resources(bool reset, std::vector<ui_menu_item>& sliders)
post_effect->add_uniform("ScanlineBrightOffset", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_OFFSET);
post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER);
post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR);
post_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE);
distortion_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING);
distortion_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE);
distortion_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER);
distortion_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER);
distortion_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION);
distortion_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE);
initialized = true;
@ -1656,7 +1654,11 @@ void shaders::render_quad(poly_info *poly, int vertnum)
{
lines_pending = true;
curr_render_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
bool swap_xy = d3d->window().swap_xy();
int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width();
int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height();
curr_render_target = find_render_target(source_width, source_height, 0, 0);
d3d_render_target *rt = curr_render_target;
if (rt == nullptr)
@ -1679,7 +1681,11 @@ void shaders::render_quad(poly_info *poly, int vertnum)
{
curr_screen = curr_screen < num_screens ? curr_screen : 0;
curr_render_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
bool swap_xy = d3d->window().swap_xy();
int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width();
int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height();
curr_render_target = find_render_target(source_width, source_height, 0, 0);
d3d_render_target *rt = curr_render_target;
if (rt == nullptr)
@ -1820,14 +1826,21 @@ d3d_render_target* shaders::get_vector_target(render_primitive *prim)
return nullptr;
}
int target_width = static_cast<int>(prim->get_quad_width() + 0.5f);
int target_height = static_cast<int>(prim->get_quad_height() + 0.5f);
bool swap_xy = d3d->window().swap_xy();
int target_width = swap_xy
? static_cast<int>(prim->get_quad_height() + 0.5f)
: static_cast<int>(prim->get_quad_width() + 0.5f);
int target_height = swap_xy
? static_cast<int>(prim->get_quad_width() + 0.5f)
: static_cast<int>(prim->get_quad_height() + 0.5f);
int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width();
int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height();
target_width *= oversampling_enable ? 2 : 1;
target_height *= oversampling_enable ? 2 : 1;
// find render target and check of the size of the target quad has changed
d3d_render_target *target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
d3d_render_target *target = find_render_target(source_width, source_height, 0, 0);
if (target != nullptr && target->target_width == target_width && target->target_height == target_height)
{
return target;
@ -1840,14 +1853,21 @@ d3d_render_target* shaders::get_vector_target(render_primitive *prim)
void shaders::create_vector_target(render_primitive *prim)
{
int target_width = static_cast<int>(prim->get_quad_width() + 0.5f);
int target_height = static_cast<int>(prim->get_quad_height() + 0.5f);
bool swap_xy = d3d->window().swap_xy();
int target_width = swap_xy
? static_cast<int>(prim->get_quad_height() + 0.5f)
: static_cast<int>(prim->get_quad_width() + 0.5f);
int target_height = swap_xy
? static_cast<int>(prim->get_quad_width() + 0.5f)
: static_cast<int>(prim->get_quad_height() + 0.5f);
int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width();
int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height();
target_width *= oversampling_enable ? 2 : 1;
target_height *= oversampling_enable ? 2 : 1;
osd_printf_verbose("create_vector_target() - %d, %d\n", target_width, target_height);
if (!add_render_target(d3d, nullptr, d3d->get_width(), d3d->get_height(), target_width, target_height))
if (!add_render_target(d3d, nullptr, source_width, source_height, target_width, target_height))
{
vector_enable = false;
}
@ -2587,10 +2607,26 @@ void uniform::update()
}
case CU_SOURCE_DIMS:
{
if (shadersys->curr_texture)
bool vector_screen =
d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR;
if (vector_screen)
{
vec2f sourcedims = shadersys->curr_texture->get_rawdims();
m_shader->set_vector("SourceDims", 2, &sourcedims.c.x);
if (shadersys->curr_render_target)
{
// 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) };
m_shader->set_vector("SourceDims", 2, sourcedims);
}
}
else
{
if (shadersys->curr_texture)
{
vec2f sourcedims = shadersys->curr_texture->get_rawdims();
m_shader->set_vector("SourceDims", 2, &sourcedims.c.x);
}
}
break;
}
@ -2623,35 +2659,6 @@ void uniform::update()
m_shader->set_bool("SwapXY", d3d->window().swap_xy());
break;
}
case CU_ORIENTATION_SWAP:
{
bool orientation_swap_xy =
(d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
m_shader->set_bool("OrientationSwapXY", orientation_swap_xy);
break;
}
case CU_ROTATION_SWAP:
{
bool rotation_swap_xy =
(d3d->window().target()->orientation() & ROT90) == ROT90 ||
(d3d->window().target()->orientation() & ROT270) == ROT270;
m_shader->set_bool("RotationSwapXY", rotation_swap_xy);
break;
}
case CU_ROTATION_TYPE:
{
int rotation_type =
(d3d->window().target()->orientation() & ROT90) == ROT90
? 1
: (d3d->window().target()->orientation() & ROT180) == ROT180
? 2
: (d3d->window().target()->orientation() & ROT270) == ROT270
? 3
: 0;
m_shader->set_int("RotationType", rotation_type);
break;
}
case CU_VECTOR_SCREEN:
{
bool vector_screen =

View File

@ -49,9 +49,6 @@ public:
CU_QUAD_DIMS,
CU_SWAP_XY,
CU_ORIENTATION_SWAP,
CU_ROTATION_SWAP,
CU_ROTATION_TYPE,
CU_VECTOR_SCREEN,
CU_NTSC_CCFREQ,

View File

@ -1398,13 +1398,13 @@ void renderer_d3d9::batch_vectors()
{
windows_options &options = downcast<windows_options &>(window().machine().options());
float quad_width = 0.0f;
float quad_height = 0.0f;
int vector_size = (options.antialias() ? 24 : 6);
m_vectorbatch = mesh_alloc(m_line_count * vector_size);
m_batchindex = 0;
float width = 0.0f;
float height = 0.0f;
static int start_index = 0;
int line_index = 0;
float period = options.screen_vector_time_period();
@ -1432,8 +1432,8 @@ void renderer_d3d9::batch_vectors()
case render_primitive::QUAD:
if (PRIMFLAG_GET_VECTORBUF(prim.flags))
{
width = prim.bounds.x1 - prim.bounds.x0;
height = prim.bounds.y1 - prim.bounds.y0;
quad_width = prim.bounds.x1 - prim.bounds.x0;
quad_height = prim.bounds.y1 - prim.bounds.y0;
}
break;
@ -1443,9 +1443,76 @@ void renderer_d3d9::batch_vectors()
}
}
// handle orientation and rotation for vectors as they were a texture
if (m_shaders->enabled())
{
bool orientation_swap_xy =
(window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool rotation_swap_xy =
(window().target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool swap_xy = orientation_swap_xy ^ rotation_swap_xy;
bool rotation_0 = window().target()->orientation() == ROT0;
bool rotation_90 = window().target()->orientation() == ROT90;
bool rotation_180 = window().target()->orientation() == ROT180;
bool rotation_270 = window().target()->orientation() == ROT270;
bool flip_x =
((rotation_0 || rotation_270) && orientation_swap_xy) ||
((rotation_180 || rotation_270) && !orientation_swap_xy);
bool flip_y =
((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 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;
if (swap_xy)
{
std::swap(screen_quad_ratio_x, screen_quad_ratio_y);
}
for (int batchindex = 0; batchindex < m_batchindex; batchindex++)
{
if (swap_xy)
{
m_vectorbatch[batchindex].x *= screen_swap_x_factor;
m_vectorbatch[batchindex].y *= screen_swap_y_factor;
std::swap(m_vectorbatch[batchindex].x, m_vectorbatch[batchindex].y);
}
if (flip_x)
{
m_vectorbatch[batchindex].x = screen_width - m_vectorbatch[batchindex].x;
}
if (flip_y)
{
m_vectorbatch[batchindex].y = screen_height - m_vectorbatch[batchindex].y;
}
// center
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;
// un-center
m_vectorbatch[batchindex].x += half_screen_width;
m_vectorbatch[batchindex].y += half_screen_height;
}
}
// now add a polygon entry
m_poly[m_numpolys].init(D3DPT_TRIANGLELIST, m_line_count * (options.antialias() ? 8 : 2), vector_size * m_line_count, cached_flags,
m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f, width, height);
m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f, quad_width, quad_height);
m_numpolys++;
start_index += (int)((float)line_index * period);
@ -1470,13 +1537,22 @@ void renderer_d3d9::batch_vector(const render_primitive &prim, float line_time)
render_bounds b0, b1;
render_line_to_quad(&prim.bounds, effwidth, &b0, &b1);
float dx = b1.x1 - b0.x1;
float dy = b1.y1 - b0.y1;
float line_length = sqrtf(dx * dx + dy * dy);
vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart());
vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop());
// iterate over AA steps
for (const line_aa_step *step = PRIMFLAG_GET_ANTIALIAS(prim.flags) ? line_aa_4step : line_aa_1step;
step->weight != 0; step++)
{
// get a pointer to the vertex buffer
if (m_vectorbatch == nullptr)
{
return;
}
m_vectorbatch[m_batchindex + 0].x = b0.x0 + step->xoffs;
m_vectorbatch[m_batchindex + 0].y = b0.y0 + step->yoffs;
@ -1492,10 +1568,6 @@ void renderer_d3d9::batch_vector(const render_primitive &prim, float line_time)
m_vectorbatch[m_batchindex + 5].x = b1.x1 + step->xoffs;
m_vectorbatch[m_batchindex + 5].y = b1.y1 + step->yoffs;
float dx = b1.x1 - b0.x1;
float dy = b1.y1 - b0.y1;
float line_length = sqrtf(dx * dx + dy * dy);
// determine the color of the line
INT32 r = (INT32)(prim.color.r * step->weight * 255.0f);
INT32 g = (INT32)(prim.color.g * step->weight * 255.0f);
@ -1518,9 +1590,6 @@ void renderer_d3d9::batch_vector(const render_primitive &prim, float line_time)
if (a > 255) a = 255;
DWORD color = D3DCOLOR_ARGB(a, r, g, b);
vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart());
vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop());
m_vectorbatch[m_batchindex + 0].u0 = start.c.x;
m_vectorbatch[m_batchindex + 0].v0 = start.c.y;
m_vectorbatch[m_batchindex + 1].u0 = start.c.x;