Previous 199869 Revisions Next

r41781 Tuesday 17th November, 2015 at 18:37:56 UTC by Jezze
Changed screen adjustment for HLSL

- screen adjustment (scale, offset) can now be handled by the respective
render API itself (default behavior is as before)
- D3D (if HLSL) is activated handles screen adjustment by itself within
the shader, which fixes the odd behavior of some effects (e.g. round
corners) when screen scale and offset is used
[hlsl]post.fx
[hlsl/artwork_support]post.fx
[src/emu]render.cpp render.h
[src/osd/modules/render]drawd3d.cpp
[src/osd/modules/render/d3d]d3dhlsl.cpp

trunk/hlsl/artwork_support/post.fx
r250292r250293
152152// Post-Processing Pixel Shader
153153//-----------------------------------------------------------------------------
154154
155uniform float2 ScreenScale = float2(1.0f, 1.0f);
156uniform float2 ScreenOffset = float2(0.0f, 0.0f);
157
155158uniform float ScanlineAlpha = 1.0f;
156159uniform float ScanlineScale = 1.0f;
157160uniform float ScanlineBrightScale = 1.0f;
r250292r250293
334337   return coord;
335338}
336339
340float2 GetAdjustedCoords(float2 coord, float2 centerOffset, float distortionAmount)
341{
342   float2 RatioCorrection = GetRatioCorrection();
343
344   // center coordinates
345   coord -= centerOffset;
346
347   // apply ratio difference between screen and quad
348   coord /= RatioCorrection;
349
350   // applay screen scale
351   coord /= ScreenScale;
352
353   // distort coordinates
354   coord = GetDistortedCoords(coord, distortionAmount);
355
356   // revert ratio difference between screen and quad
357   coord *= RatioCorrection;
358
359   // un-center coordinates
360   coord += centerOffset;
361
362   // apply screen offset
363   coord += (centerOffset * 2.0) * ScreenOffset;
364
365   return coord;
366}
367
337368float4 ps_main(PS_INPUT Input) : COLOR
338369{
339370   float2 ScreenTexelDims = 1.0f / ScreenDims;
r250292r250293
345376   float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
346377   ScreenCoord = GetCoords(ScreenCoord, float2(0.5f, 0.5f), CurvatureAmount);
347378
379   float2 DistortionCoord = Input.TexCoord;
380   DistortionCoord = GetCoords(DistortionCoord, HalfSourceRect, CurvatureAmount);
381
348382   float2 BaseCoord = Input.TexCoord;
349   BaseCoord = GetCoords(BaseCoord, HalfSourceRect, CurvatureAmount);
383   BaseCoord = GetAdjustedCoords(BaseCoord, HalfSourceRect, CurvatureAmount);
350384
385   float2 DistortionCoordCentered = DistortionCoord;
386   DistortionCoordCentered -= HalfSourceRect;
387
351388   float2 BaseCoordCentered = BaseCoord;
352389   BaseCoordCentered -= HalfSourceRect;
353390
354391   float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
355392   BaseColor.a = 1.0f;
356393
394   if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f)
395   {
396      BaseColor.rgb = 0.0f;
397   }
398
357399   // Mask Simulation (may not affect bloom)
358400   if (!PrepareBloom)
359401   {
r250292r250293
431473   // Vignetting Simulation (may not affect bloom)
432474   if (!PrepareBloom)
433475   {
434      float2 VignetteCoord = BaseCoordCentered;
476      float2 VignetteCoord = DistortionCoordCentered;
435477
436478      float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount);
437479      Output.rgb *= VignetteFactor;
r250292r250293
442484   {
443485      float3 LightColor = float3(1.0f, 0.90f, 0.80f);
444486
445      float2 SpotCoord = BaseCoordCentered;
446      float2 NoiseCoord = BaseCoordCentered;
487      float2 SpotCoord = DistortionCoordCentered;
488      float2 NoiseCoord = DistortionCoordCentered;
447489
448490      float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount);
449491      float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord));
r250292r250293
451493   }
452494
453495   // Round Corners Simulation (may affect bloom)
454   float2 RoundCornerCoord = BaseCoordCentered;
496   float2 RoundCornerCoord = DistortionCoordCentered;
455497
456498   float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount);
457499   Output.rgb *= roundCornerFactor;
trunk/hlsl/post.fx
r250292r250293
7777
7878uniform float2 ScreenDims; // size of the window or fullscreen
7979uniform float2 SourceDims; // size of the texture in power-of-two size
80uniform float2 SourceRect; // size of the uv rectangle
8081uniform float2 TargetDims; // size of the target surface
8182
8283uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size)
r250292r250293
124125// Post-Processing Pixel Shader
125126//-----------------------------------------------------------------------------
126127
128uniform float2 ScreenScale = float2(1.0f, 1.0f);
129uniform float2 ScreenOffset = float2(0.0f, 0.0f);
130
127131uniform float ScanlineAlpha = 1.0f;
128132uniform float ScanlineScale = 1.0f;
129133uniform float ScanlineBrightScale = 1.0f;
r250292r250293
138142uniform float3 Power = float3(1.0f, 1.0f, 1.0f);
139143uniform float3 Floor = float3(0.0f, 0.0f, 0.0f);
140144
145float2 GetAdjustedCoords(float2 coord, float2 centerOffset)
146{
147   // center coordinates
148   coord -= centerOffset;
149
150   // apply screen scale
151   coord /= ScreenScale;
152
153   // un-center coordinates
154   coord += centerOffset;
155
156   // apply screen offset
157   coord += (centerOffset * 2.0) * ScreenOffset;
158
159   return coord;
160}
161
141162float4 ps_main(PS_INPUT Input) : COLOR
142163{
143164   float2 ScreenTexelDims = 1.0f / ScreenDims;
144165
166   float2 HalfSourceRect = PrepareVector
167      ? float2(0.5f, 0.5f)
168      : SourceRect * 0.5f;
169
145170   float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
146   float2 BaseCoord = Input.TexCoord;
171   float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect);
147172
148173   // Color
149174   float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
150175   BaseColor.a = 1.0f;
151176
177   if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f)
178   {
179      BaseColor.rgb = 0.0f;
180   }
181
152182   // Mask Simulation (may not affect bloom)
153183   if (!PrepareBloom)
154184   {
trunk/src/emu/render.cpp
r250292r250293
924924      m_base_view(NULL),
925925      m_base_orientation(ROT0),
926926      m_maxtexwidth(65536),
927      m_maxtexheight(65536)
927      m_maxtexheight(65536),
928      m_scale_primitives(true),
929      m_offset_primitives(true)
928930{
929931   // determine the base layer configuration based on options
930932   m_base_layerconfig.set_backdrops_enabled(manager.machine().options().use_backdrops());
r250292r250293
16591661      float yoffs = (container_xform.orientation & ORIENTATION_SWAP_XY) ? container.xoffset() : container.yoffset();
16601662      if (container_xform.orientation & ORIENTATION_FLIP_X) xoffs = -xoffs;
16611663      if (container_xform.orientation & ORIENTATION_FLIP_Y) yoffs = -yoffs;
1664      if (!m_scale_primitives)
1665      {
1666         xscale = 1.0f;
1667         yscale = 1.0f;
1668      }
1669      if (!m_offset_primitives)
1670      {
1671         xoffs = 0.0f;
1672         yoffs = 0.0f;
1673      }
16621674      container_xform.xscale = xform.xscale * xscale;
16631675      container_xform.yscale = xform.yscale * yscale;
16641676      if (xform.no_center)
trunk/src/emu/render.h
r250292r250293
898898   void set_orientation(int orientation) { m_orientation = orientation; }
899899   void set_view(int viewindex);
900900   void set_max_texture_size(int maxwidth, int maxheight);
901   void set_scale_primitives(bool enable) { m_scale_primitives = enable; }
902   void set_offset_primitives(bool enable) { m_offset_primitives = enable; }
901903
902904   // layer config getters
903905   bool backdrops_enabled() const { return m_layerconfig.backdrops_enabled(); }
r250292r250293
996998   simple_list<render_container> m_debug_containers;   // list of debug containers
997999   INT32                   m_clear_extent_count;       // number of clear extents
9981000   INT32                   m_clear_extents[MAX_CLEAR_EXTENTS]; // array of clear extents
1001   bool                    m_scale_primitives;         // determines if the primitive shall be scaled/offset by screen settings,
1002   bool                    m_offset_primitives;        // otherwise the respective render API will handle it (default is true)
9991003
10001004   static render_screen_list s_empty_screen_list;
10011005};
trunk/src/osd/modules/render/d3d/d3dhlsl.cpp
r250292r250293
964964   color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION);
965965
966966   prescale_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
967   prescale_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
968
967   
969968   deconverge_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
970969   deconverge_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
971970   deconverge_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
r250292r250293
988987   bloom_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
989988
990989   post_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
991   post_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT); // backward compatibility
990   post_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
992991   post_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
993992   post_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
994993   post_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); // backward compatibility
r250292r250293
13711370               ? 3
13721371               : 0;
13731372
1373   render_container &screen_container = machine->first_screen()->container();
1374
1375   float xscale = screen_container.xscale();
1376   float yscale = screen_container.yscale();
1377   float xoffset = -screen_container.xoffset();
1378   float yoffset = -screen_container.yoffset();     
1379
1380   float screen_scale[2] = { xscale, yscale };
1381   float screen_offset[2] = { xoffset, yoffset };   
1382
13741383   curr_effect = post_effect;
13751384   curr_effect->update_uniforms();
13761385   curr_effect->set_texture("ShadowTexture", shadow_texture == NULL ? NULL : shadow_texture->get_finaltex());
13771386   curr_effect->set_texture("DiffuseTexture", rt->prescale_texture[next_index]);
1387   curr_effect->set_vector("ScreenScale", 2, screen_scale);
1388   curr_effect->set_vector("ScreenOffset", 2, screen_offset);
13781389   curr_effect->set_float("ScanlineOffset", texture->get_cur_frame() == 0 ? 0.0f : options->scanline_offset);
13791390   curr_effect->set_bool("OrientationSwapXY", orientation_swap_xy);
13801391   curr_effect->set_bool("RotationSwapXY", rotation_swap_xy);
trunk/src/osd/modules/render/drawd3d.cpp
r250292r250293
245245      window().target()->set_bounds(rect_width(&client), rect_height(&client), window().aspect());
246246      window().target()->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh());
247247   }
248   if (m_shaders != NULL)
249   {
250      window().target()->set_scale_primitives(!m_shaders->enabled());
251      window().target()->set_offset_primitives(!m_shaders->enabled());
252   }
248253   return &window().target()->get_primitives();
249254}
250255


Previous 199869 Revisions Next


© 1997-2024 The MAME Team