This commit is contained in:
SoulliesOfficial
2025-09-19 23:39:23 -04:00
parent f612d5bcd4
commit a9bc898e4c
130 changed files with 227554 additions and 24284 deletions

View File

@@ -118,7 +118,7 @@ namespace MhRender.RendererFeatures
// Shader shader = Shader.Find("XuanXuan/Postprocess/NBPostProcessUber");
NBPostProcessMaterial = CoreUtils.CreateEngineMaterial(Shader.Find("XuanXuan/Postprocess/NBPostProcessUber"));
NBPostProcessingManager.InitMat();
PostProcessingManager.InitMat();
// if (Application.isPlaying)
// {
@@ -349,23 +349,25 @@ namespace MhRender.RendererFeatures
using (new ProfilingScope(cmd, _profilingSampler))
{
context.DrawRenderers(renderingData.cullResults, ref DisturbanceDraw, ref _Filtering);
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_renderMaskMat.SetTexture(CameraTexture, _DisturbanceMaskRTHandle);
cmd.SetRenderTarget((RenderTargetIdentifier)_DownRT);
switch (_downSampling)
{
case Downsampling._2xBilinear:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, Vector2.one, _renderMaskMat, 0);
break;
case Downsampling._4xBilinear:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, Vector2.one, _renderMaskMat, 0);
break;
case Downsampling._4xBox:
_renderMaskMat.SetFloat(SampleOffset, 2);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 1);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, Vector2.one, _renderMaskMat, 1);
break;
default:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, Vector2.one, _renderMaskMat, 0);
break;
}
@@ -439,7 +441,7 @@ namespace MhRender.RendererFeatures
public static Material _material;
public Mesh _fullScreenMesh;
public NBPostProcessFlags _shaderFlag => NBPostProcessingManager.flags;
public NBPostProcessFlags _shaderFlag => PostProcessingManager.flags;
private Vector4 _lastOutlineProps;
public Vector4 outLinePorps = Vector4.one;

View File

@@ -5,7 +5,7 @@ public class NBPostProcessFlags: ShaderFlagsBase
public const string FlagsName = "_NBPostProcessFlags";
public static int FlagsId = Shader.PropertyToID(FlagsName);
protected override int GetShaderFlagsId(int index = 0)
public override int GetShaderFlagsId(int index = 0)
{
return FlagsId;
}

View File

@@ -13,14 +13,14 @@ using UnityEditor;
[ExecuteInEditMode]
public class NBPostProcessingController : MonoBehaviour
public class PostProcessingController : MonoBehaviour
{
#if UNITY_EDITOR
public AnimBool[] AnimBools = new AnimBool[10];
#endif
// [ShowInInspector][ReadOnly]
//[SerializeField]
public NBPostProcessingManager _manager;
[SerializeField]
private PostProcessingManager _manager;
public int index
{
@@ -199,6 +199,7 @@ public class NBPostProcessingController : MonoBehaviour
// [LabelText("对比度")] [ToggleGroup("flashToggle")]
public float flashContrast = 1f;
public Color flashColor = new Color(1f,1f,1f,1f);
public Color blackFlashColor = new Color(0f,0f,0f,1f);
// [ToggleGroup("vignetteToggle", "暗角")]
// [OnValueChanged("InitAllSettings")]
@@ -225,7 +226,7 @@ public class NBPostProcessingController : MonoBehaviour
return;
}
_manager = NBPostProcessingManager.Instance;
_manager = PostProcessingManager.Instance;
_manager.InitController(this);
InitAllSettings();
@@ -245,30 +246,30 @@ public class NBPostProcessingController : MonoBehaviour
void SetScreenCenterPos()
{
NBPostProcessingManager.customScreenCenterPos = customScreenCenterPos;
PostProcessingManager.customScreenCenterPos = customScreenCenterPos;
_lastCustomScreenCenterPos = customScreenCenterPos;
}
void SetUVFromDistort()
{
NBPostProcessingManager.isDistortScreenUVMode = distortScreenUVMode;
NBPostProcessingManager.isCaByDistort = caFromDistort;
NBPostProcessingManager.isRadialBlurByDistort = radialBlurFromDistort;
PostProcessingManager.isDistortScreenUVMode = distortScreenUVMode;
PostProcessingManager.isCaByDistort = caFromDistort;
PostProcessingManager.isRadialBlurByDistort = radialBlurFromDistort;
}
private void SetTexture()
{
if(NBPostProcessingManager.material == null) return;
if(PostProcessingManager.material == null) return;
if (distortSpeedToggle)
{
if (distortSpeedTexture != null)
{
NBPostProcessingManager.material.SetTexture(_distortSpeedTextureID, distortSpeedTexture);
NBPostProcessingManager.distortTextureMidValue = distortTextureMidValue;
PostProcessingManager.material.SetTexture(_distortSpeedTextureID, distortSpeedTexture);
PostProcessingManager.distortTextureMidValue = distortTextureMidValue;
}
else
{
NBPostProcessingManager.material.SetTexture(_distortSpeedTextureID, null);
PostProcessingManager.material.SetTexture(_distortSpeedTextureID, null);
}
}
@@ -276,34 +277,34 @@ public class NBPostProcessingController : MonoBehaviour
{
if (overlayTexturePolarCoordMode)
{
NBPostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
PostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
}
else
{
NBPostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
PostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
}
if (overlayTexture)
{
Debug.Log("SetOverlayTexture");
NBPostProcessingManager.material.SetTexture(_overlayTextureID,overlayTexture);
PostProcessingManager.material.SetTexture(_overlayTextureID,overlayTexture);
}
else
{
Debug.Log("ClearOverlayTexture");
NBPostProcessingManager.material.SetTexture(_overlayTextureID,null);
PostProcessingManager.material.SetTexture(_overlayTextureID,null);
}
if (overlayMaskTexture)
{
Debug.Log("SetOverlayMaskTexture");
NBPostProcessingManager.material.SetTexture(_textureOverlayMaskProperty,overlayMaskTexture);
NBPostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
PostProcessingManager.material.SetTexture(_textureOverlayMaskProperty,overlayMaskTexture);
PostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
}
else
{
Debug.Log("ClearOverlayMaskTexture");
NBPostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
PostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
}
}
@@ -311,15 +312,15 @@ public class NBPostProcessingController : MonoBehaviour
private void SetToggles()
{
SetBit(ref NBPostProcessingManager.chromaticAberrationToggles,index,chromaticAberrationToggle);
SetBit(ref NBPostProcessingManager.distortSpeedToggles,index,distortSpeedToggle);
SetBit(ref PostProcessingManager.chromaticAberrationToggles,index,chromaticAberrationToggle);
SetBit(ref PostProcessingManager.distortSpeedToggles,index,distortSpeedToggle);
#if CINIMACHINE_3_0
SetBit(ref PostProcessingManager.cameraShakeToggles,index,cameraShakeToggle);
#endif
SetBit(ref NBPostProcessingManager.overlayTextureToggles,index,overlayTextureToggle);
SetBit(ref NBPostProcessingManager.flashToggles,index,flashToggle);
SetBit(ref NBPostProcessingManager.radialBlurToggles,index,radialBlurToggle);
SetBit(ref NBPostProcessingManager.vignetteToggles,index,vignetteToggle);
SetBit(ref PostProcessingManager.overlayTextureToggles,index,overlayTextureToggle);
SetBit(ref PostProcessingManager.flashToggles,index,flashToggle);
SetBit(ref PostProcessingManager.radialBlurToggles,index,radialBlurToggle);
SetBit(ref PostProcessingManager.vignetteToggles,index,vignetteToggle);
#if UNITY_EDITOR
SetTexture();
@@ -329,15 +330,15 @@ public class NBPostProcessingController : MonoBehaviour
private void ClearToggles()
{
SetBit(ref NBPostProcessingManager.chromaticAberrationToggles,index,false);
SetBit(ref NBPostProcessingManager.distortSpeedToggles,index,false);
SetBit(ref PostProcessingManager.chromaticAberrationToggles,index,false);
SetBit(ref PostProcessingManager.distortSpeedToggles,index,false);
#if CINIMACHINE_3_0
SetBit(ref PostProcessingManager.cameraShakeToggles,index,false);
#endif
SetBit(ref NBPostProcessingManager.overlayTextureToggles,index,false);
SetBit(ref NBPostProcessingManager.flashToggles,index,false);
SetBit(ref NBPostProcessingManager.radialBlurToggles,index,false);
SetBit(ref NBPostProcessingManager.vignetteToggles,index,false);
SetBit(ref PostProcessingManager.overlayTextureToggles,index,false);
SetBit(ref PostProcessingManager.flashToggles,index,false);
SetBit(ref PostProcessingManager.radialBlurToggles,index,false);
SetBit(ref PostProcessingManager.vignetteToggles,index,false);
}
private bool _lastChormaticAberrationToggle = false;
@@ -455,7 +456,7 @@ public class NBPostProcessingController : MonoBehaviour
isFirstUpdate = false;
return;
}
if(!NBPostProcessingManager.material) return;
if(!PostProcessingManager.material) return;
//#if UNITY_EDITOR
//Odin的ToggleGroup和OnValueChange功能冲突导致不一定生效。不好调试。所以用手动的方式更新。
bool isToggleChanged = false;
@@ -482,35 +483,35 @@ public class NBPostProcessingController : MonoBehaviour
if (chromaticAberrationToggle)
{
NBPostProcessingManager.chromaticAberrationIntensity =
Mathf.Max(NBPostProcessingManager.chromaticAberrationIntensity, chromaticAberrationIntensity);
NBPostProcessingManager.chromaticAberrationPos =
Mathf.Max(NBPostProcessingManager.chromaticAberrationPos, chromaticAberrationPos);
NBPostProcessingManager.chromaticAberrationRange =
Mathf.Max(NBPostProcessingManager.chromaticAberrationRange, chromaticAberrationRange);
PostProcessingManager.chromaticAberrationIntensity =
Mathf.Max(PostProcessingManager.chromaticAberrationIntensity, chromaticAberrationIntensity);
PostProcessingManager.chromaticAberrationPos =
Mathf.Max(PostProcessingManager.chromaticAberrationPos, chromaticAberrationPos);
PostProcessingManager.chromaticAberrationRange =
Mathf.Max(PostProcessingManager.chromaticAberrationRange, chromaticAberrationRange);
}
if (distortSpeedToggle)
{
if (index == NBPostProcessingManager.laseUpdateControllerIndex)
if (index == PostProcessingManager.laseUpdateControllerIndex)
{
//只有这里才会更新Scale
NBPostProcessingManager.material.SetVector(_distortSpeedTextureStID, distortSpeedTexSt);
PostProcessingManager.material.SetVector(_distortSpeedTextureStID, distortSpeedTexSt);
}
NBPostProcessingManager.distortSpeedIntensity =
Mathf.Max(NBPostProcessingManager.distortSpeedIntensity, distortSpeedIntensity);
NBPostProcessingManager.distortSpeedPosition =
Mathf.Max(NBPostProcessingManager.distortSpeedPosition, distortSpeedPosition);
NBPostProcessingManager.distortSpeedRange =
Mathf.Max(NBPostProcessingManager.distortSpeedRange, distortSpeedRange);
NBPostProcessingManager.distortSpeedMoveSpeedX =
Mathf.Abs(NBPostProcessingManager.distortSpeedMoveSpeedX) > Mathf.Abs(distortSpeedMoveSpeedX)
? NBPostProcessingManager.distortSpeedMoveSpeedX
PostProcessingManager.distortSpeedIntensity =
Mathf.Max(PostProcessingManager.distortSpeedIntensity, distortSpeedIntensity);
PostProcessingManager.distortSpeedPosition =
Mathf.Max(PostProcessingManager.distortSpeedPosition, distortSpeedPosition);
PostProcessingManager.distortSpeedRange =
Mathf.Max(PostProcessingManager.distortSpeedRange, distortSpeedRange);
PostProcessingManager.distortSpeedMoveSpeedX =
Mathf.Abs(PostProcessingManager.distortSpeedMoveSpeedX) > Mathf.Abs(distortSpeedMoveSpeedX)
? PostProcessingManager.distortSpeedMoveSpeedX
: distortSpeedMoveSpeedX;
NBPostProcessingManager.distortSpeedMoveSpeedY =
Mathf.Abs(NBPostProcessingManager.distortSpeedMoveSpeedY) > Mathf.Abs(distortSpeedMoveSpeed)
? NBPostProcessingManager.distortSpeedMoveSpeedY
PostProcessingManager.distortSpeedMoveSpeedY =
Mathf.Abs(PostProcessingManager.distortSpeedMoveSpeedY) > Mathf.Abs(distortSpeedMoveSpeed)
? PostProcessingManager.distortSpeedMoveSpeedY
: distortSpeedMoveSpeed;
}
@@ -525,47 +526,48 @@ public class NBPostProcessingController : MonoBehaviour
if (overlayTextureToggle)
{
if (index == NBPostProcessingManager.laseUpdateControllerIndex)
if (index == PostProcessingManager.laseUpdateControllerIndex)
{
NBPostProcessingManager.material.SetVector(_overlayTextureStID, overlayTextureSt);
NBPostProcessingManager.material.SetVector(_textureOverlayMaskStProperty, overlayMaskTextureSt);
NBPostProcessingManager.material.SetVector(_textureOverlayAnimProperty,overlayTextureAnim);
PostProcessingManager.material.SetVector(_overlayTextureStID, overlayTextureSt);
PostProcessingManager.material.SetVector(_textureOverlayMaskStProperty, overlayMaskTextureSt);
PostProcessingManager.material.SetVector(_textureOverlayAnimProperty,overlayTextureAnim);
}
NBPostProcessingManager.overlayTextureIntensity = Mathf.Max(NBPostProcessingManager.overlayTextureIntensity,
PostProcessingManager.overlayTextureIntensity = Mathf.Max(PostProcessingManager.overlayTextureIntensity,
overlayTextureIntensity);
}
if (flashToggle)
{
NBPostProcessingManager.flashDesaturateIntensity =
Mathf.Max(NBPostProcessingManager.flashDesaturateIntensity, flashDeSaturateIntensity);
NBPostProcessingManager.flashInvertIntensity =
Mathf.Max(NBPostProcessingManager.flashInvertIntensity, flashInvertIntensity);
NBPostProcessingManager.flashContrast =
Mathf.Max(NBPostProcessingManager.flashContrast, flashContrast);
NBPostProcessingManager.flashColor = flashColor;
PostProcessingManager.flashDesaturateIntensity =
Mathf.Max(PostProcessingManager.flashDesaturateIntensity, flashDeSaturateIntensity);
PostProcessingManager.flashInvertIntensity =
Mathf.Max(PostProcessingManager.flashInvertIntensity, flashInvertIntensity);
PostProcessingManager.flashContrast =
Mathf.Max(PostProcessingManager.flashContrast, flashContrast);
PostProcessingManager.flashColor = flashColor;
PostProcessingManager.blackFlashColor = blackFlashColor;
}
if (radialBlurToggle)
{
NBPostProcessingManager.radialBlurIntensity =
Mathf.Max(NBPostProcessingManager.radialBlurIntensity, radialBlurIntensity);
NBPostProcessingManager.radialBlurSampleCount = Mathf.Max(NBPostProcessingManager.radialBlurSampleCount,
PostProcessingManager.radialBlurIntensity =
Mathf.Max(PostProcessingManager.radialBlurIntensity, radialBlurIntensity);
PostProcessingManager.radialBlurSampleCount = Mathf.Max(PostProcessingManager.radialBlurSampleCount,
radialBlurSampleCount);
NBPostProcessingManager.radialBlurPos = Mathf.Max(NBPostProcessingManager.radialBlurPos, radialBlurPos);
NBPostProcessingManager.radialBlurRange = Mathf.Max(NBPostProcessingManager.radialBlurRange, radialBlurRange);
PostProcessingManager.radialBlurPos = Mathf.Max(PostProcessingManager.radialBlurPos, radialBlurPos);
PostProcessingManager.radialBlurRange = Mathf.Max(PostProcessingManager.radialBlurRange, radialBlurRange);
}
if (vignetteToggle)
{
NBPostProcessingManager.vignetteIntensity =
Mathf.Max(NBPostProcessingManager.vignetteIntensity, vignetteIntensity);
NBPostProcessingManager.vignetteRoundness = Mathf.Max(NBPostProcessingManager.vignetteRoundness, vignetteRoundness);
NBPostProcessingManager.vignetteSmothness = Mathf.Max(NBPostProcessingManager.vignetteSmothness, vignetteSmothness);
if (index == NBPostProcessingManager.laseUpdateControllerIndex)
PostProcessingManager.vignetteIntensity =
Mathf.Max(PostProcessingManager.vignetteIntensity, vignetteIntensity);
PostProcessingManager.vignetteRoundness = Mathf.Max(PostProcessingManager.vignetteRoundness, vignetteRoundness);
PostProcessingManager.vignetteSmothness = Mathf.Max(PostProcessingManager.vignetteSmothness, vignetteSmothness);
if (index == PostProcessingManager.laseUpdateControllerIndex)
{
NBPostProcessingManager.material.SetColor(_vignetteColorID,vignetteColor);
PostProcessingManager.material.SetColor(_vignetteColorID,vignetteColor);
}
}
@@ -586,7 +588,7 @@ public class NBPostProcessingController : MonoBehaviour
{
GameObject Effect = new GameObject();
Effect.name = "NBPostprocessController";
NBPostProcessingController controller = Effect.AddComponent<NBPostProcessingController>();
PostProcessingController controller = Effect.AddComponent<PostProcessingController>();
UnityEditor.Selection.activeObject = Effect;
}

View File

@@ -17,26 +17,26 @@ using MhRender.RendererFeatures;
[ExecuteAlways]
public class NBPostProcessingManager : MonoBehaviour
public class PostProcessingManager : MonoBehaviour
{
//单例实现
private static NBPostProcessingManager _instance = null;
private static PostProcessingManager _instance = null;
public static NBPostProcessingManager Instance
public static PostProcessingManager Instance
{
get
{
if (_instance == null)
{
#if UNITY_2022_1_OR_NEWER
_instance = FindFirstObjectByType<NBPostProcessingManager>();
#else
_instance = FindObjectOfType<PostProcessingManager>();
#endif
// #if UNITY_2022_1_OR_NEWER
// _instance = FindFirstObjectByType<PostProcessingManager>();
// #else
_instance = FindObjectOfType<PostProcessingManager>();//因为兼容性因素,保留较慢版本
// #endif
if (_instance == null)
{
GameObject singletonObj = new GameObject();
_instance = singletonObj.AddComponent<NBPostProcessingManager>();
_instance = singletonObj.AddComponent<PostProcessingManager>();
if (Application.isPlaying)
{
singletonObj.name = "NBPostProcessManager";
@@ -62,7 +62,7 @@ public class NBPostProcessingManager : MonoBehaviour
}
else
{
//DestroyImmediate(this);
DestroyImmediate(this);
}
}
@@ -88,7 +88,7 @@ public class NBPostProcessingManager : MonoBehaviour
public static void InitMat()
{
flags.SetMaterial(NBPostProcessingManager.material);
flags.SetMaterial(PostProcessingManager.material);
if (_instance)
{
_instance.ResetEffect();
@@ -197,7 +197,7 @@ public class NBPostProcessingManager : MonoBehaviour
return count;
}
//每次Controller触发Play都会触发Init
public void InitController(NBPostProcessingController controller)
public void InitController(PostProcessingController controller)
{
#if CINIMACHINE_3_0
if (controller.cinemachineCamera != null)
@@ -210,7 +210,7 @@ public class NBPostProcessingManager : MonoBehaviour
controller.SetIndex(GetControllerIndex());
}
public void EndController(NBPostProcessingController controller)
public void EndController(PostProcessingController controller)
{
#if CINIMACHINE_3_0
if (currentVirtualCamera == controller.cinemachineCamera)
@@ -629,11 +629,13 @@ public class NBPostProcessingManager : MonoBehaviour
public static float flashContrast = 0;
public static Color flashColor = new Color(1, 1, 1, 1);
public static Color blackFlashColor = new Color(0, 0, 0, 1);
private readonly int _flashDesaturateProperty = Shader.PropertyToID("_DeSaturateIntensity");
private readonly int _flashInvertProperty = Shader.PropertyToID("_InvertIntensity");
private readonly int _flashContrastProperty = Shader.PropertyToID("_Contrast");
private readonly int _flashColorProperty = Shader.PropertyToID("_FlashColor");
private readonly int _blackFlashColorProperty = Shader.PropertyToID("_BlackFlashColor");
private void InitFlash()
{
@@ -646,6 +648,7 @@ public class NBPostProcessingManager : MonoBehaviour
material.SetFloat(_flashInvertProperty, flashInvertIntensity);
material.SetFloat(_flashContrastProperty, flashContrast);
material.SetColor(_flashColorProperty,flashColor);
material.SetColor(_blackFlashColorProperty,blackFlashColor);
flashDesaturateIntensity = 0;
flashInvertIntensity = 0;
flashContrast = 0;

View File

@@ -132,20 +132,22 @@ namespace MhRender.RendererFeatures
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_material.SetTexture(CameraTexture, _screenColorHandle);
cmd.SetRenderTarget((RenderTargetIdentifier)_tempRTHandle);
switch (_downSampling)
{
case Downsampling._2xBilinear:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
Blitter.BlitTexture(cmd, _screenColorHandle, Vector2.one, _material, 0);
break;
case Downsampling._4xBilinear:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
Blitter.BlitTexture(cmd, _screenColorHandle, Vector2.one, _material, 0);
break;
case Downsampling._4xBox:
_material.SetFloat(SampleOffset,2);
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 1);
Blitter.BlitTexture(cmd, _screenColorHandle, Vector2.one, _material, 1);
break;
default:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
Blitter.BlitTexture(cmd, _screenColorHandle, Vector2.one, _material, 0);
break;
}
#else