[BetterShadowClone] Added DontRespectFPR setting

This commit is contained in:
NotAKidoS 2024-02-03 04:14:17 -06:00
parent 829ad55195
commit 0d82606308
6 changed files with 45 additions and 24 deletions

View file

@ -24,6 +24,10 @@ public static class ModSettings
Category.CreateEntry("Copy Material to Shadow", true,
description: "Should the shadow clone copy the material from the original mesh? Note: This can have a slight performance hit.");
internal static readonly MelonPreferences_Entry<bool> EntryDontRespectFPR =
Category.CreateEntry("Dont Respect FPR", false,
description: "Should the transform hider not respect FPR?");
internal static readonly MelonPreferences_Entry<bool> EntryDebugHeadHide =
Category.CreateEntry("Debug Head Hide", false,
description: "Should head be hidden for first render?");
@ -39,6 +43,7 @@ public static class ModSettings
private static void OnSettingsChanged(object oldValue = null, object newValue = null)
{
TransformHiderManager.s_DisallowFprExclusions = EntryDontRespectFPR.Value;
TransformHiderManager.s_DebugHeadHide = EntryDebugHeadHide.Value;
ShadowCloneManager.s_CopyMaterialsToShadow = EntryCopyMaterialToShadow.Value;
}

View file

@ -10,9 +10,7 @@ public class FPRExclusion : MonoBehaviour
{
public Transform target;
internal List<Transform> affectedChildren = new();
[NonSerialized]
internal readonly List<Transform> affectedChildren = new();
internal readonly List<IFPRExclusionTask> relatedTasks = new();
private void OnEnable()

View file

@ -6,6 +6,6 @@ public interface ITransformHider : IDisposable
bool IsValid { get; }
bool Process();
bool PostProcess();
void HideTransform();
void HideTransform(bool forced = false);
void ShowTransform();
}

View file

@ -16,6 +16,9 @@ public class MeshTransformHider : ITransformHider, IFPRExclusionTask
private readonly MeshRenderer _mainMesh;
private bool _enabledState;
// exclusion
private readonly FPRExclusion _exclusion;
#region ITransformHider Methods
public bool IsActive { get; set; } = true; // default hide, but FPRExclusion can override
@ -34,7 +37,8 @@ public class MeshTransformHider : ITransformHider, IFPRExclusionTask
return;
}
exclusion.relatedTasks.Add(this);
_exclusion = exclusion;
_exclusion.relatedTasks.Add(this);
_mainMesh = renderer;
@ -73,12 +77,13 @@ public class MeshTransformHider : ITransformHider, IFPRExclusionTask
}
public bool PostProcess()
{
return true;
}
=> true;
public void HideTransform()
public void HideTransform(bool forced = false)
{
if (!forced && !IsActive)
return;
_enabledState = _mainMesh.enabled;
_mainMesh.enabled = false;
}

View file

@ -75,7 +75,7 @@ public class SkinnedTransformHider : ITransformHider
if (exclusionVerts.Count == 0)
continue;
SubTask subTask = new(this, exclusion.target, exclusionVerts);
SubTask subTask = new(this, exclusion, exclusionVerts);
_subTasks.Add(subTask);
exclusion.relatedTasks.Add(subTask);
}
@ -116,14 +116,15 @@ public class SkinnedTransformHider : ITransformHider
public bool PostProcess()
=> false; // not needed
public void HideTransform()
public void HideTransform(bool forced = false)
{
_mainMesh.forceRenderingOff = false;
_graphicsBuffer = _mainMesh.GetVertexBuffer();
foreach (SubTask subTask in _subTasks)
if (subTask.IsActive && subTask.IsValid) subTask.Dispatch();
if ((forced || subTask.IsActive) && subTask.IsValid)
subTask.Dispatch();
_graphicsBuffer.Release();
}
@ -176,10 +177,13 @@ public class SkinnedTransformHider : ITransformHider
private readonly ComputeBuffer _computeBuffer;
private readonly int _threadGroups;
public SubTask(SkinnedTransformHider parent, Transform shrinkBone, List<int> exclusionVerts)
private readonly FPRExclusion _exclusion;
public SubTask(SkinnedTransformHider parent, FPRExclusion exclusion, List<int> exclusionVerts)
{
_parent = parent;
_shrinkBone = shrinkBone;
_exclusion = exclusion;
_shrinkBone = _exclusion.target;
_vertexCount = exclusionVerts.Count;
_computeBuffer = new ComputeBuffer(_vertexCount, sizeof(int));

View file

@ -1,4 +1,5 @@
using ABI_RC.Core.Player;
using ABI_RC.Systems.VRModeSwitch;
using MagicaCloth;
using UnityEngine;
@ -32,6 +33,7 @@ public class TransformHiderManager : MonoBehaviour
// Settings
internal static bool s_DebugHeadHide;
internal static bool s_DisallowFprExclusions = true;
// Implementation
private bool _hasRenderedThisFrame;
@ -58,7 +60,10 @@ public class TransformHiderManager : MonoBehaviour
UpdatePlayerCameras();
s_DisallowFprExclusions = ModSettings.EntryDontRespectFPR.Value;
s_DebugHeadHide = ModSettings.EntryDebugHeadHide.Value;
VRModeSwitchEvents.OnCompletedVRModeSwitch.AddListener(OnVRModeSwitchCompleted);
}
private void OnEnable()
@ -73,6 +78,12 @@ public class TransformHiderManager : MonoBehaviour
Camera.onPostRender -= MyOnPostRender;
}
private void OnDestroy()
{
VRModeSwitchEvents.OnCompletedVRModeSwitch.RemoveListener(OnVRModeSwitchCompleted);
OnAvatarCleared();
}
#endregion
#region Transform Hider Managment
@ -113,7 +124,7 @@ public class TransformHiderManager : MonoBehaviour
if (!hider.Process()) continue; // not ready yet or disabled
if (hider.IsActive) hider.HideTransform();
hider.HideTransform(s_DisallowFprExclusions);
}
_stopWatch.Stop();
@ -136,7 +147,7 @@ public class TransformHiderManager : MonoBehaviour
if (!hider.PostProcess()) continue; // does not need post processing
if (hider.IsActive) hider.ShowTransform();
hider.ShowTransform();
}
}
@ -153,10 +164,8 @@ public class TransformHiderManager : MonoBehaviour
s_TransformHider.Clear();
}
private void OnVRModeSwitchCompleted(bool _, Camera __)
{
UpdatePlayerCameras();
}
private void OnVRModeSwitchCompleted(bool _)
=> UpdatePlayerCameras();
#endregion