[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, 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."); 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 = internal static readonly MelonPreferences_Entry<bool> EntryDebugHeadHide =
Category.CreateEntry("Debug Head Hide", false, Category.CreateEntry("Debug Head Hide", false,
description: "Should head be hidden for first render?"); 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) private static void OnSettingsChanged(object oldValue = null, object newValue = null)
{ {
TransformHiderManager.s_DisallowFprExclusions = EntryDontRespectFPR.Value;
TransformHiderManager.s_DebugHeadHide = EntryDebugHeadHide.Value; TransformHiderManager.s_DebugHeadHide = EntryDebugHeadHide.Value;
ShadowCloneManager.s_CopyMaterialsToShadow = EntryCopyMaterialToShadow.Value; ShadowCloneManager.s_CopyMaterialsToShadow = EntryCopyMaterialToShadow.Value;
} }

View file

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

View file

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

View file

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

View file

@ -75,7 +75,7 @@ public class SkinnedTransformHider : ITransformHider
if (exclusionVerts.Count == 0) if (exclusionVerts.Count == 0)
continue; continue;
SubTask subTask = new(this, exclusion.target, exclusionVerts); SubTask subTask = new(this, exclusion, exclusionVerts);
_subTasks.Add(subTask); _subTasks.Add(subTask);
exclusion.relatedTasks.Add(subTask); exclusion.relatedTasks.Add(subTask);
} }
@ -116,14 +116,15 @@ public class SkinnedTransformHider : ITransformHider
public bool PostProcess() public bool PostProcess()
=> false; // not needed => false; // not needed
public void HideTransform() public void HideTransform(bool forced = false)
{ {
_mainMesh.forceRenderingOff = false; _mainMesh.forceRenderingOff = false;
_graphicsBuffer = _mainMesh.GetVertexBuffer(); _graphicsBuffer = _mainMesh.GetVertexBuffer();
foreach (SubTask subTask in _subTasks) foreach (SubTask subTask in _subTasks)
if (subTask.IsActive && subTask.IsValid) subTask.Dispatch(); if ((forced || subTask.IsActive) && subTask.IsValid)
subTask.Dispatch();
_graphicsBuffer.Release(); _graphicsBuffer.Release();
} }
@ -169,17 +170,20 @@ public class SkinnedTransformHider : ITransformHider
{ {
public bool IsActive { get; set; } = true; public bool IsActive { get; set; } = true;
public bool IsValid => _computeBuffer != null; // TODO: cleanup dead tasks public bool IsValid => _computeBuffer != null; // TODO: cleanup dead tasks
private readonly SkinnedTransformHider _parent; private readonly SkinnedTransformHider _parent;
private readonly Transform _shrinkBone; private readonly Transform _shrinkBone;
private readonly int _vertexCount; private readonly int _vertexCount;
private readonly ComputeBuffer _computeBuffer; private readonly ComputeBuffer _computeBuffer;
private readonly int _threadGroups; 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; _parent = parent;
_shrinkBone = shrinkBone; _exclusion = exclusion;
_shrinkBone = _exclusion.target;
_vertexCount = exclusionVerts.Count; _vertexCount = exclusionVerts.Count;
_computeBuffer = new ComputeBuffer(_vertexCount, sizeof(int)); _computeBuffer = new ComputeBuffer(_vertexCount, sizeof(int));

View file

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