From dc69ca0fede58f86f4e363ebadb5f0ffdd05d5e2 Mon Sep 17 00:00:00 2001 From: Jon Cable Date: Thu, 11 Jul 2024 16:52:47 -0400 Subject: [PATCH] Fix #51: Only apply postprocessing to the final camera, and add a second antialising mode to be used in cameras other than the local space (main) one. --- GameData/TUFX/Profiles/TUFX-Default.cfg | 2 ++ .../TUFX/Addon/TexturesUnlimitedFXLoader.cs | 28 +++++-------------- Plugin/TUFX/GUI/ConfigurationGUI.cs | 16 +++++++---- Plugin/TUFX/TUFXProfile.cs | 6 +++- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/GameData/TUFX/Profiles/TUFX-Default.cfg b/GameData/TUFX/Profiles/TUFX-Default.cfg index 6ba7c84..ee086e0 100644 --- a/GameData/TUFX/Profiles/TUFX-Default.cfg +++ b/GameData/TUFX/Profiles/TUFX-Default.cfg @@ -103,6 +103,8 @@ TUFX_PROFILE name = Default-Flight hdr = True antialiasing = TemporalAntialiasing + secondaryAntialiasing = FastApproximateAntialiasing + EFFECT { name = AmbientOcclusion diff --git a/Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs b/Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs index 7c853cd..4ed28ad 100644 --- a/Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs +++ b/Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs @@ -538,31 +538,17 @@ private void ApplyProfileToCamera(Camera camera, TUFXProfile tufxProfile, bool i { if (camera == null) return; + bool isPrimaryCamera = object.ReferenceEquals(camera, Camera.main); + var layer = camera.gameObject.AddOrGetComponent(); layer.Init(Resources); camera.allowHDR = tufxProfile.HDREnabled; - // this seems to work for bloom and color grading, but in IVA using SMAA or FXAA affects the terrain while TAA does not - // haven't tested orbit or map yet - layer.volumeLayer = isFinalCamera ? 1 : 0; - layer.antialiasingMode = isFinalCamera ? tufxProfile.AntiAliasing : PostProcessLayer.Antialiasing.None; - layer.enabled = isFinalCamera; - - /* - if (isFinalCamera) - { - layer.breakBeforeColorGrading = false; - layer.antialiasingMode = tufxProfile.AntiAliasing; - } - else - { - layer.breakBeforeColorGrading = true; - layer.antialiasingMode = tufxProfile.AntiAliasing == PostProcessLayer.Antialiasing.TemporalAntialiasing - ? PostProcessLayer.Antialiasing.None - : tufxProfile.AntiAliasing; - - } - */ + // In general all postprocessing should be done on the "final" camera - local when in flight, internal when in IVA, etc. + // But we don't want to apply TAA (and possibly motion blur and DoF) to anything but the local space camera since + // motion vectors aren't shared between cameras, and applying TAA on multiple cameras will produce smearing + layer.volumeLayer = isFinalCamera ? 1 : 0; + layer.antialiasingMode = isPrimaryCamera ? tufxProfile.AntiAliasing : tufxProfile.SecondaryCameraAntialiasing; } private void ApplyCurrentProfile() diff --git a/Plugin/TUFX/GUI/ConfigurationGUI.cs b/Plugin/TUFX/GUI/ConfigurationGUI.cs index 418c87e..b1376ec 100644 --- a/Plugin/TUFX/GUI/ConfigurationGUI.cs +++ b/Plugin/TUFX/GUI/ConfigurationGUI.cs @@ -312,12 +312,12 @@ private void renderHDRSettings() private void renderAntialiasingSettings() { - PostProcessLayer.Antialiasing mode = TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing; - AddEnumField("AntiAliasing Mode", ref mode); - if (mode != TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing) + bool primaryChanged = AddEnumField("Primary Camera Antialiasing", ref TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing); + bool secondaryChanged = AddEnumField("Secondary Camera Antialiasing", ref TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.SecondaryCameraAntialiasing); + + if (primaryChanged || secondaryChanged) { - TexturesUnlimitedFXLoader.INSTANCE.CurrentProfile.AntiAliasing = mode; - TexturesUnlimitedFXLoader.INSTANCE.RefreshCameras(); + TexturesUnlimitedFXLoader.INSTANCE.RefreshCameras(); } //TODO -- add parameters for the AA modes //if (mode == PostProcessLayer.Antialiasing.FastApproximateAntialiasing) @@ -633,7 +633,7 @@ private void AddEnumParameter(string label, ParameterOverride para GUILayout.EndHorizontal(); } - private void AddEnumField(string label, ref Tenum param) + private bool AddEnumField(string label, ref Tenum param) { Tenum value = param; Type type = value.GetType(); @@ -641,11 +641,13 @@ private void AddEnumField(string label, ref Tenum param) int index = values.IndexOf(value); GUILayout.BeginHorizontal(); GUILayout.Label(label, GUILayout.Width(300)); + bool changed = false; if (GUILayout.Button("<", GUILayout.Width(110))) { index--; if (index < 0) { index = values.Length - 1; } param = (values[index]); + changed = true; } GUILayout.Label(value.ToString(), GUILayout.Width(220)); if (GUILayout.Button(">", GUILayout.Width(110))) @@ -653,8 +655,10 @@ private void AddEnumField(string label, ref Tenum param) index++; if (index >= values.Length) { index = 0; } param = (values[index]); + changed = true; } GUILayout.EndHorizontal(); + return changed; } private void AddBoolParameter(string label, ParameterOverride param) diff --git a/Plugin/TUFX/TUFXProfile.cs b/Plugin/TUFX/TUFXProfile.cs index ee462b8..9ccfb20 100644 --- a/Plugin/TUFX/TUFXProfile.cs +++ b/Plugin/TUFX/TUFXProfile.cs @@ -101,7 +101,9 @@ public class TUFXProfile /// /// Configured AntiAliasing setting for the profile. /// - public PostProcessLayer.Antialiasing AntiAliasing { get; set; } + public PostProcessLayer.Antialiasing AntiAliasing; + + public PostProcessLayer.Antialiasing SecondaryCameraAntialiasing; private UrlDir.UrlConfig urlConfig; @@ -128,6 +130,7 @@ ConfigNode SaveToNode() node.SetValue("name", ProfileName, true); node.SetValue("hdr", HDREnabled, true); node.SetValue("antialiasing", AntiAliasing.ToString(), true); + node.SetValue("secondaryAntialiasing", SecondaryCameraAntialiasing.ToString(), true); int len = Settings.Count; for (int i = 0; i < len; i++) { @@ -173,6 +176,7 @@ void LoadProfile(ConfigNode node) ProfileName = node.GetStringValue("name"); HDREnabled = node.GetBoolValue("hdr", false); AntiAliasing = node.GetEnumValue("antialiasing", PostProcessLayer.Antialiasing.None); + SecondaryCameraAntialiasing = node.GetEnumValue("secondaryAntialiasing", PostProcessLayer.Antialiasing.None); Settings.Clear(); ConfigNode[] effectNodes = node.GetNodes("EFFECT"); int len = effectNodes.Length;