Skip to content

Commit 1116dd4

Browse files
authored
Merge pull request #383 from YoRyan/antialiasing
Add a video options setting for MultiSampleCount anti-aliasing
2 parents 0630a02 + 2c201ae commit 1116dd4

File tree

5 files changed

+157
-11
lines changed

5 files changed

+157
-11
lines changed

Source/Documentation/Manual/options.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,17 @@ Ambient daylight brightness
367367

368368
With this slider you can set the daylight brightness.
369369

370+
Anti-aliasing
371+
-------------
372+
373+
Controls the anti-aliasing method used by Open Rails. Anti-aliasing is a
374+
computer graphics technique that smooths any harsh edges, otherwise known as
375+
"jaggies," present in the video image. Currently, Open Rails only supports the
376+
multisample anti-aliasing (MSAA) method. Higher applications of anti-aliasing
377+
will require exponentially more graphics computing power.
378+
379+
The default setting is MSAA with 2x sampling.
380+
370381
.. _options-simulation:
371382

372383
Simulation Options

Source/Menu/Options.Designer.cs

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/Options.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ public OptionsForm(UserSettings settings, UpdateManager updateManager, bool init
179179
comboWindowSize.Text = Settings.WindowSize;
180180
trackDayAmbientLight.Value = Settings.DayAmbientLight;
181181
trackDayAmbientLight_ValueChanged(null, null);
182+
trackAntiAliasing.Value = Settings.AntiAliasing;
183+
trackAntiAliasing_ValueChanged(null, null);
182184
checkDoubleWire.Checked = Settings.DoubleWire;
183185

184186
// Simulation tab
@@ -467,6 +469,7 @@ void buttonOK_Click(object sender, EventArgs e)
467469

468470
Settings.DayAmbientLight = (int)trackDayAmbientLight.Value;
469471
Settings.DoubleWire = checkDoubleWire.Checked;
472+
Settings.AntiAliasing = trackAntiAliasing.Value;
470473

471474
// Simulation tab
472475
Settings.SimpleControlPhysics = checkSimpleControlsPhysics.Checked;
@@ -627,6 +630,36 @@ private void trackDayAmbientLight_ValueChanged(object sender, EventArgs e)
627630
labelDayAmbientLight.Text = catalog.GetStringFmt("{0}%", trackDayAmbientLight.Value * 5);
628631
}
629632

633+
private void trackAntiAliasing_ValueChanged(object sender, EventArgs e)
634+
{
635+
string method;
636+
switch ((UserSettings.AntiAliasingMethod)trackAntiAliasing.Value)
637+
{
638+
case UserSettings.AntiAliasingMethod.None:
639+
method = "Disabled";
640+
break;
641+
case UserSettings.AntiAliasingMethod.MSAA2x:
642+
method = "2x MSAA";
643+
break;
644+
case UserSettings.AntiAliasingMethod.MSAA4x:
645+
method = "4x MSAA";
646+
break;
647+
case UserSettings.AntiAliasingMethod.MSAA8x:
648+
method = "8x MSAA";
649+
break;
650+
case UserSettings.AntiAliasingMethod.MSAA16x:
651+
method = "16x MSAA";
652+
break;
653+
case UserSettings.AntiAliasingMethod.MSAA32x:
654+
method = "32x MSAA";
655+
break;
656+
default:
657+
method = "";
658+
break;
659+
}
660+
labelAntiAliasingValue.Text = method;
661+
}
662+
630663
private void trackLODBias_ValueChanged(object sender, EventArgs e)
631664
{
632665
if (trackLODBias.Value == -100)

Source/ORTS.Settings/UserSettings.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ public enum Menu_SelectionIndex
9090
}
9191
#endregion
9292

93+
/// <summary>
94+
/// Specifies an anti-aliasing method. Currently, Monogame's MSAA is the only supported method.
95+
/// </summary>
96+
public enum AntiAliasingMethod
97+
{
98+
/// <summary>
99+
/// No antialiasing
100+
/// </summary>
101+
None = 1,
102+
/// <summary>
103+
/// 2x multisampling
104+
/// </summary>
105+
MSAA2x = 2,
106+
/// <summary>
107+
/// 4x multisampling
108+
/// </summary>
109+
MSAA4x = 3,
110+
/// <summary>
111+
/// 8x multisampling
112+
/// </summary>
113+
MSAA8x = 4,
114+
/// <summary>
115+
/// 16x multisampling
116+
/// </summary>
117+
MSAA16x = 5,
118+
/// <summary>
119+
/// 32x multisampling
120+
/// </summary>
121+
MSAA32x = 6,
122+
}
123+
93124
public enum DirectXFeature
94125
{
95126
Level9_1,
@@ -195,6 +226,8 @@ public enum DirectXFeature
195226
public string WindowSize { get; set; }
196227
[Default(20)]
197228
public int DayAmbientLight { get; set; }
229+
[Default(AntiAliasingMethod.MSAA2x)]
230+
public int AntiAliasing { get; set; }
198231

199232
// Simulation settings:
200233

Source/RunActivity/Viewer3D/Processes/RenderProcess.cs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System;
2525
using System.Diagnostics;
2626
using System.Windows.Forms;
27+
using static ORTS.Settings.UserSettings;
2728

2829
namespace Orts.Viewer3D.Processes
2930
{
@@ -98,7 +99,7 @@ internal RenderProcess(Game game)
9899
GraphicsDeviceManager.PreferredBackBufferFormat = SurfaceFormat.Color;
99100
GraphicsDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
100101
GraphicsDeviceManager.IsFullScreen = Game.Settings.FullScreen;
101-
GraphicsDeviceManager.PreferMultiSampling = true;
102+
GraphicsDeviceManager.PreferMultiSampling = (AntiAliasingMethod)Game.Settings.AntiAliasing != AntiAliasingMethod.None;
102103
GraphicsDeviceManager.HardwareModeSwitch = !Game.Settings.FastFullScreenAltTab;
103104
GraphicsDeviceManager.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(GDM_PreparingDeviceSettings);
104105
}
@@ -118,19 +119,38 @@ void GDM_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs
118119

119120
e.GraphicsDeviceInformation.GraphicsProfile = e.GraphicsDeviceInformation.Adapter.IsProfileSupported(GraphicsProfile.HiDef) ? GraphicsProfile.HiDef : GraphicsProfile.Reach;
120121

121-
// TODO: XNA defaults to lowest multisample anti-aliasing quality (2x), so we'll do the same here until we add a setting for it.
122-
e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 2;
123-
124-
if (e.GraphicsDeviceInformation.PresentationParameters.IsFullScreen)
122+
var pp = e.GraphicsDeviceInformation.PresentationParameters;
123+
switch ((AntiAliasingMethod)Game.Settings.AntiAliasing)
124+
{
125+
case AntiAliasingMethod.None:
126+
default:
127+
break;
128+
case AntiAliasingMethod.MSAA2x:
129+
pp.MultiSampleCount = 2;
130+
break;
131+
case AntiAliasingMethod.MSAA4x:
132+
pp.MultiSampleCount = 4;
133+
break;
134+
case AntiAliasingMethod.MSAA8x:
135+
pp.MultiSampleCount = 8;
136+
break;
137+
case AntiAliasingMethod.MSAA16x:
138+
pp.MultiSampleCount = 16;
139+
break;
140+
case AntiAliasingMethod.MSAA32x:
141+
pp.MultiSampleCount = 32;
142+
break;
143+
}
144+
if (pp.IsFullScreen)
125145
{
126146
var screen = Screen.FromControl(GameForm);
127-
e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = screen.Bounds.Width;
128-
e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = screen.Bounds.Height;
147+
pp.BackBufferWidth = screen.Bounds.Width;
148+
pp.BackBufferHeight = screen.Bounds.Height;
129149
}
130150
else
131151
{
132-
e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = GameWindowSize.X;
133-
e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = GameWindowSize.Y;
152+
pp.BackBufferWidth = GameWindowSize.X;
153+
pp.BackBufferHeight = GameWindowSize.Y;
134154
}
135155
}
136156

@@ -141,7 +161,7 @@ internal void Start()
141161
DisplaySize = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
142162

143163
// Validate that the DirectX feature level is one we understand
144-
if (!Enum.IsDefined(typeof(ORTS.Settings.UserSettings.DirectXFeature), "Level" + Game.Settings.DirectXFeatureLevel))
164+
if (!Enum.IsDefined(typeof(DirectXFeature), "Level" + Game.Settings.DirectXFeatureLevel))
145165
Game.Settings.DirectXFeatureLevel = "";
146166

147167
if (Game.Settings.DirectXFeatureLevel == "")
@@ -159,7 +179,7 @@ internal void Start()
159179
ShadowMapCount = Game.Settings.ShadowMapCount;
160180
if (!Game.Settings.DynamicShadows)
161181
ShadowMapCount = 0;
162-
else if ((ShadowMapCount > 1) && !Game.Settings.IsDirectXFeatureLevelIncluded(ORTS.Settings.UserSettings.DirectXFeature.Level9_3))
182+
else if ((ShadowMapCount > 1) && !Game.Settings.IsDirectXFeatureLevelIncluded(DirectXFeature.Level9_3))
163183
ShadowMapCount = 1;
164184
else if (ShadowMapCount < 0)
165185
ShadowMapCount = 0;

0 commit comments

Comments
 (0)