Skip to content

Commit

Permalink
Fix #51: Only apply postprocessing to the final camera, and add a sec…
Browse files Browse the repository at this point in the history
…ond antialising mode to be used in cameras other than the local space (main) one.
  • Loading branch information
JonnyOThan committed Jul 11, 2024
1 parent 730cbbd commit dc69ca0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
2 changes: 2 additions & 0 deletions GameData/TUFX/Profiles/TUFX-Default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ TUFX_PROFILE
name = Default-Flight
hdr = True
antialiasing = TemporalAntialiasing
secondaryAntialiasing = FastApproximateAntialiasing

EFFECT
{
name = AmbientOcclusion
Expand Down
28 changes: 7 additions & 21 deletions Plugin/TUFX/Addon/TexturesUnlimitedFXLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostProcessLayer>();
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()
Expand Down
16 changes: 10 additions & 6 deletions Plugin/TUFX/GUI/ConfigurationGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -633,28 +633,32 @@ private void AddEnumParameter<Tenum>(string label, ParameterOverride<Tenum> para
GUILayout.EndHorizontal();
}

private void AddEnumField<Tenum>(string label, ref Tenum param)
private bool 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));
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)))
{
index++;
if (index >= values.Length) { index = 0; }
param = (values[index]);
changed = true;
}
GUILayout.EndHorizontal();
return changed;
}

private void AddBoolParameter(string label, ParameterOverride<bool> param)
Expand Down
6 changes: 5 additions & 1 deletion Plugin/TUFX/TUFXProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public class TUFXProfile
/// <summary>
/// Configured AntiAliasing setting for the profile.
/// </summary>
public PostProcessLayer.Antialiasing AntiAliasing { get; set; }
public PostProcessLayer.Antialiasing AntiAliasing;

public PostProcessLayer.Antialiasing SecondaryCameraAntialiasing;

private UrlDir.UrlConfig urlConfig;

Expand All @@ -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++)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dc69ca0

Please sign in to comment.