Skip to content

Commit

Permalink
add antialiasing mode setting to config UI, to profile, and to saved/…
Browse files Browse the repository at this point in the history
…loaded persistence data
  • Loading branch information
shadowmage45 committed Mar 8, 2020
1 parent 7b936d8 commit 1f97155
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 9 deletions.
Binary file modified GameData/TUFX/Plugins/TUFX.dll
Binary file not shown.
Binary file modified GameData/TUFX/Plugins/TUFX.pdb
Binary file not shown.
25 changes: 24 additions & 1 deletion Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,11 @@ internal void enableProfile(string profileName)
{
Log.log("Enabling profile: " + profileName + ". Current GameScene: " + HighLogic.LoadedScene);
TUFXProfile tufxProfile = Profiles[profileName];
currentProfile = tufxProfile;
Log.debug("Profile (hashcode): " + tufxProfile?.GetHashCode() + " :: "+tufxProfile?.ProfileName);
Log.log("Setting HDR for camera: " + activeCam.name + " to: " + tufxProfile.HDREnabled);
activeCam.allowHDR = tufxProfile.HDREnabled;
onAntiAliasingSelected(tufxProfile.AntiAliasing, false);
layer = activeCam.gameObject.AddOrGetComponent<PostProcessLayer>();
layer.Init(Resources);
layer.volumeLayer = ~0;//everything //TODO -- fix layer assignment...
Expand All @@ -552,7 +554,6 @@ internal void enableProfile(string profileName)
tufxProfile.Enable(volume);
}
Log.log("Profile enabled: " + profileName);
currentProfile = tufxProfile;
}
else if (string.IsNullOrEmpty(profileName))
{
Expand Down Expand Up @@ -583,6 +584,28 @@ internal void onHDRToggled()
}
}

internal void onAntiAliasingSelected(PostProcessLayer.Antialiasing mode, bool updateProfile)
{
if (updateProfile && CurrentProfile != null)
{
Log.debug("Updated profile AA value to: " + mode);
CurrentProfile.AntiAliasing = mode;
}
else if(updateProfile)
{
Log.exception("Profile was null when attempting to update AA mode.");
}
if (layer != null)
{
Log.debug("Updated post process layer AA value to: " + mode);
layer.antialiasingMode = mode;
}
else
{
Log.exception("Layer was null when attempting to update AA mode.");
}
}

/// <summary>
/// Callback for when the ApplicationLauncher button is clicked.
/// </summary>
Expand Down
70 changes: 68 additions & 2 deletions Plugin/TUFX/GUI/ConfigurationGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void renderConfigurationWindow()
GUILayout.EndHorizontal();
GUI.contentColor = c;
editScrollPos = GUILayout.BeginScrollView(editScrollPos, false, true);
renderHDRSettings();
renderGeneralSettings();
renderAmbientOcclusionSettings();
renderAutoExposureSettings();
renderBloomSettings();
Expand Down Expand Up @@ -239,10 +239,36 @@ private void initializeTextureSelectMode(string effectName, string propertyName,

#region REGION Effect Settings Rendering

private void renderGeneralSettings()
{
string hash = this.GetHashCode().ToString();
if (!effectBoolStorage.TryGetValue(hash, out bool showProps))
{
showProps = true;
effectBoolStorage.Add(hash, true);
}
GUILayout.BeginHorizontal();
GUILayout.Label("----- General Settings", GUILayout.Width(300));
if (GUILayout.Button((showProps ? "Hide Props" : "Show Props"), GUILayout.Width(110)))
{
showProps = !showProps;
effectBoolStorage[hash] = showProps;
}
GUILayout.EndHorizontal();
if (showProps)
{
renderHDRSettings();
renderAntialiasingSettings();
}
GUILayout.BeginHorizontal();
GUILayout.Label("---------------------------------------");
GUILayout.EndHorizontal();
}

private void renderHDRSettings()
{
GUILayout.BeginHorizontal();
GUILayout.Label("----- HDR", GUILayout.Width(200));
GUILayout.Label("HDR", GUILayout.Width(200));
bool enabled = TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.HDREnabled;
if (enabled) //if it is enabled, draw button to disable it
{
Expand All @@ -261,6 +287,22 @@ private void renderHDRSettings()
GUILayout.EndHorizontal();
}

private void renderAntialiasingSettings()
{
PostProcessLayer.Antialiasing mode = TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing;
AddEnumField("AntiAliasing Mode", ref mode);
if (mode != TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing)
{
TexturesUnlimitedFXLoader.INSTANCE.onAntiAliasingSelected(mode, true);
}
//TODO -- add parameters for the AA modes
//if (mode == PostProcessLayer.Antialiasing.FastApproximateAntialiasing)
//{
// //AddBoolField("FXAA Fast Mode", ref layer.fastApproximageAntialiasing.fastMode);
// //AddBoolField("FXAA Keep Alpha", ref layer.fastApproximageAntialiasing.keepAlpha);
//}
}

private void renderAmbientOcclusionSettings()
{
AmbientOcclusion ao = TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.GetSettingsFor<AmbientOcclusion>();
Expand Down Expand Up @@ -597,6 +639,30 @@ private void AddEnumParameter<Tenum>(string label, ParameterOverride<Tenum> para
GUILayout.EndHorizontal();
}

private void AddEnumField<Tenum>(string label, ref Tenum param)
{
Tenum value = param;
Type type = value.GetType();
Tenum[] values = (Tenum[])Enum.GetValues(type);
int index = values.IndexOf(value);
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(300));
if (GUILayout.Button("<", GUILayout.Width(110)))
{
index--;
if (index < 0) { index = values.Length - 1; }
param = (values[index]);
}
GUILayout.Label(value.ToString(), GUILayout.Width(220));
if (GUILayout.Button(">", GUILayout.Width(110)))
{
index++;
if (index >= values.Length) { index = 0; }
param = (values[index]);
}
GUILayout.EndHorizontal();
}

private void AddBoolParameter(string label, ParameterOverride<bool> param)
{
GUILayout.BeginHorizontal();
Expand Down
4 changes: 2 additions & 2 deletions Plugin/TUFX/PostProcessing/Effects/ColorGrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ public override bool IsEnabledAndSupported(PostProcessRenderContext context)

public override void Load(ConfigNode config)
{
if (config.HasValue("GradingMode")) { gradingMode.Override(config.GetEnumValue<GradingMode>("GradingMode", typeof(GradingMode))); }
if (config.HasValue("GradingMode")) { gradingMode.Override(config.GetEnumValue<GradingMode>("GradingMode", GradingMode.HighDefinitionRange)); }
loadTextureParameter(config, "ExternalLut", externalLut);
if (config.HasValue("Tonemapper")) { tonemapper.Override(config.GetEnumValue<Tonemapper>("Tonemapper", typeof(Tonemapper))); }
if (config.HasValue("Tonemapper")) { tonemapper.Override(config.GetEnumValue<Tonemapper>("Tonemapper", Tonemapper.None)); }
loadFloatParameter(config, "ToneCurveToeStrength", toneCurveToeStrength);
loadFloatParameter(config, "ToneCurveToeLength", toneCurveToeLength);
loadFloatParameter(config, "ToneCurveShoulderStrength", toneCurveShoulderStrength);
Expand Down
12 changes: 10 additions & 2 deletions Plugin/TUFX/TUFXProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public class TUFXProfile
/// </summary>
public bool HDREnabled { get; set; }

/// <summary>
/// Configured AntiAliasing setting for the profile.
/// </summary>
public PostProcessLayer.Antialiasing AntiAliasing { get; set; }

/// <summary>
/// List of the override settings currently configured for this profile
/// </summary>
Expand Down Expand Up @@ -131,6 +136,7 @@ public void SaveProfile(ConfigNode node)
node.SetValue("name", ProfileName, true);
}
node.SetValue("hdr", HDREnabled, true);
node.SetValue("antialiasing", AntiAliasing.ToString(), true);
int len = Settings.Count;
for (int i = 0; i < len; i++)
{
Expand All @@ -153,7 +159,8 @@ public void SaveProfile(ConfigNode node)
public static void SaveProfile(PostProcessProfile profile, ConfigNode node)
{
node.SetValue("name", profile.name, true);
node.SetValue("hdr", true, true);
node.SetValue("hdr", false, true);
node.SetValue("antialiasing", PostProcessLayer.Antialiasing.None.ToString());
int len = profile.settings.Count;
for (int i = 0; i < len; i++)
{
Expand All @@ -175,12 +182,13 @@ public void LoadProfile(ConfigNode node)
{
ProfileName = node.GetStringValue("name");
HDREnabled = node.GetBoolValue("hdr", false);
AntiAliasing = node.GetEnumValue("antialiasing", PostProcessLayer.Antialiasing.None);
Settings.Clear();
ConfigNode[] effectNodes = node.GetNodes("EFFECT");
int len = effectNodes.Length;
for (int i = 0; i < len; i++)
{
BuiltinEffect effect = effectNodes[i].GetEnumValue<BuiltinEffect>("name", typeof(BuiltinEffect));
BuiltinEffect effect = effectNodes[i].GetEnumValue("name", BuiltinEffect.AmbientOcclusion);
PostProcessEffectSettings set = TUFXProfileManager.CreateEmptySettingsForEffect(effect);
set.enabled.Override(true);
set.Load(effectNodes[i]);
Expand Down
13 changes: 11 additions & 2 deletions Plugin/TUFX/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,19 @@ public static Color getColorFromByteValues(this ConfigNode node, string name)
return color;
}

public static T GetEnumValue<T>(this ConfigNode node, string name, Type enumType)
public static T GetEnumValue<T>(this ConfigNode node, string name, T defaultValue)
{
string value = node.GetStringValue(name);
return (T)Enum.Parse(enumType, value);
if (string.IsNullOrEmpty(value)) { return defaultValue; }
try
{
return (T)Enum.Parse(defaultValue.GetType(), value);
}
catch (Exception e)
{
Log.debug(e.ToString());
return defaultValue;
}
}
#endregion

Expand Down

0 comments on commit 1f97155

Please sign in to comment.