一些特效

This commit is contained in:
SoulliesOfficial
2025-06-28 03:01:03 -04:00
parent 16418804e4
commit 1a3d37d9b5
216 changed files with 41141 additions and 2728 deletions

View File

@@ -0,0 +1,100 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7f59e54f2bfd184b9dd451a678d089b, type: 3}
m_Name: 3DPostionShake
m_EditorClassIdentifier:
PositionNoise:
- X:
Frequency: 3.2
Amplitude: 0.011
Constant: 1
Y:
Frequency: 1.9
Amplitude: 0.059
Constant: 1
Z:
Frequency: 3.33
Amplitude: 0.021
Constant: 1
- X:
Frequency: 7.7
Amplitude: 0.009
Constant: 1
Y:
Frequency: 9.1
Amplitude: 0.04
Constant: 0
Z:
Frequency: 9.22
Amplitude: 0.009
Constant: 1
- X:
Frequency: 51.51
Amplitude: 0.002
Constant: 1
Y:
Frequency: 55.54
Amplitude: 0.05
Constant: 1
Z:
Frequency: 58.55
Amplitude: 0.017
Constant: 1
OrientationNoise:
- X:
Frequency: 6.17
Amplitude: 1
Constant: 0
Y:
Frequency: 33.6
Amplitude: 0.4
Constant: 1
Z:
Frequency: 50
Amplitude: 0.29
Constant: 1
- X:
Frequency: 50
Amplitude: 0.78
Constant: 1
Y:
Frequency: 1.18
Amplitude: 0.01
Constant: 0
Z:
Frequency: 3.93
Amplitude: 0.8
Constant: 0
- X:
Frequency: 0
Amplitude: 0
Constant: 0
Y:
Frequency: 2.52
Amplitude: 1.88
Constant: 0
Z:
Frequency: 4.75
Amplitude: 1.1
Constant: 0
- X:
Frequency: 0
Amplitude: 0
Constant: 0
Y:
Frequency: 0
Amplitude: 0
Constant: 0
Z:
Frequency: 0
Amplitude: 0
Constant: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c3a1931bdb3088e4ebf4755df90c90e9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0b3052f0c1288a045a0be3d63f109623
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,356 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
using System.Reflection;
#if CINIMACHINE_3_0
using Unity.Cinemachine;
#endif
using System;
// using Unity.Properties;
[CustomEditor(typeof(PostProcessingController))]
public class PostProcessingControllerGUI : Editor
{
private SerializedProperty _managerProperty;
private SerializedProperty _indexProperty;
private Action delayExcuteReflect = () => { };
public override void OnInspectorGUI()
{
PostProcessingController ppController = (PostProcessingController)target;
serializedObject.Update();
_managerProperty = serializedObject.FindProperty("_manager");
_indexProperty = serializedObject.FindProperty("_index");
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_managerProperty);
EditorGUI.EndDisabledGroup();
EditorGUI.BeginChangeCheck();
// ppController.customScreenCenterPos = EditorGUILayout.Vector2Field("自定义屏幕中心", ppController.customScreenCenterPos);
SerializedProperty customScreenCenterPosProp = serializedObject.FindProperty("customScreenCenterPos");
EditorGUILayout.PropertyField(customScreenCenterPosProp,new GUIContent("自定义屏幕中心"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetScreenCenterPos", ppController);
}
SerializedProperty caToggleProp = serializedObject.FindProperty("chromaticAberrationToggle");
DrawToggleFoldOut(ppController.AnimBools[0], "色散", caToggleProp,
drawEndChangeCheck: isChangeToggle => { ReflectMethod("InitAllSettings", ppController); }
, drawBlock: isToggle =>
{
EditorGUI.BeginChangeCheck();
// ppController.caFromDistort = EditorGUILayout.Toggle("色散UV跟随后处理扭曲", ppController.caFromDistort);
SerializedProperty caFromDistortProp = serializedObject.FindProperty("caFromDistort");
EditorGUILayout.PropertyField(caFromDistortProp, new GUIContent("色散UV跟随后处理扭曲"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetUVFromDistort", ppController);
}
// ppController.chromaticAberrationIntensity = EditorGUILayout.FloatField("色散强度", ppController.chromaticAberrationIntensity);
SerializedProperty caIntensityProps = serializedObject.FindProperty("chromaticAberrationIntensity");
EditorGUILayout.PropertyField(caIntensityProps, new GUIContent("色散强度"));
if (!ppController.caFromDistort)
{
// ppController.chromaticAberrationPos = EditorGUILayout.FloatField("色散位置", ppController.chromaticAberrationPos);
SerializedProperty caPosProp = serializedObject.FindProperty("chromaticAberrationPos");
EditorGUILayout.PropertyField(caPosProp, new GUIContent("色散位置"));
// ppController.chromaticAberrationRange = EditorGUILayout.FloatField("色散过渡范围", ppController.chromaticAberrationRange);
SerializedProperty caRangeProp = serializedObject.FindProperty("chromaticAberrationRange");
EditorGUILayout.PropertyField(caRangeProp, new GUIContent("色散过渡范围"));
}
});
SerializedProperty distortSpeedToggleProp = serializedObject.FindProperty("distortSpeedToggle");
DrawToggleFoldOut(ppController.AnimBools[1], "扭曲", distortSpeedToggleProp, drawEndChangeCheck:
isChangeToggle => { ReflectMethod("InitAllSettings", ppController); },
drawBlock: isToggle =>
{
EditorGUI.BeginChangeCheck();
// ppController.distortScreenUVMode = EditorGUILayout.Toggle("后处理走常规屏幕坐标", ppController.distortScreenUVMode);
SerializedProperty distortScreenUVModeProp = serializedObject.FindProperty("distortScreenUVMode");
EditorGUILayout.PropertyField(distortScreenUVModeProp,new GUIContent("后处理走常规屏幕坐标"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetUVFromDistort", ppController);
}
EditorGUI.BeginChangeCheck();
// ppController.distortSpeedTexture = (Texture2D)EditorGUILayout.ObjectField("后处理扭曲贴图", ppController.distortSpeedTexture, typeof(Texture2D));
SerializedProperty distortSpeedTextureProp = serializedObject.FindProperty("distortSpeedTexture");
EditorGUILayout.PropertyField(distortSpeedTextureProp, new GUIContent("后处理扭曲贴图"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("InitAllSettings", ppController);
}
if (ppController.distortScreenUVMode)
{
EditorGUI.BeginChangeCheck();
// ppController.distortTextureMidValue = EditorGUILayout.FloatField("扭曲贴图中间值", ppController.distortTextureMidValue);
SerializedProperty distortTextureMidValueProp = serializedObject.FindProperty("distortTextureMidValue");
EditorGUILayout.PropertyField(distortTextureMidValueProp, new GUIContent("扭曲贴图中间值"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetTexture", ppController);
}
}
// ppController.distortSpeedTexSt = EditorGUILayout.Vector4Field("扭曲贴图ST", ppController.distortSpeedTexSt);
SerializedProperty distortSpeedTexStProp = serializedObject.FindProperty("distortSpeedTexSt");
EditorGUILayout.PropertyField(distortSpeedTexStProp, new GUIContent("扭曲贴图缩放平移"));
// ppController.distortSpeedIntensity = EditorGUILayout.FloatField("扭曲强度", ppController.distortSpeedIntensity);
SerializedProperty distortSpeedIntensityProp = serializedObject.FindProperty("distortSpeedIntensity");
EditorGUILayout.PropertyField(distortSpeedIntensityProp, new GUIContent("扭曲强度"));
if (!ppController.distortScreenUVMode)
{
// ppController.distortSpeedPosition = EditorGUILayout.FloatField("扭曲位置", ppController.distortSpeedPosition);
SerializedProperty distortSpeedPositionProp = serializedObject.FindProperty("distortSpeedPosition");
EditorGUILayout.PropertyField(distortSpeedPositionProp, new GUIContent("扭曲位置"));
// ppController.distortSpeedRange = EditorGUILayout.FloatField("扭曲过渡范围", ppController.distortSpeedRange);
SerializedProperty distortSpeedRangeProp = serializedObject.FindProperty("distortSpeedRange");
EditorGUILayout.PropertyField(distortSpeedRangeProp, new GUIContent("扭曲过渡范围"));
}
// ppController.distortSpeedMoveSpeedX = EditorGUILayout.FloatField("扭曲纹理流动X", ppController.distortSpeedMoveSpeedX);
SerializedProperty distortSpeedMoveSpeedXProp = serializedObject.FindProperty("distortSpeedMoveSpeedX");
EditorGUILayout.PropertyField(distortSpeedMoveSpeedXProp, new GUIContent("扭曲纹理流动X"));
// ppController.distortSpeedMoveSpeed = EditorGUILayout.FloatField("扭曲纹理流动Y", ppController.distortSpeedMoveSpeed);
SerializedProperty distortSpeedMoveSpeed = serializedObject.FindProperty("distortSpeedMoveSpeed");
EditorGUILayout.PropertyField(distortSpeedMoveSpeed , new GUIContent("扭曲纹理流动Y"));
});
SerializedProperty radialBlurToggleProp = serializedObject.FindProperty("radialBlurToggle");
DrawToggleFoldOut(ppController.AnimBools[2], "径向模糊", radialBlurToggleProp, drawEndChangeCheck:
isChangeToggle => { ReflectMethod("InitAllSettings", ppController); },
drawBlock: isToggle =>
{
EditorGUI.BeginChangeCheck();
// ppController.radialBlurFromDistort = EditorGUILayout.Toggle("径向模糊跟随后处理扭曲", ppController.radialBlurFromDistort);
SerializedProperty radialBlurFromDistortProp = serializedObject.FindProperty("radialBlurFromDistort");
EditorGUILayout.PropertyField(radialBlurFromDistortProp, new GUIContent("径向模糊跟随后处理扭曲"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetUVFromDistort", ppController);
}
// ppController.radialBlurSampleCount = EditorGUILayout.IntSlider("采样次数", ppController.radialBlurSampleCount, 1, 12);
SerializedProperty radialBlurSampleCountProp = serializedObject.FindProperty("radialBlurSampleCount");
EditorGUILayout.PropertyField(radialBlurSampleCountProp, new GUIContent("采样次数"));
// ppController.radialBlurIntensity = EditorGUILayout.FloatField("强度", ppController.radialBlurIntensity);
SerializedProperty radialBlurIntensityProp = serializedObject.FindProperty("radialBlurIntensity");
EditorGUILayout.PropertyField(radialBlurIntensityProp, new GUIContent("强度"));
if (!ppController.radialBlurFromDistort)
{
// ppController.radialBlurPos = EditorGUILayout.FloatField("位置", ppController.radialBlurPos);\
SerializedProperty radialBlurPosProp = serializedObject.FindProperty("radialBlurPos");
EditorGUILayout.PropertyField(radialBlurPosProp, new GUIContent("位置"));
// ppController.radialBlurRange = EditorGUILayout.FloatField("过渡范围", ppController.radialBlurRange);
SerializedProperty radialBlurRangeProp = serializedObject.FindProperty("radialBlurRange");
EditorGUILayout.PropertyField(radialBlurRangeProp, new GUIContent("过渡范围"));
}
});
#if CINIMACHINE_3_0
SerializedProperty cameraShakeToggleProp = serializedObject.FindProperty("cameraShakeToggle");
DrawToggleFoldOut(ppController.AnimBools[3], "震屏", cameraShakeToggleProp, drawEndChangeCheck:
isChangeToggle =>
{
ReflectMethod("InitAllSettings",ppController);
},
drawBlock: isToggle =>
{
EditorGUI.BeginChangeCheck();
// ppController.cinemachineCamera = (CinemachineCamera)EditorGUILayout.ObjectField("绑定Cinemachine相机", ppController.cinemachineCamera, typeof(CinemachineCamera));
SerializedProperty cinemachineCameraProp = serializedObject.FindProperty("cinemachineCamera");
EditorGUILayout.PropertyField(cinemachineCameraProp, new GUIContent("绑定Cinemachine相机"));
if (EditorGUI.EndChangeCheck())
{
// ReflectMethod("InitCinemachineCamera",ppController);
ppController.InitCinemachineCamera();
}
// ppController.cameraShakeIntensity = EditorGUILayout.FloatField("相机震动强度", ppController.cameraShakeIntensity);
SerializedProperty cameraShakeIntensityProp = serializedObject.FindProperty("cameraShakeIntensity");
EditorGUILayout.PropertyField(cameraShakeIntensityProp, new GUIContent("相机震动强度"));
});
#endif
SerializedProperty overlayTextureToggleProp = serializedObject.FindProperty("overlayTextureToggle");
DrawToggleFoldOut(ppController.AnimBools[4], "肌理叠加图", overlayTextureToggleProp, drawEndChangeCheck:isChangeToggle =>
{
ReflectMethod("InitAllSettings", ppController);
},
drawBlock: isToggle =>
{
EditorGUI.BeginChangeCheck();
// ppController.overlayTexturePolarCoordMode = EditorGUILayout.Toggle("肌理图极坐标模式", ppController.overlayTexturePolarCoordMode);
SerializedProperty overlayTexturePolarCoordModeProp = serializedObject.FindProperty("overlayTexturePolarCoordMode");
EditorGUILayout.PropertyField(overlayTexturePolarCoordModeProp, new GUIContent("肌理图极坐标模式"));
// ppController.overlayTexture = (Texture2D)EditorGUILayout.ObjectField("肌理图", ppController.overlayTexture, typeof(Texture2D));
SerializedProperty overlayTextureProp = serializedObject.FindProperty("overlayTexture");
EditorGUILayout.PropertyField(overlayTextureProp, new GUIContent("肌理图"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetTexture",ppController);
}
// ppController.overlayTextureSt = EditorGUILayout.Vector4Field("肌理图缩放平移", ppController.overlayTextureSt);
SerializedProperty overlayTextureStProp = serializedObject.FindProperty("overlayTextureSt");
EditorGUILayout.PropertyField(overlayTextureStProp, new GUIContent("肌理图缩放平移"));
// ppController.overlayTextureAnim = EditorGUILayout.Vector2Field("肌理图偏移动画", ppController.overlayTextureAnim);
SerializedProperty overlayTextureAnimProp = serializedObject.FindProperty("overlayTextureAnim");
EditorGUILayout.PropertyField(overlayTextureAnimProp, new GUIContent("肌理图偏移动画"));
// ppController.overlayTextureIntensity = EditorGUILayout.FloatField("肌理图强度", ppController.overlayTextureIntensity);
SerializedProperty overlayTextureIntensityProp = serializedObject.FindProperty("overlayTextureIntensity");
EditorGUILayout.PropertyField(overlayTextureIntensityProp, new GUIContent("肌理图强度"));
EditorGUI.BeginChangeCheck();
// ppController.overlayMaskTexture = (Texture2D)EditorGUILayout.ObjectField("肌理蒙版图", ppController.overlayMaskTexture, typeof(Texture2D));
SerializedProperty overlayMaskTextureProp = serializedObject.FindProperty("overlayMaskTexture");
EditorGUILayout.PropertyField(overlayMaskTextureProp, new GUIContent("肌理蒙版图"));
if (EditorGUI.EndChangeCheck())
{
ReflectMethod("SetTexture",ppController);
}
// ppController.overlayMaskTextureSt = EditorGUILayout.Vector4Field("肌理图蒙版缩放平移", ppController.overlayMaskTextureSt);
SerializedProperty overlayMaskTextureStProp = serializedObject.FindProperty("overlayMaskTextureSt");
EditorGUILayout.PropertyField(overlayMaskTextureStProp, new GUIContent("肌理图蒙版缩放平移"));
});
SerializedProperty flashToggleProp = serializedObject.FindProperty("flashToggle");
DrawToggleFoldOut(ppController.AnimBools[5], "反闪", flashToggleProp, drawEndChangeCheck:
isChangeToggle =>
{
ReflectMethod("InitAllSettings",ppController);
},
drawBlock: isToggle =>
{
// ppController.flashInvertIntensity = EditorGUILayout.FloatField("反转度", ppController.flashInvertIntensity);
SerializedProperty flashInvertIntensityProp = serializedObject.FindProperty("flashInvertIntensity");
EditorGUILayout.PropertyField(flashInvertIntensityProp, new GUIContent("反转度"));
// ppController.flashDeSaturateIntensity = EditorGUILayout.FloatField("饱和度", ppController.flashDeSaturateIntensity);
SerializedProperty flashDeSaturateIntensityProp = serializedObject.FindProperty("flashDeSaturateIntensity");
EditorGUILayout.PropertyField(flashDeSaturateIntensityProp, new GUIContent("饱和度"));
// ppController.flashContrast = EditorGUILayout.FloatField("对比度", ppController.flashContrast);
SerializedProperty flashContrastProp = serializedObject.FindProperty("flashContrast");
EditorGUILayout.PropertyField(flashContrastProp, new GUIContent("对比度"));
// ppController.flashColor = EditorGUILayout.ColorField("闪颜色", ppController.flashColor);
SerializedProperty flashColorProp = serializedObject.FindProperty("flashColor");
EditorGUILayout.PropertyField(flashColorProp, new GUIContent("闪颜色"));
});
SerializedProperty vignetteToggleProp = serializedObject.FindProperty("vignetteToggle");
DrawToggleFoldOut(ppController.AnimBools[6], "暗角", vignetteToggleProp, drawEndChangeCheck:
isChangeToggle =>
{
ReflectMethod("InitAllSettings", ppController);
},
drawBlock: isToggle =>
{
// ppController.vignetteColor = EditorGUILayout.ColorField("暗角颜色", ppController.vignetteColor);
SerializedProperty vignetteColorProp = serializedObject.FindProperty("vignetteColor");
EditorGUILayout.PropertyField(vignetteColorProp, new GUIContent("暗角颜色"));
// ppController.vignetteIntensity = EditorGUILayout.FloatField("暗角强度", ppController.vignetteIntensity);
SerializedProperty vignetteIntensityProp = serializedObject.FindProperty("vignetteIntensity");
EditorGUILayout.PropertyField(vignetteIntensityProp, new GUIContent("暗角强度"));
// ppController.vignetteRoundness = EditorGUILayout.FloatField("暗角圆度", ppController.vignetteRoundness);
SerializedProperty vignetteRoundnessProp = serializedObject.FindProperty("vignetteRoundness");
EditorGUILayout.PropertyField(vignetteRoundnessProp, new GUIContent("暗角圆度"));
// ppController.vignetteSmothness = EditorGUILayout.FloatField("暗角平滑度", ppController.vignetteSmothness);
SerializedProperty vignetteSmothnessProp = serializedObject.FindProperty("vignetteSmothness");
EditorGUILayout.PropertyField(vignetteSmothnessProp, new GUIContent("暗角平滑度"));
});
if (GUILayout.Button("选择当前Manager"))
{
ReflectMethod("FindManager",ppController);
}
#if CINIMACHINE_3_0
if (GUILayout.Button("选择当前CinemachineCamera"))
{
ppController.FindVirtualCamera();
}
#endif
serializedObject.ApplyModifiedProperties();
}
public void DrawToggleFoldOut(AnimBool foldOutAnimBool,string label, SerializedProperty boolProperty,
bool isIndentBlock = true,
FontStyle fontStyle = FontStyle.Bold,
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
{
if (fontStyle == FontStyle.Bold)
{
EditorGUILayout.Space();
}
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
// foldoutRect.width = toggleRect.x - foldoutRect.x;
var labelRect = new Rect(rect.x + 18f, rect.y, rect.width - 18f, rect.height);
// bool isToggle = false;
// 必须先画Toggle不然按钮会被FoldOut和Label覆盖。
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(rect,boolProperty,new GUIContent(""));
// isToggle = EditorGUI.Toggle(rect, isToggle, EditorStyles.toggle);
if (EditorGUI.EndChangeCheck())
{
drawEndChangeCheck?.Invoke(boolProperty.boolValue);
}
// EditorGUI.DrawRect(foldoutRect,Color.red);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = fontStyle;
// EditorGUI.DrawRect(labelRect,Color.blue);
EditorGUI.LabelField(labelRect, label);
EditorStyles.label.fontStyle = origFontStyle;
EditorGUILayout.EndHorizontal();
if (isIndentBlock) EditorGUI.indentLevel++;
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f; //用于欺骗FadeGroup不要让他真的关闭了。这样会藏不住相关的GUI。我们的目的是GUI藏住但是逻辑还是在跑。drawBlock要执行。
EditorGUILayout.BeginFadeGroup(faded);
{
EditorGUI.BeginDisabledGroup(!boolProperty.boolValue);
drawBlock?.Invoke(boolProperty.boolValue);
EditorGUI.EndDisabledGroup();
}
EditorGUILayout.EndFadeGroup();
if (isIndentBlock) EditorGUI.indentLevel--;
}
void ReflectMethod(string methodName,PostProcessingController controller)
{
serializedObject.ApplyModifiedProperties();
MethodInfo privateMethod = typeof(PostProcessingController).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
if (privateMethod != null)
{
privateMethod.Invoke(controller, null);
}
else
{
Debug.LogError("Private method " + methodName + " not found!");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed187d8c0d9f5b14aa156ff45e7405c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
[CustomEditor(typeof(PostProcessingManager))]
public class PostProcessingManagerGUI : Editor
{
private PostProcessingManager _ppManager;
public override void OnInspectorGUI()
{
_ppManager = (PostProcessingManager)target;
serializedObject.Update();
DrawToggle("controllerIndexFlags","_controllerIndexFlags");
DrawToggle("色散开关",PostProcessingManager.chromaticAberrationToggles);
DrawToggle("径向扭曲开关",PostProcessingManager.distortSpeedToggles);
DrawToggle("径向模糊开关",PostProcessingManager.radialBlurToggles);
#if CINIMACHINE_3_0
DrawToggle("震屏开关",PostProcessingManager.cameraShakeToggles);
#endif
DrawToggle("肌理开关",PostProcessingManager.overlayTextureToggles);
DrawToggle("黑白闪开关",PostProcessingManager.flashToggles);
DrawToggle("暗角开关",PostProcessingManager.vignetteToggles);
DrawToggle32("ShaderFlags", PostProcessingManager.material.GetInteger(NBPostProcessFlags.FlagsId));
}
void DrawToggle(string label, string propertyName)
{
int intValue = ReflectIntValue(propertyName);
DrawToggle(label,intValue);
}
void DrawToggle(string label, int intValue)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label);
EditorGUILayout.LabelField(BinaryIntDrawer.DrawBinaryInt(intValue,8));
EditorGUILayout.EndHorizontal();
}
void DrawToggle32(string label, int intValue)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label);
EditorGUILayout.LabelField(BinaryIntDrawer.DrawBinaryInt(intValue,32));
EditorGUILayout.EndHorizontal();
}
int ReflectIntValue(string propertyName)
{
FieldInfo privateField = typeof(PostProcessingManager).GetField(propertyName, BindingFlags.NonPublic | BindingFlags.Instance);
if (privateField != null)
{
// 获取私有字段的值
int value = (int)privateField.GetValue(_ppManager);
return value;
}
else
{
Debug.LogError("PostProcessingManagerGUI获取变量错误");
return -1;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7bf2aa095c38c4972ba5c008ae40a3f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
{
"name": "com.xuanxuan.nb.postprocessing.Editor",
"rootNamespace": "",
"references": [
"GUID:a1f23b61b189bd949adfd0f7a353734f",
"GUID:8495541fcd41b0c40b5b6e6e7a7639d1",
"GUID:8f9e4d586616f13449cfeb86c5f704c2",
"GUID:4307f53044263cf4b835bd812fc161a4"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.cinemachine",
"expression": "3.0",
"define": "CINIMACHINE_3_0"
}
],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 12fb0c569d0951c40a3f4013cd8758b5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,2 @@
# NBPostProcessing
NBPostProcessing

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 11345d4fc578e4c15a13b9e5a61107df
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4f0e3118134388949838b53cc48e9c89
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,483 @@
// using ConfigSystem.MConfig;
// using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System.Collections.Generic;
namespace MhRender.RendererFeatures
{
public class NBPostProcess : ScriptableRendererFeature
{
private NBPostProcessRenderPass _renderPass;
private DisturbanceMaskRenderPass _disturbanceMaskRenderPass;
private ScreenColorRenderPass _screenColorRenderPass;
public static Material NBPostProcessMaterial;
//public MaskFormat maskFormat = MaskFormat.RG32;
public Downsampling downSampling = Downsampling.None;
public LayerMask disturbanceLayerMask=1 << 25;
private Material _disturbanceDownSampleMat;
private Material _screenColorDownSampleMat;
private float _screenHeight;
private ProfilingSampler _profilingSampler;
// private PostProcessingManager manager;-+
static Mesh s_FullscreenTriangle;
/// <summary>
/// A fullscreen triangle mesh.抄自Unity的后处理包,拿到一个全屏的Triangle。
/// </summary>
static Mesh fullscreenTriangle;
// {
// get
// {
// if (s_FullscreenTriangle != null)
// return s_FullscreenTriangle;
//
// s_FullscreenTriangle = new Mesh
// {
// name = "Fullscreen Triangle"
// };
//
// // Because we have to support older platforms (GLES2/3, DX9 etc) we can't do all of
// // this directly in the vertex shader using vertex ids :(
// s_FullscreenTriangle.SetVertices(new List<Vector3>
// {
// new Vector3 (-1f, -1f, 0f),
// new Vector3 (-1f, 3f, 0f),
// new Vector3 (3f, -1f, 0f)
// // new Vector3 (3f, -1f, 0f),
// // new Vector3 (-1f, 3f, 0f),
// // new Vector3 (-1f, -1f, 0f)
// });
// s_FullscreenTriangle.SetIndices(new[]
// {
// 0,
// 1,
// 2
// }, MeshTopology.Triangles, 0, false);
// s_FullscreenTriangle.UploadMeshData(false);
//
// meshTest = s_FullscreenTriangle;
// return s_FullscreenTriangle;
// }
// }
private bool canFind = false;
public override void Create()
{
if (Shader.Find("XuanXuan/ColorBlit") == null ||
Shader.Find("XuanXuan/Postprocess/NBPostProcessUber") == null)
{
canFind = false;
return;
}
else
{
canFind = true;
}
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_screenColorDownSampleMat = CoreUtils.CreateEngineMaterial(Shader.Find("XuanXuan/ColorBlit"));
#else
_screenColorDownSampleMat = CoreUtils.CreateEngineMaterial(Shader.Find("XuanXuan/ColorBufferBlit"));
#endif
_screenColorRenderPass = new ScreenColorRenderPass(_screenColorDownSampleMat, downSampling);
_screenColorRenderPass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
_profilingSampler = new ProfilingSampler("DisturbanceRender");
_disturbanceDownSampleMat = CoreUtils.CreateEngineMaterial(Shader.Find("XuanXuan/ColorBlit"));
_disturbanceMaskRenderPass = new DisturbanceMaskRenderPass(_profilingSampler,_disturbanceDownSampleMat,downSampling,disturbanceLayerMask);
_disturbanceMaskRenderPass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
#if !UNIVERSAL_RP_13_1_2_OR_NEWER
_profilingSampler = new ProfilingSampler("DisturbanceDownRTBlit");
#endif
if (fullscreenTriangle == null)
{
/*UNITY_NEAR_CLIP_VALUE*/
float nearClipZ = -1;
if (SystemInfo.usesReversedZBuffer)
nearClipZ = 1;
fullscreenTriangle = new Mesh();
fullscreenTriangle.vertices = GetFullScreenTriangleVertexPosition(nearClipZ);
fullscreenTriangle.uv = GetFullScreenTriangleTexCoord();
fullscreenTriangle.triangles = new int[3] { 0, 1, 2 };
}
// Shader shader = Shader.Find("XuanXuan/Postprocess/NBPostProcessUber");
NBPostProcessMaterial = CoreUtils.CreateEngineMaterial(Shader.Find("XuanXuan/Postprocess/NBPostProcessUber"));
PostProcessingManager.InitMat();
// if (Application.isPlaying)
// {
// manager = PostProcessingManager.Instance;
// }
_renderPass = new NBPostProcessRenderPass(NBPostProcessMaterial,fullscreenTriangle);
_renderPass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
}
#if UNIVERSAL_RP_13_1_2_OR_NEWER
public override void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData)
{
if ((renderingData.cameraData.cameraType == CameraType.Game ||
renderingData.cameraData.cameraType == CameraType.SceneView) && canFind)
{
//_disturbanceMaskRenderPass.SetUp(renderer.cameraDepthTargetHandle);
//if (renderingData.cameraData.cameraType == CameraType.Game)
//{
// _screenHeight = renderer.cameraDepthTargetHandle.rt.descriptor.height;
//}
_disturbanceMaskRenderPass.ConfigureInput(ScriptableRenderPassInput.Color);
_disturbanceMaskRenderPass.SetUp(renderer.cameraColorTargetHandle);
_screenColorRenderPass.ConfigureInput(ScriptableRenderPassInput.Color);
_screenColorRenderPass.SetUp(renderer.cameraColorTargetHandle);
}
}
#endif
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if ((renderingData.cameraData.cameraType == CameraType.Game ||
renderingData.cameraData.cameraType == CameraType.SceneView) && canFind)
{
#if !UNIVERSAL_RP_13_1_2_OR_NEWER
// _disturbanceMaskRenderPass.ConfigureInput(ScriptableRenderPassInput.Color);
// _disturbanceMaskRenderPass.SetUp(renderer.cameraColorTargetHandle);
_screenColorRenderPass.ConfigureInput(ScriptableRenderPassInput.Color);
_screenColorRenderPass.SetUp(renderer);
#endif
renderer.EnqueuePass(_screenColorRenderPass);
renderer.EnqueuePass(_disturbanceMaskRenderPass);
renderer.EnqueuePass(_renderPass);
}
}
// Should match Common.hlsl
static Vector3[] GetFullScreenTriangleVertexPosition(float z /*= UNITY_NEAR_CLIP_VALUE*/)
{
var r = new Vector3[3];
for (int i = 0; i < 3; i++)
{
Vector2 uv = new Vector2((i << 1) & 2, i & 2);
r[i] = new Vector3(uv.x * 2.0f - 1.0f, uv.y * 2.0f - 1.0f, z);
}
return r;
}
// Should match Common.hlsl
static Vector2[] GetFullScreenTriangleTexCoord()
{
var r = new Vector2[3];
for (int i = 0; i < 3; i++)
{
if (SystemInfo.graphicsUVStartsAtTop)
r[i] = new Vector2((i << 1) & 2, 1.0f - (i & 2));
else
r[i] = new Vector2((i << 1) & 2, i & 2);
}
return r;
}
protected override void Dispose(bool disposing)
{
CoreUtils.Destroy(_disturbanceDownSampleMat);
//CoreUtils.Destroy(NBPostProcessMaterial);
_disturbanceMaskRenderPass?.Dispose();
CoreUtils.Destroy(_screenColorDownSampleMat);
_screenColorRenderPass?.Dispose();
}
}
public class DisturbanceMaskRenderPass : ScriptableRenderPass
{
private ProfilingSampler _profilingSampler;
#if UNIVERSAL_RP_13_1_2_OR_NEWER
private RTHandle _DisturbanceMaskRTHandle;
private RTHandle _cameraDepthRTHandle;
private RTHandle _DownRT;
#else
private static readonly int _DisturbanceMaskRTID = Shader.PropertyToID("_DisturbanceMaskRT");
private static readonly int _DownRTID = Shader.PropertyToID("_DisturbanceMaskTex");
private RenderTargetIdentifier _DisturbanceMaskRTHandle = new RenderTargetIdentifier (_DisturbanceMaskRTID);
private RenderTargetIdentifier _cameraDepthRTHandle;
private RenderTargetIdentifier _DownRT = new RenderTargetIdentifier (_DownRTID);
#endif
private Material tempMat;
private readonly Downsampling _downSampling;
//private readonly MaskFormat _maskFormat;
private Material _renderMaskMat ;
public LayerMask _DisturbanceMaskLayer = 1 << 25;
private FilteringSettings _Filtering;
private static readonly int CameraTexture = Shader.PropertyToID("_CameraTexture");
private static readonly int SampleOffset = Shader.PropertyToID("_SampleOffset");
private readonly List<ShaderTagId> _shaderTag = new List<ShaderTagId>()
{
new ShaderTagId("UniversalForward"),
new ShaderTagId("SRPDefaultUnlit"),
new ShaderTagId("UniversalForwardOnly")
};
public DisturbanceMaskRenderPass(ProfilingSampler profilingSampler,Material DisturbanceMaskMat, Downsampling downSampling,LayerMask disturbanceMaskLayer)
{
_profilingSampler = profilingSampler;
_renderMaskMat = DisturbanceMaskMat;
_downSampling = downSampling;
_DisturbanceMaskLayer = disturbanceMaskLayer;
}
#if UNIVERSAL_RP_13_1_2_OR_NEWER
public void SetUp ( RTHandle cameraRTHandle )
{
RenderTextureDescriptor descrip = cameraRTHandle.rt.descriptor;
descrip.colorFormat = RenderTextureFormat.RG32;
descrip.depthBufferBits = 0;
RenderingUtils.ReAllocateIfNeeded(ref _DisturbanceMaskRTHandle, descrip, name: "DisturbanceMaskRT");
switch (_downSampling)
{
case Downsampling._2xBilinear:
descrip.width /= 2;
descrip.height /= 2;
break;
case Downsampling._4xBilinear:
descrip.width /= 4;
descrip.height /= 4;
break;
case Downsampling._4xBox:
descrip.width /= 4;
descrip.height /= 4;
break;
}
RenderingUtils.ReAllocateIfNeeded(ref _DownRT, descrip, name:"MaskDownCopyRT");
}
#else
//在AddPass之前触发
public void SetUpDisturbanceMask(RenderTextureDescriptor descrip ,CommandBuffer cmd)
{
descrip.colorFormat = RenderTextureFormat.RG32;
descrip.depthBufferBits = 0;
cmd.GetTemporaryRT(_DisturbanceMaskRTID, descrip,FilterMode.Bilinear);
switch (_downSampling)
{
case Downsampling._2xBilinear:
descrip.width /= 2;
descrip.height /= 2;
break;
case Downsampling._4xBilinear:
descrip.width /= 4;
descrip.height /= 4;
break;
case Downsampling._4xBox:
descrip.width /= 4;
descrip.height /= 4;
break;
}
cmd.GetTemporaryRT(_DownRTID, descrip,FilterMode.Bilinear);
}
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
_Filtering = new FilteringSettings(RenderQueueRange.all, _DisturbanceMaskLayer);
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_cameraDepthRTHandle = renderingData.cameraData.renderer.cameraDepthTargetHandle;
#else
_cameraDepthRTHandle = renderingData.cameraData.renderer.cameraDepthTarget;
SetUpDisturbanceMask(renderingData.cameraData.cameraTargetDescriptor,cmd);
#endif
}
private readonly Color _clearDisturbanceMaskColor = new Color(0.5f, 0.5f, 0f, 1f);
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
#if UNIVERSAL_RP_13_1_2_OR_NEWER
ConfigureTarget(_DisturbanceMaskRTHandle, _cameraDepthRTHandle);
#else
ConfigureTarget(_DisturbanceMaskRTID, _cameraDepthRTHandle);
#endif
//将RT清空
ConfigureClear(ClearFlag.Color, _clearDisturbanceMaskColor);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (!(renderingData.cameraData.cameraType == CameraType.Game || renderingData.cameraData.cameraType == CameraType.SceneView))
return;
if (!_renderMaskMat)
{
return;
}
var DisturbanceDraw = CreateDrawingSettings(_shaderTag, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);
CommandBuffer cmd = CommandBufferPool.Get();
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);
switch (_downSampling)
{
case Downsampling._2xBilinear:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
break;
case Downsampling._4xBilinear:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
break;
case Downsampling._4xBox:
_renderMaskMat.SetFloat(SampleOffset, 2);
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 1);
break;
default:
Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
break;
}
#else
// cmd.SetGlobalTexture(_DisturbanceMaskRTID, _DisturbanceMaskRTHandle);
//Bug:在非播放状态时_DisturbanceMaskRTID在这里会经常丢失。造成画面闪烁。但是只要有一个DistortObject在Scene中并LockInspector就不会闪烁非常奇怪。
cmd.SetGlobalTexture(CameraTexture, _DisturbanceMaskRTHandle);
// _renderMaskMat.SetTexture(CameraTexture, Shader.GetGlobalTexture(_DisturbanceMaskRTID));
cmd.SetRenderTarget(_DownRT);
switch (_downSampling)
{
case Downsampling._2xBilinear:
// Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.Blit(_DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _renderMaskMat, 0, 2);
Blit(cmd, _DisturbanceMaskRTHandle,_DownRT,_renderMaskMat,0);
break;
case Downsampling._4xBilinear:
// Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.Blit(_DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _renderMaskMat, 0, 2);
Blit(cmd, _DisturbanceMaskRTHandle,_DownRT,_renderMaskMat,0);
break;
case Downsampling._4xBox:
_renderMaskMat.SetFloat(SampleOffset, 2);
// Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 1);
// cmd.Blit(_DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 1);
// cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _renderMaskMat, 0, 3);
Blit(cmd, _DisturbanceMaskRTHandle,_DownRT,_renderMaskMat,1);
break;
default:
// Blitter.BlitTexture(cmd, _DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.Blit(_DisturbanceMaskRTHandle, _DownRT, _renderMaskMat, 0);
// cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _renderMaskMat, 0, 2);
Blit(cmd, _DisturbanceMaskRTHandle,_DownRT,_renderMaskMat,0);
break;
}
#endif
cmd.SetGlobalTexture("_DisturbanceMaskTex", _DownRT);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
#if !UNIVERSAL_RP_13_1_2_OR_NEWER
// Cleanup any allocated resources that were created during the execution of this render pass.
public override void OnCameraCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(_DisturbanceMaskRTID);
cmd.ReleaseTemporaryRT(_DownRTID);
}
//JustForSimple
public void Dispose()
{
}
#else
public void Dispose()
{
_DisturbanceMaskRTHandle?.Release();
_DownRT?.Release();
}
#endif
}
public class NBPostProcessRenderPass : ScriptableRenderPass
{
private ProfilingSampler _profilingSampler;
public static Material _material;
public Mesh _fullScreenMesh;
public NBPostProcessFlags _shaderFlag => PostProcessingManager.flags;
private Vector4 _lastOutlineProps;
public Vector4 outLinePorps = Vector4.one;
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (!(renderingData.cameraData.cameraType == CameraType.Game || renderingData.cameraData.cameraType == CameraType.SceneView))
return;
// if(!_shaderFlag.CheckFlagBits(NBPostProcessFlags.FLAG_BIT_NB_POSTPROCESS_ON))return;//Disturbance需要执行
//ConfigureTarget()
CommandBuffer cmdBuffer = CommandBufferPool.Get();
cmdBuffer.Clear();
// cmdBuffer.name = "NBPostProcess";
using (new ProfilingScope(cmdBuffer,_profilingSampler))
{
Camera camera = renderingData.cameraData.camera;
cmdBuffer.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
if(_material == null) return;
cmdBuffer.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material, 0, 0);
cmdBuffer.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
}
context.ExecuteCommandBuffer(cmdBuffer);
CommandBufferPool.Release(cmdBuffer);
}
public NBPostProcessRenderPass(Material mat,Mesh mesh)
{
_material = mat;
_fullScreenMesh = mesh;
_profilingSampler ??= new ProfilingSampler("NBPostProcess");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d5a1f9350d8fc2c46a372955ef0e73b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using UnityEngine;
public class NBPostProcessFlags: ShaderFlagsBase
{
public const string FlagsName = "_NBPostProcessFlags";
public static int FlagsId = Shader.PropertyToID(FlagsName);
protected override int GetShaderFlagsId(int index = 0)
{
return FlagsId;
}
protected override string GetShaderFlagsName(int index = 0)
{
return FlagsName;
}
public NBPostProcessFlags(Material material = null): base(material)
{
}
public const int FLAG_BIT_NB_POSTPROCESS_ON = 1 << 0;
public const int FLAG_BIT_DISTORT_SPEED = 1 << 1;
public const int FLAG_BIT_OVERLAYTEXTURE = 1 << 2;
public const int FLAG_BIT_FLASH = 1 << 3;
public const int FLAG_BIT_CHORATICABERRAT = 1 << 4;
public const int FLAG_BIT_RADIALBLUR = 1 << 5;
public const int FLAG_BIT_VIGNETTE = 1 << 6;
public const int FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD = 1 << 7;
public const int FLAG_BIT_OVERLAYTEXTURE_MASKMAP = 1 << 8;
public const int FLAG_BIT_POST_DISTORT_SCREEN_UV = 1 << 9;//默认来自于PolarUV
public const int FLAG_BIT_RADIALBLUR_BY_DISTORT = 1 << 10;//默认来自于PolarUV
public const int FLAG_BIT_CHORATICABERRAT_BY_DISTORT = 1 << 11;//默认来自于PolarUV
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be6a95b97f4bc3846bdada66138f6da1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,602 @@
using System;
using UnityEngine;
// using Sirenix.OdinInspector;
#if CINIMACHINE_3_0
using Unity.Cinemachine;
#endif
// using Unity.Cinemachine.Editor;
#if UNITY_EDITOR
using UnityEditor.AnimatedValues;
using UnityEditor;
#endif
[ExecuteInEditMode]
public class PostProcessingController : MonoBehaviour
{
#if UNITY_EDITOR
public AnimBool[] AnimBools = new AnimBool[10];
#endif
// [ShowInInspector][ReadOnly]
[SerializeField]
private PostProcessingManager _manager;
public int index
{
get
{
return _index;
}
}
// [ShowInInspector][ReadOnly]
private int _index;
public void SetIndex(int controllerIndex)
{
_index = controllerIndex;
}
// [OnValueChanged("SetScreenCenterPos")]
// [LabelText("自定义屏幕中心")]
public Vector2 customScreenCenterPos = new Vector2(0.5f, 0.5f);
private Vector2 _lastCustomScreenCenterPos = new Vector2(0.5f, 0.5f);
// [OnValueChanged("SetToggles")]
// [ToggleGroup("chromaticAberrationToggle", "色散")]
// [OnValueChanged("InitAllSettings")]
public bool chromaticAberrationToggle = false;
// [OnValueChanged("SetUVFromDistort")]
// [LabelText("色散UV跟随后处理扭曲")]
// [ToggleGroup("chromaticAberrationToggle")]
public bool caFromDistort = false;
// [LabelText("色散强度")]
// [ToggleGroup("chromaticAberrationToggle")]
public float chromaticAberrationIntensity = 0.2f;
// [HideIf("caFromDistort")]
// [LabelText("色散位置")]
// [ToggleGroup("chromaticAberrationToggle")]
public float chromaticAberrationPos = 0.5f;
// [HideIf("caFromDistort")]
// [LabelText("色散过渡范围")]
// [ToggleGroup("chromaticAberrationToggle")]
public float chromaticAberrationRange = 0.5f;
// [OnValueChanged("SetToggles")]
// [ToggleGroup("distortSpeedToggle", "扭曲")]
public bool distortSpeedToggle = false;
// [ToggleGroup("distortSpeedToggle")]
// [LabelText("后处理走常规屏幕坐标")]
// [OnValueChanged("SetUVFromDistort")]
public bool distortScreenUVMode = false;
// [LabelText("后处理扭曲")]
// [ToggleGroup("distortSpeedToggle")]
// [OnValueChanged("InitAllSettings")]
public Texture2D distortSpeedTexture;
// [LabelText("扭曲贴图中间值")]
// [ToggleGroup("distortSpeedToggle")]
// [OnValueChanged("SetTexture")]
public float distortTextureMidValue = 1;
// [LabelText("扭曲贴图ST")]
// [ToggleGroup("distortSpeedToggle")]
public Vector4 distortSpeedTexSt = new Vector4(30,1,0,0);
// [LabelText("扭曲强度")]
// [ToggleGroup("distortSpeedToggle")]
public float distortSpeedIntensity = 1f;
// [HideIf("distortScreenUVMode")]
// [LabelText("扭曲位置")]
// [ToggleGroup("distortSpeedToggle")]
public float distortSpeedPosition = 0.5f;
// [HideIf("distortScreenUVMode")]
// [LabelText("扭曲范围")]
// [ToggleGroup("distortSpeedToggle")]
public float distortSpeedRange = 1f;
// [LabelText("扭曲纹理流动X")]
// [ToggleGroup("distortSpeedToggle")]
public float distortSpeedMoveSpeedX = 0.1f;
// [LabelText("扭曲纹理流动Y")]
// [ToggleGroup("distortSpeedToggle")]
public float distortSpeedMoveSpeed = -0.5f;//因为老的做法是没有X偏移的只有Y的偏移不改变量兼容老做法。
private readonly int _distortSpeedTextureID = Shader.PropertyToID("_SpeedDistortMap");
private readonly int _distortSpeedTextureStID = Shader.PropertyToID("_SpeedDistortMap_ST");
// [ToggleGroup("radialBlurToggle", "径向模糊")]
// [OnValueChanged("InitAllSettings")]
public bool radialBlurToggle = false;
// [OnValueChanged("SetUVFromDistort")]
// [ToggleGroup("radialBlurToggle")] [LabelText("径向模糊跟随后处理扭曲")]
public bool radialBlurFromDistort = false;
// [ToggleGroup("radialBlurToggle")]
// [LabelText("采样次数")]
[Range(1,12)]
public int radialBlurSampleCount = 4;
// [ToggleGroup("radialBlurToggle")]
// [LabelText("强度")]
public float radialBlurIntensity = 1;
// [HideIf("radialBlurFromDistort")]
// [LabelText("位置")]
// [ToggleGroup("radialBlurToggle")]
public float radialBlurPos = 0.5f;
// [HideIf("radialBlurFromDistort")]
// [LabelText("过度范围")]
// [ToggleGroup("radialBlurToggle")]
public float radialBlurRange = 0.5f;
#if CINIMACHINE_3_0
// [OnValueChanged("SetToggles")]
// [ToggleGroup("cameraShakeToggle", "震屏")]
// [OnValueChanged("InitAllSettings")]
public bool cameraShakeToggle = false;
// [ToggleGroup("cameraShakeToggle")]
// [LabelText("绑定Cinemachine相机")]
// [OnValueChanged("InitCinemachineCamera")]
public CinemachineCamera cinemachineCamera;
// [ToggleGroup("cameraShakeToggle")]
// [LabelText("相机震动强度")]
public float cameraShakeIntensity;
#endif
// [ToggleGroup("overlayTextureToggle", "肌理叠加图")]
// [OnValueChanged("InitAllSettings")]
public bool overlayTextureToggle = false;
// [LabelText("肌理图极坐标模式")] [ToggleGroup("overlayTextureToggle")]
// [OnValueChanged("SetTexture")]
public bool overlayTexturePolarCoordMode = false;
// [ToggleGroup("overlayTextureToggle")]
// [LabelText("肌理图")]
// [OnValueChanged("SetTexture")]
public Texture2D overlayTexture;
private readonly int _overlayTextureID = Shader.PropertyToID("_TextureOverlay");
private readonly int _overlayTextureStID = Shader.PropertyToID("_TextureOverlay_ST");
private readonly int _textureOverlayAnimProperty = Shader.PropertyToID("_TextureOverlayAnim");
private readonly int _textureOverlayMaskProperty = Shader.PropertyToID("_TextureOverlayMask");
private readonly int _textureOverlayMaskStProperty = Shader.PropertyToID("_TextureOverlayMask_ST");
// [LabelText("肌理图缩放平移")] [ToggleGroup("overlayTextureToggle")]
public Vector4 overlayTextureSt = new Vector4(1, 1, 0, 0);
// [LabelText("肌理图偏移动画")] [ToggleGroup("overlayTextureToggle")]
public Vector2 overlayTextureAnim = new Vector2(0, 0);
// [LabelText("肌理图强度")] [ToggleGroup("overlayTextureToggle")]
public float overlayTextureIntensity = 1f;
// [LabelText("肌理图蒙板")] [ToggleGroup("overlayTextureToggle")]
// [OnValueChanged("SetTexture")]
public Texture2D overlayMaskTexture;
// [LabelText("肌理图蒙板缩放平移")] [ToggleGroup("overlayTextureToggle")]
public Vector4 overlayMaskTextureSt;
// [ToggleGroup("flashToggle", "反闪")]
// [OnValueChanged("InitAllSettings")]
public bool flashToggle = false;
// [LabelText("反转度")] [ToggleGroup("flashToggle")]
public float flashInvertIntensity = 1f;
// [LabelText("饱和度")] [ToggleGroup("flashToggle")]
public float flashDeSaturateIntensity = 1f;
// [LabelText("对比度")] [ToggleGroup("flashToggle")]
public float flashContrast = 1f;
public Color flashColor = new Color(1f,1f,1f,1f);
// [ToggleGroup("vignetteToggle", "暗角")]
// [OnValueChanged("InitAllSettings")]
public bool vignetteToggle = false;
// [ToggleGroup("vignetteToggle")]
// [LabelText("暗角颜色")]
public Color vignetteColor = Color.black;
private readonly int _vignetteColorID = Shader.PropertyToID("_VignetteColor");
// [ToggleGroup("vignetteToggle")]
// [LabelText("暗角强度")]
public float vignetteIntensity = 1;
// [ToggleGroup("vignetteToggle")]
// [LabelText("暗角圆度")]
public float vignetteRoundness = 1;
// [ToggleGroup("vignetteToggle")]
// [LabelText("暗角平滑度")]
public float vignetteSmothness = 10;
public void InitController()
{
if (this.isActiveAndEnabled == false)
{
return;
}
_manager = PostProcessingManager.Instance;
_manager.InitController(this);
InitAllSettings();
}
void InitAllSettings()
{
SetScreenCenterPos();
SetToggles();
SetUVFromDistort();
SetTexture();
#if CINIMACHINE_3_0
InitCinemachineCamera();
#endif
}
void SetScreenCenterPos()
{
PostProcessingManager.customScreenCenterPos = customScreenCenterPos;
_lastCustomScreenCenterPos = customScreenCenterPos;
}
void SetUVFromDistort()
{
PostProcessingManager.isDistortScreenUVMode = distortScreenUVMode;
PostProcessingManager.isCaByDistort = caFromDistort;
PostProcessingManager.isRadialBlurByDistort = radialBlurFromDistort;
}
private void SetTexture()
{
if(PostProcessingManager.material == null) return;
if (distortSpeedToggle)
{
if (distortSpeedTexture != null)
{
PostProcessingManager.material.SetTexture(_distortSpeedTextureID, distortSpeedTexture);
PostProcessingManager.distortTextureMidValue = distortTextureMidValue;
}
else
{
PostProcessingManager.material.SetTexture(_distortSpeedTextureID, null);
}
}
if (overlayTextureToggle)
{
if (overlayTexturePolarCoordMode)
{
PostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
}
else
{
PostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD);
}
if (overlayTexture)
{
Debug.Log("SetOverlayTexture");
PostProcessingManager.material.SetTexture(_overlayTextureID,overlayTexture);
}
else
{
Debug.Log("ClearOverlayTexture");
PostProcessingManager.material.SetTexture(_overlayTextureID,null);
}
if (overlayMaskTexture)
{
Debug.Log("SetOverlayMaskTexture");
PostProcessingManager.material.SetTexture(_textureOverlayMaskProperty,overlayMaskTexture);
PostProcessingManager.flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
}
else
{
Debug.Log("ClearOverlayMaskTexture");
PostProcessingManager.flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE_MASKMAP);
}
}
}
private void SetToggles()
{
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 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();
#endif
}
private void ClearToggles()
{
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 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;
private bool _lastDistortSpeedToggle = false;
#if CINIMACHINE_3_0
private bool _lastCamerashakeToggle = false;
#endif
private bool _lastOverlayTextureToggle = false;
private bool _lastFlashToggle= false;
private bool _lastRadialBlurToggle= false;
private bool _lastVignetteToggle= false;
bool checkIfToggleChanged(ref bool lastTogggle, bool currentToggle)
{
if (lastTogggle != currentToggle)
{
lastTogggle = currentToggle;
return true;
}
else
{
return false;
}
}
private static void SetBit(ref int bit, int index,bool bitToggle)
{
if (bitToggle)
{
bit |= (1 << index);
}
else
{
bit &= ~(1 << index);
}
}
// [LabelText("跳过数值锁定")] public bool isSkipUpdate = false;
#if UNITY_EDITOR
// [Button("选择当前Manager")]
void FindManager()
{
UnityEditor.Selection.activeObject = _manager.gameObject;
}
#if CINIMACHINE_3_0
// [Button("选择当前VituralCamera")]
public void FindVirtualCamera()
{
UnityEditor.Selection.activeObject = _manager.currentVirtualCamera;
}
public void InitCinemachineCamera()
{
if (cinemachineCamera)
{
// _perlin = ;
if (!cinemachineCamera.gameObject.TryGetComponent<CinemachineBasicMultiChannelPerlin>(out var _perlin))
{
_perlin = cinemachineCamera.gameObject.AddComponent<CinemachineBasicMultiChannelPerlin>();
}
if (_perlin)
{
_perlin.NoiseProfile =
UnityEditor.AssetDatabase.LoadAssetAtPath<NoiseSettings>(
"Packages/com.xuanxuan.nb.postprocessing/3DPostionShake.asset");
_perlin.FrequencyGain = 5f; //做一个自定义
_perlin.AmplitudeGain = 0f; //一开始先不要震动
}
#if UNITY_EDITOR
if (_manager)
{
_manager.currentVirtualCamera = cinemachineCamera;
}
#endif
}
}
#endif
#endif
private void OnEnable()
{
// Debug.Log("InitController");
InitController();
#if UNITY_EDITOR
// 注册编辑器帧更新事件
EditorApplication.update += ControllerEditorUpdate;
_manager.ReRegistEditorUpdate();//保证Manager的注册在最后
#endif
}
private void OnDisable()
{
// Debug.Log("EndController");
EndController();
#if UNITY_EDITOR
// 注册编辑器帧更新事件
EditorApplication.update -= ControllerEditorUpdate;
#endif
}
bool isFirstUpdate = true;
// Update is called once per frame
void Update()
{
if (isFirstUpdate)
{
isFirstUpdate = false;
return;
}
if(!PostProcessingManager.material) return;
//#if UNITY_EDITOR
//Odin的ToggleGroup和OnValueChange功能冲突导致不一定生效。不好调试。所以用手动的方式更新。
bool isToggleChanged = false;
isToggleChanged |= checkIfToggleChanged(ref _lastChormaticAberrationToggle, chromaticAberrationToggle);
isToggleChanged |= checkIfToggleChanged(ref _lastDistortSpeedToggle, distortSpeedToggle);
#if CINIMACHINE_3_0
isToggleChanged |= checkIfToggleChanged(ref _lastCamerashakeToggle, cameraShakeToggle);
#endif
isToggleChanged |= checkIfToggleChanged(ref _lastOverlayTextureToggle, overlayTextureToggle);
isToggleChanged |= checkIfToggleChanged(ref _lastFlashToggle, flashToggle);
isToggleChanged |= checkIfToggleChanged(ref _lastRadialBlurToggle, radialBlurToggle);
isToggleChanged |= checkIfToggleChanged(ref _lastVignetteToggle, vignetteToggle);
if (isToggleChanged)
{
SetToggles();
}
//#endif
if (customScreenCenterPos != _lastCustomScreenCenterPos)
{
SetScreenCenterPos();
}
if (chromaticAberrationToggle)
{
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 == PostProcessingManager.laseUpdateControllerIndex)
{
//只有这里才会更新Scale
PostProcessingManager.material.SetVector(_distortSpeedTextureStID, distortSpeedTexSt);
}
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;
PostProcessingManager.distortSpeedMoveSpeedY =
Mathf.Abs(PostProcessingManager.distortSpeedMoveSpeedY) > Mathf.Abs(distortSpeedMoveSpeed)
? PostProcessingManager.distortSpeedMoveSpeedY
: distortSpeedMoveSpeed;
}
#if CINIMACHINE_3_0
if (cameraShakeToggle)
{
PostProcessingManager.cameraShakeIntensity =
Mathf.Max(PostProcessingManager.cameraShakeIntensity, cameraShakeIntensity);
}
#endif
if (overlayTextureToggle)
{
if (index == PostProcessingManager.laseUpdateControllerIndex)
{
PostProcessingManager.material.SetVector(_overlayTextureStID, overlayTextureSt);
PostProcessingManager.material.SetVector(_textureOverlayMaskStProperty, overlayMaskTextureSt);
PostProcessingManager.material.SetVector(_textureOverlayAnimProperty,overlayTextureAnim);
}
PostProcessingManager.overlayTextureIntensity = Mathf.Max(PostProcessingManager.overlayTextureIntensity,
overlayTextureIntensity);
}
if (flashToggle)
{
PostProcessingManager.flashDesaturateIntensity =
Mathf.Max(PostProcessingManager.flashDesaturateIntensity, flashDeSaturateIntensity);
PostProcessingManager.flashInvertIntensity =
Mathf.Max(PostProcessingManager.flashInvertIntensity, flashInvertIntensity);
PostProcessingManager.flashContrast =
Mathf.Max(PostProcessingManager.flashContrast, flashContrast);
PostProcessingManager.flashColor = flashColor;
}
if (radialBlurToggle)
{
PostProcessingManager.radialBlurIntensity =
Mathf.Max(PostProcessingManager.radialBlurIntensity, radialBlurIntensity);
PostProcessingManager.radialBlurSampleCount = Mathf.Max(PostProcessingManager.radialBlurSampleCount,
radialBlurSampleCount);
PostProcessingManager.radialBlurPos = Mathf.Max(PostProcessingManager.radialBlurPos, radialBlurPos);
PostProcessingManager.radialBlurRange = Mathf.Max(PostProcessingManager.radialBlurRange, radialBlurRange);
}
if (vignetteToggle)
{
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)
{
PostProcessingManager.material.SetColor(_vignetteColorID,vignetteColor);
}
}
}
void EndController()
{
ClearToggles();
_manager.EndController(this);
}
#if UNITY_EDITOR
[UnityEditor.MenuItem("GameObject/创建NB后处理特效")]
static void CreatMenu()
{
GameObject Effect = new GameObject();
Effect.name = "NBPostprocessController";
PostProcessingController controller = Effect.AddComponent<PostProcessingController>();
UnityEditor.Selection.activeObject = Effect;
}
void ControllerEditorUpdate()
{
if (!Application.isPlaying)
{
Update();
}
}
#endif
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 909ea7d136ae0c349a24f02cac1f5f71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- manager: {instanceID: 0}
- distortSpeedTexture: {fileID: 2800000, guid: 7f808d0c8608b954d8f20cb4132c3049, type: 3}
- overlayTexture: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,720 @@
using System;
using UnityEngine;
// using Sirenix.OdinInspector;
// #if UNITY_EDITOR
// using Sirenix.OdinInspector.Editor;
// #endif
#if UNITY_EDITOR
using UnityEditor;
#endif
#if CINIMACHINE_3_0
using Unity.Cinemachine;
#endif
using MhRender.RendererFeatures;
[ExecuteAlways]
public class PostProcessingManager : MonoBehaviour
{
//单例实现
private static PostProcessingManager _instance = null;
public static PostProcessingManager Instance
{
get
{
if (_instance == null)
{
#if UNITY_2022_1_OR_NEWER
_instance = FindFirstObjectByType<PostProcessingManager>();
#else
_instance = FindObjectOfType<PostProcessingManager>();
#endif
if (_instance == null)
{
GameObject singletonObj = new GameObject();
_instance = singletonObj.AddComponent<PostProcessingManager>();
if (Application.isPlaying)
{
singletonObj.name = "NBPostProcessManager";
DontDestroyOnLoad(singletonObj);
}
else
{
singletonObj.name = "测试用NB后处理管理器请美术删除此脚本再上传";
}
}
}
return _instance;
}
}
private void Awake()
{
if (_instance == null)
{
_instance = this;
}
else
{
DestroyImmediate(this);
}
}
// [ReadOnly] public Volume volume;
// private static VolumeProfile profile;
// [ReadOnly]
public static Material material
{
get
{
return NBPostProcess.NBPostProcessMaterial;
}
}
public static NBPostProcessFlags flags = new NBPostProcessFlags();
// public CinemachineBrain cameraBrain;
// public CinemachineVirtualCamera currentVirtualCamera;
#if CINIMACHINE_3_0
public CinemachineCamera currentVirtualCamera;
private CinemachineBasicMultiChannelPerlin _perlin;
#endif
public static void InitMat()
{
flags.SetMaterial(PostProcessingManager.material);
if (_instance)
{
_instance.ResetEffect();
}
}
private void OnEnable()
{
#if UNITY_EDITOR
if (_controllerIndexFlags > 0)
{
ReRegistEditorUpdate();
}
else
{
EditorApplication.update += EditorUpdate;
}
// 注册编辑器帧更新事件
#endif
// //TODO 后续版本要找比较准确快的找Volume的方式
// volume = GameObject.FindObjectOfType<Volume>();
// if (volume != null)
// {
// profile = volume.profile;
// }
// #if UNITY_EDITOR
// //仅仅用于测试。
// if (currentVirtualCamera == null)
// {
// currentVirtualCamera = FindFirstObjectByType<CinemachineCamera>();
//
// if (currentVirtualCamera)
// {
// if (!currentVirtualCamera.gameObject.TryGetComponent<CinemachineBasicMultiChannelPerlin>(out _perlin))
// {
// _perlin = currentVirtualCamera.gameObject.AddComponent<CinemachineBasicMultiChannelPerlin>();
// }
// }
//
// if (_perlin)
// {
// _perlin.NoiseProfile =
// // ResourceManager.LoadAssetAsync<NoiseSettings>("Assets/AddressableAssets/Shader/CustomPostprocess/3DPostionShake.asset");
// //在runtime下是找不到的。但设计是美术做好然后存引用在预制件里。
// UnityEditor.AssetDatabase.LoadAssetAtPath<NoiseSettings>(
// "Packages/com.r2.render.postprocessing/3DPostionShake.asset");
// _perlin.FrequencyGain = 5f; //做一个自定义
// _perlin.AmplitudeGain = 0f; //一开始先不要震动
// }
// }
//
// #endif
//重置Flag
flags = new NBPostProcessFlags(material);
flags.SetFlagBits(0);
}
private void OnDisable()
{
#if UNITY_EDITOR
// 注册编辑器帧更新事件
EditorApplication.update -= EditorUpdate;
#endif
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_NB_POSTPROCESS_ON);
}
// [ShowInInspector]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
private int _controllerIndexFlags = 0;
public static int laseUpdateControllerIndex;
private int GetControllerIndex()
{
for (int i = 0; i < 31; i++)
{
if (((~_controllerIndexFlags) & (1 << i)) != 0)
{
_controllerIndexFlags |= (1 << i);
laseUpdateControllerIndex = i;
return i;
}
}
return 32;
}
private void ReleaseControllerIndex(int index)
{
_controllerIndexFlags &= ~(1 << index);
}
private int CountBit(int bit)
{
int count = 0;
while (bit > 0)
{
bit = bit & (bit - 1);
count++;
}
return count;
}
//每次Controller触发Play都会触发Init
public void InitController(PostProcessingController controller)
{
#if CINIMACHINE_3_0
if (controller.cinemachineCamera != null)
{
currentVirtualCamera = controller.cinemachineCamera;
_perlin = currentVirtualCamera.gameObject.GetComponent<CinemachineBasicMultiChannelPerlin>();
}
#endif
controller.SetIndex(GetControllerIndex());
}
public void EndController(PostProcessingController controller)
{
#if CINIMACHINE_3_0
if (currentVirtualCamera == controller.cinemachineCamera)
{
currentVirtualCamera = null;
_perlin = null;
}
#endif
ReleaseControllerIndex(controller.index);
controller.SetIndex(32); //设置32为关闭index
}
private void EffectUpdater(Action initEffect,Action updateEffect,Action endEffect,ref bool lastIsEffect,int effectToggles)
{
if (effectToggles > 0)
{
if (!lastIsEffect)
{
initEffect();
}
updateEffect();
lastIsEffect = true;
}
else
{
if (lastIsEffect)
{
endEffect();
lastIsEffect = false;
}
}
}
private bool isFirstUpdate = true;
private void ResetEffect()
{
if (_lastIsChromaticAberration)
{
EndChromaticAberration();
_lastIsChromaticAberration = false;
}
if (_lastIsRadialBlur)
{
EndRadialBlur();
_lastIsRadialBlur = false;
}
if (_lastIsDistortSpeed)
{
EndDistortSpeed();
_lastIsDistortSpeed = false;
}
#if CINIMACHINE_3_0
if (_lastIsCameraShake)
{
EndCameraShake();
_lastIsCameraShake = false;
}
#endif
if (_lastIsOverlayTexture)
{
EndOverlayTexture();
_lastIsOverlayTexture = false;
}
if (_lastIsFlash)
{
EndFlash();
_lastIsFlash = false;
}
if (_lastIsVignette)
{
EndVignette();
_lastIsVignette = false;
}
}
private void LateUpdate()//晚于所有脚本触发。
{
if (isFirstUpdate)
{
isFirstUpdate = false;
return;
}
if(!material) return;
/*
#if UNITY_EDITOR
if (flags.GetMaterial() != PostProcessingManager.material)
{
flags.SetMaterial(PostProcessingManager.material);
}
#endif
*/
if (_controllerIndexFlags == 0)
{
ResetEffect();
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_NB_POSTPROCESS_ON);
return;
}
EffectUpdater(InitChromaticAberration,UpdateChromaticAberration,EndChromaticAberration,ref _lastIsChromaticAberration,chromaticAberrationToggles);
EffectUpdater(InitDistortSpeed,UpdateDistortSpeed,EndDistortSpeed,ref _lastIsDistortSpeed,distortSpeedToggles);
EffectUpdater(InitRadialBlur, UpdateRadialBlur, EndRadialBlur,ref _lastIsRadialBlur, radialBlurToggles);
bool isSetCustomScreenCenterPos = (chromaticAberrationToggles | distortSpeedToggles | radialBlurToggles) > 0;
if (isSetCustomScreenCenterPos)
{
material.SetVector(_customScreenCenterProperty,
new Vector4(customScreenCenterPos.x, customScreenCenterPos.y, 0, 0));
}
#if CINIMACHINE_3_0
EffectUpdater(() => { },UpdateCameraShake,EndCameraShake,ref _lastIsCameraShake,cameraShakeToggles);
#endif
EffectUpdater(InitOverlayTexture, UpdateOverlayTexture, EndOverlayTexture,ref _lastIsOverlayTexture, overlayTextureToggles);
EffectUpdater(InitFlash, UpdateFlash, EndFlash,ref _lastIsFlash, flashToggles);
EffectUpdater(InitVignette, UpdateVignette, EndVignette,ref _lastIsVignette, vignetteToggles);
bool hasEffect =
(
chromaticAberrationToggles|
distortSpeedToggles|
#if CINIMACHINE_3_0
cameraShakeToggles|
#endif
radialBlurToggles|
overlayTextureToggles|
flashToggles|
vignetteToggles
) >0;
if (hasEffect)
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_NB_POSTPROCESS_ON);
}
else
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_NB_POSTPROCESS_ON);
}
}
private readonly int _customScreenCenterProperty = Shader.PropertyToID("_CustomScreenCenter");
public static Vector2 customScreenCenterPos = new Vector2(0.5f, 0.5f);
#region
//色散相关
// private ChromaticAberration chromaticAberrationComp;
// private bool preserveChromaticAberrationActive;
// private float preserveChromaticAberrationIntensity;
private bool _lastIsChromaticAberration = false;
private readonly int _chromaticAberrationVecProperty = Shader.PropertyToID("_ChromaticAberrationVec");
public static int chromaticAberrationToggles = 0;
public static bool isCaByDistort= false;
private bool _lastIsCaByDistort = false;
public static float chromaticAberrationIntensity = 0;
public static float chromaticAberrationPos = 0;
public static float chromaticAberrationRange = 0;
private void InitChromaticAberration()
{
// Debug.Log("InitCA");
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_CHORATICABERRAT);
}
private void UpdateChromaticAberration()
{
if (_lastIsCaByDistort != isCaByDistort)
{
if (isCaByDistort)
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_CHORATICABERRAT_BY_DISTORT);
}
else
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_CHORATICABERRAT_BY_DISTORT);
}
_lastIsCaByDistort = isCaByDistort;
}
material.SetVector(_chromaticAberrationVecProperty, new Vector4(chromaticAberrationIntensity,chromaticAberrationPos,chromaticAberrationRange));
chromaticAberrationIntensity = 0;//等待下一次update
chromaticAberrationPos = 0;//等待下一次update
chromaticAberrationRange = 0;//等待下一次update
}
private void EndChromaticAberration()
{
// Debug.Log("EndCA");
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_CHORATICABERRAT);
}
#endregion
#region
//径向速度扭曲相关
private readonly int _distortVecProperty = Shader.PropertyToID("_SpeedDistortVec");
private readonly int _distortVec2Property = Shader.PropertyToID("_SpeedDistortVec2");
private bool _lastIsDistortSpeed = false;
public static bool isDistortScreenUVMode;
private bool _lastIsDistortScreenUVMode;
// [ShowInInspector]
// [LabelText("径向扭曲开关")]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
public static int distortSpeedToggles;
public static Texture2D distortTexture2D;
public static float distortSpeedIntensity = 0;
public static float distortSpeedPosition = 0;
public static float distortSpeedRange = 0;
public static float distortSpeedMoveSpeedX = 0;
public static float distortSpeedMoveSpeedY = 0;
public static float distortTextureMidValue = 0;
private void InitDistortSpeed()
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_DISTORT_SPEED);
}
private void UpdateDistortSpeed()
{
if (_lastIsDistortScreenUVMode!=isDistortScreenUVMode)
{
if (isDistortScreenUVMode)
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_POST_DISTORT_SCREEN_UV);
}
else
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_POST_DISTORT_SCREEN_UV);
}
_lastIsDistortScreenUVMode = isDistortScreenUVMode;
}
Vector4 distortVec = new Vector4(distortSpeedIntensity, distortSpeedPosition, distortSpeedRange,
distortTextureMidValue);
Vector4 distortVec2 = new Vector4(distortSpeedMoveSpeedX, distortSpeedMoveSpeedY, 0, 0);
material.SetVector(_distortVecProperty, distortVec);
material.SetVector(_distortVec2Property, distortVec2);
distortSpeedIntensity = 0;
distortSpeedPosition = 0;
distortSpeedRange = 0;
distortSpeedMoveSpeedX = 0;
distortSpeedMoveSpeedY = 0;
}
private void EndDistortSpeed()
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_DISTORT_SPEED);
}
#endregion
#region
// [ShowInInspector]
// [LabelText("径向模糊开关")]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
public static int radialBlurToggles = 0;
private readonly int _radialBlurVecProperty = Shader.PropertyToID("_RadialBlurVec");
public static float radialBlurIntensity = 0;
public static float radialBlurPos = 0;
public static float radialBlurRange = 0;
public static int radialBlurSampleCount = 4;
public static bool isRadialBlurByDistort = false;
private bool _lastIsRadialBlurByDistort = false;
private bool _lastIsRadialBlur = false;
private void InitRadialBlur()
{
// Debug.Log("InitRB");
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_RADIALBLUR);
}
private void UpdateRadialBlur()
{
if (_lastIsRadialBlurByDistort != isRadialBlurByDistort)
{
if (isRadialBlurByDistort)
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_RADIALBLUR_BY_DISTORT);
}
else
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_RADIALBLUR_BY_DISTORT);
}
_lastIsRadialBlurByDistort = isRadialBlurByDistort;
}
Vector4 radialBlurVec = new Vector4(radialBlurIntensity*0.1f/radialBlurSampleCount, radialBlurPos, radialBlurRange, radialBlurSampleCount);
material.SetVector(_radialBlurVecProperty,radialBlurVec);
radialBlurIntensity = 0;
radialBlurSampleCount = 0;
radialBlurPos = 0;
radialBlurRange = 0;
}
private void EndRadialBlur()
{
// Debug.Log("EndRB");
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_RADIALBLUR);
}
#endregion
#region
#if CINIMACHINE_3_0
public static int cameraShakeToggles = 0;
private bool _lastIsCameraShake = false;
public static float cameraShakeIntensity = 0;
private void UpdateCameraShake()
{
if (_perlin)
{
_perlin.AmplitudeGain = cameraShakeIntensity;
}
cameraShakeIntensity = 0;
// #if UNITY_EDITOR
if (currentVirtualCamera )
{
CinemachineCore.SoloCamera = currentVirtualCamera;
}
// #endif
// Debug.Log(_perlin.m_AmplitudeGain);
}
private void EndCameraShake()
{
if (_perlin)
{
_perlin.AmplitudeGain = 0;
}
CinemachineCore.SoloCamera = null;
}
#endif
#endregion
#region
//肌理图
//注意肌理图就是硬切只有intensity可以做差值。
// [ShowInInspector]
// [LabelText("肌理开关")]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
public static int overlayTextureToggles = 0;
private bool _lastIsOverlayTexture = false;
public static float overlayTextureIntensity = 0;
private readonly int _overlayTextureProperty = Shader.PropertyToID("_TextureOverlay");
private readonly int _overlayTextureStProperty = Shader.PropertyToID("_TextureOverlay_ST");
private readonly int _overlayTextureIntensityProperty = Shader.PropertyToID("_TextureOverlayIntensity");
private void InitOverlayTexture()
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE);
}
private void UpdateOverlayTexture()
{
material.SetFloat(_overlayTextureIntensityProperty, overlayTextureIntensity);
overlayTextureIntensity = 0;
}
private void EndOverlayTexture()
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_OVERLAYTEXTURE);
}
#endregion
#region
// [ShowInInspector]
// [LabelText("黑白闪开关")]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
public static int flashToggles = 0;
private bool _lastIsFlash = false;
public static float flashDesaturateIntensity = 0;
public static float flashInvertIntensity = 0;
public static float flashContrast = 0;
public static Color flashColor = new Color(1, 1, 1, 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 void InitFlash()
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_FLASH);
}
private void UpdateFlash()
{
material.SetFloat(_flashDesaturateProperty, flashDesaturateIntensity);
material.SetFloat(_flashInvertProperty, flashInvertIntensity);
material.SetFloat(_flashContrastProperty, flashContrast);
material.SetColor(_flashColorProperty,flashColor);
flashDesaturateIntensity = 0;
flashInvertIntensity = 0;
flashContrast = 0;
flashColor = Color.white;
}
private void EndFlash()
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_FLASH);
}
#endregion
#region
// [ShowInInspector]
// [LabelText("暗角开关")]
// #if UNITY_EDITOR
// [BinaryInt(8)]
// #endif
public static int vignetteToggles = 0;
private bool _lastIsVignette;
public static float vignetteIntensity = 0f;
public static float vignetteRoundness = 0f;
public static float vignetteSmothness = 0f;
private readonly int _vignetteVecProperty = Shader.PropertyToID("_VignetteVec");
private void InitVignette()
{
flags.SetFlagBits(NBPostProcessFlags.FLAG_BIT_VIGNETTE);
}
private void UpdateVignette()
{
Vector4 vignetteVec = new Vector4(vignetteIntensity, vignetteRoundness, vignetteSmothness, 0);
material.SetVector(_vignetteVecProperty,vignetteVec);
vignetteIntensity = 0;
vignetteRoundness = 0;
vignetteSmothness = 0;
}
private void EndVignette()
{
flags.ClearFlagBits(NBPostProcessFlags.FLAG_BIT_VIGNETTE);
}
#endregion
#if UNITY_EDITOR
void EditorUpdate()
{
if (!Application.isPlaying)
{
LateUpdate();//每帧Update会导致SceneView闪
}
}
public void ReRegistEditorUpdate()
{
EditorApplication.update -= EditorUpdate;
EditorApplication.update += EditorUpdate;
}
#endif
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe30e455c04f33342bb3d1c227855682
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,189 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System.Reflection;
namespace MhRender.RendererFeatures
{
public class ScreenColorRenderPass : ScriptableRenderPass
{
#if UNIVERSAL_RP_13_1_2_OR_NEWER
private RTHandle _screenColorHandle;
private RTHandle _tempRTHandle;
#else
private RenderTargetIdentifier _screenColorHandle;
private static readonly int _screenColorRTID = Shader.PropertyToID("_screenColorRT");
private RenderTargetIdentifier _tempRTHandle = new RenderTargetIdentifier(_tempRTID);
private static readonly int _tempRTID = Shader.PropertyToID("CopyColorRT");
#endif
private ProfilingSampler _profilingSampler;
private readonly Downsampling _downSampling;
readonly Material _material;
private static readonly int CameraTexture = Shader.PropertyToID("_CameraTexture");
private static readonly int SampleOffset = Shader.PropertyToID("_SampleOffset");
public ScreenColorRenderPass(Material material, Downsampling downSampling)
{
_material = material;
_downSampling = downSampling;
}
#if UNIVERSAL_RP_13_1_2_OR_NEWER
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
ConfigureTarget(_screenColorHandle);
}
public void SetUp(RTHandle colorHandle)
{
_profilingSampler ??= new ProfilingSampler("ScreenColorRender");
_screenColorHandle = colorHandle;
RenderTextureDescriptor descriptor = _screenColorHandle.rt.descriptor;
descriptor.autoGenerateMips = true;
descriptor.useMipMap = true;
switch (_downSampling)
{
case Downsampling._2xBilinear:
descriptor.width /= 2;
descriptor.height /= 2;
break;
case Downsampling._4xBilinear:
descriptor.width /= 4;
descriptor.height /= 4;
break;
case Downsampling._4xBox:
descriptor.width /= 4;
descriptor.height /= 4;
break;
}
RenderingUtils.ReAllocateIfNeeded(ref _tempRTHandle, descriptor,name:"CopyColorRT");
}
#else
FieldInfo cameraColorAttachment = typeof(UniversalRenderer).GetField("m_ActiveCameraColorAttachment", BindingFlags.NonPublic|BindingFlags.Instance);
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
var renderer = (UniversalRenderer)renderingData.cameraData.renderer;
// cmd.SetGlobalTexture(_screenColorRTID,_screenColorHandle);
SetUpCopyColorRT(renderer,renderingData.cameraData.cameraTargetDescriptor,cmd);
ConfigureTarget(_tempRTHandle);
ConfigureClear(ClearFlag.Color, Color.clear);
}
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
}
public void SetUp(ScriptableRenderer renderer)
{
RenderTargetHandle value = (RenderTargetHandle)cameraColorAttachment.GetValue(renderer);
_screenColorHandle = value.Identifier();
// _screenColorHandle = colorTarget;
}
public void SetUpCopyColorRT(ScriptableRenderer renderer,RenderTextureDescriptor descriptor ,CommandBuffer cmd)
{
descriptor.autoGenerateMips = true;
descriptor.useMipMap = true;
switch (_downSampling)
{
case Downsampling._2xBilinear:
descriptor.width /= 2;
descriptor.height /= 2;
break;
case Downsampling._4xBilinear:
descriptor.width /= 4;
descriptor.height /= 4;
break;
case Downsampling._4xBox:
descriptor.width /= 4;
descriptor.height /= 4;
break;
}
cmd.GetTemporaryRT( _tempRTID, descriptor,FilterMode.Bilinear);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(_tempRTID);
}
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (!(renderingData.cameraData.cameraType == CameraType.Game || renderingData.cameraData.cameraType == CameraType.SceneView))
return;
if (_material == null)
return;
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, _profilingSampler))
{
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_material.SetTexture(CameraTexture, _screenColorHandle);
switch (_downSampling)
{
case Downsampling._2xBilinear:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
break;
case Downsampling._4xBilinear:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
break;
case Downsampling._4xBox:
_material.SetFloat(SampleOffset,2);
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 1);
break;
default:
Blitter.BlitTexture(cmd, _screenColorHandle, _tempRTHandle, _material, 0);
break;
}
#else
cmd.SetGlobalTexture(_screenColorRTID,_screenColorHandle);
_material.SetTexture(CameraTexture,Shader.GetGlobalTexture(_screenColorRTID));
cmd.SetRenderTarget(_tempRTHandle);
switch (_downSampling)
{
case Downsampling._2xBilinear:
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material, 0,0);
break;
case Downsampling._4xBilinear:
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material, 0,0);
break;
case Downsampling._4xBox:
_material.SetFloat(SampleOffset,2);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material, 0,1);
break;
default:
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material, 0,0);
break;
}
#endif
cmd.SetGlobalTexture("_ScreenColorCopy1", _tempRTHandle);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
public void Dispose()
{
#if UNIVERSAL_RP_13_1_2_OR_NEWER
_tempRTHandle?.Release();
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff8358dc3f3531d4c92a43a49d07f36c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
{
"name": "com.xuanxuan.nb.postprocessing",
"rootNamespace": "",
"references": [
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
"GUID:15fc0a57446b3144c949da3e2b9737a9",
"GUID:4307f53044263cf4b835bd812fc161a4",
"GUID:8f9e4d586616f13449cfeb86c5f704c2"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.cinemachine",
"expression": "3.0",
"define": "CINIMACHINE_3_0"
},
{
"name": "com.unity.render-pipelines.universal",
"expression": "13.1.2",
"define": "UNIVERSAL_RP_13_1_2_OR_NEWER"
}
],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a1f23b61b189bd949adfd0f7a353734f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b96c6f78e9ea0924b92677f2c4812124
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,238 @@
Shader "XuanXuan/ColorBlit"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
#pragma multi_compile _ BLIT_SINGLE_SLICE
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
ENDHLSL
SubShader
{
Tags
{
"RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"
}
ZWrite Off Cull Off
Pass
{
Name "ColorBlitPass0"
HLSLPROGRAM
#pragma vertex vert
// #pragma vertex vert
// #pragma fragment FragNearest
#pragma fragment frag
#pragma enable_d3d11_debug_symbols
Texture2D _CameraTexture;
// Texture2D _CameraTexture;
//
// struct MyAttributes
// {
// float4 positionOS : POSITION;
// float4 texCoord : TEXCOORD0;
// };
//
// Varyings vert(MyAttributes IN)
// {
// Varyings OUT = (Varyings)0;
// OUT.positionCS = float4(IN.positionOS.xyz,1);
// half4 clipVertex = OUT.positionCS/OUT.positionCS.w;
// OUT.texcoord = ComputeScreenPos(clipVertex);
// return OUT;
// }
Varyings vert(Attributes input)//避开官方_BlitScaleBias为0的错误。
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
#if SHADER_API_GLES
float4 pos = input.positionOS;
float2 uv = input.uv;
#else
float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
#endif
output.positionCS = pos;
// output.texcoord = uv * _BlitScaleBias.xy + _BlitScaleBias.zw;
output.texcoord = uv;
return output;
}
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float4 color = SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_LinearRepeat, input.texcoord);
return color;
}
ENDHLSL
}
Pass
{
Name "BoxDownsample"
ZWrite Off
Cull Off
HLSLPROGRAM
// #pragma vertex Vert
#pragma vertex vert
#pragma fragment FragBoxDownsample
#pragma enable_d3d11_debug_symbols
Texture2D _CameraTexture;
SAMPLER(sampler_CameraTexture);
#if UNITY_VERSION < 202320
float4 _BlitTexture_TexelSize;
#endif
Varyings vert(Attributes input)//避开官方_BlitScaleBias为0的错误。
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
#if SHADER_API_GLES
float4 pos = input.positionOS;
float2 uv = input.uv;
#else
float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
#endif
output.positionCS = pos;
// output.texcoord = uv * _BlitScaleBias.xy + _BlitScaleBias.zw;
output.texcoord = uv;
return output;
}
float _SampleOffset;
half4 FragBoxDownsample(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
float4 d = _BlitTexture_TexelSize.xyxy * float4(-_SampleOffset, -_SampleOffset, _SampleOffset,
_SampleOffset);
half4 s;
s = SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.xy);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.zy);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.xw);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.zw);
return s * 0.25h;
}
ENDHLSL
}
Pass
{
Name "ColorBlitPass_URP_13_1_2_OR_OLDER"
HLSLPROGRAM
#pragma vertex vert
// #pragma vertex vert
// #pragma fragment FragNearest
#pragma fragment frag
#pragma enable_d3d11_debug_symbols
Texture2D _CameraTexture;
// Texture2D _CameraTexture;
struct MyAttributes
{
float4 positionOS : POSITION;
float4 texCoord : TEXCOORD0;
};
Varyings vert(MyAttributes IN)
{
Varyings OUT = (Varyings)0;
OUT.positionCS = float4(IN.positionOS.xyz,1);
half4 clipVertex = OUT.positionCS/OUT.positionCS.w;
OUT.texcoord = ComputeScreenPos(clipVertex);
return OUT;
}
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float4 color = SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_LinearRepeat, input.texcoord);
return color;
}
ENDHLSL
}
Pass
{
Name "BoxDownsample_URP_13_1_2_OR_OLDER"
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment FragBoxDownsample
#pragma enable_d3d11_debug_symbols
Texture2D _CameraTexture;
SAMPLER(sampler_CameraTexture);
#if UNITY_VERSION < 202320
float4 _BlitTexture_TexelSize;
#endif
float _SampleOffset;
struct MyAttributes
{
float4 positionOS : POSITION;
float4 texCoord : TEXCOORD0;
};
Varyings vert(MyAttributes IN)
{
Varyings OUT = (Varyings)0;
OUT.positionCS = float4(IN.positionOS.xyz,1);
half4 clipVertex = OUT.positionCS/OUT.positionCS.w;
OUT.texcoord = ComputeScreenPos(clipVertex);
return OUT;
}
half4 FragBoxDownsample(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
float4 d = _BlitTexture_TexelSize.xyxy * float4(-_SampleOffset, -_SampleOffset, _SampleOffset,
_SampleOffset);
half4 s;
s = SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.xy);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.zy);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.xw);
s += SAMPLE_TEXTURE2D_X(_CameraTexture, sampler_CameraTexture, uv + d.zw);
return s * 0.25h;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3e92fe624a4f13d4eadc7753e236006a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
Shader "XuanXuan/ColorBufferBlit"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
#pragma multi_compile _ BLIT_SINGLE_SLICE
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
ENDHLSL
SubShader
{
Tags
{
"RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"
}
ZWrite Off Cull Off
Pass
{
Name "ColorBlitPass0"
HLSLPROGRAM
// #pragma vertex Vert
#pragma vertex vert
// #pragma fragment FragNearest
#pragma fragment frag
#pragma enable_d3d11_debug_symbols
Texture2D _CameraColorTexture;
SAMPLER(sampler_CameraColorTexture);
struct MyAttributes
{
float4 positionOS : POSITION;
float4 texCoord : TEXCOORD0;
};
Varyings vert(MyAttributes IN)
{
Varyings OUT = (Varyings)0;
OUT.positionCS = float4(IN.positionOS.xyz,1);
half4 clipVertex = OUT.positionCS/OUT.positionCS.w;
OUT.texcoord = ComputeScreenPos(clipVertex);
return OUT;
}
half4 frag (Varyings input) : SV_Target
{
// UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float4 color = SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_LinearRepeat, input.texcoord);
return color;
}
ENDHLSL
}
Pass
{
Name "BoxDownsample"
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBoxDownsample
#pragma enable_d3d11_debug_symbols
// Texture2D _CameraTexture;
// SAMPLER(sampler_CameraTexture);
Texture2D _CameraColorTexture;
SAMPLER(sampler_CameraColorTexture);
#if UNITY_VERSION < 202320
float4 _BlitTexture_TexelSize;
#endif
float _SampleOffset;
half4 FragBoxDownsample(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
float4 d = _BlitTexture_TexelSize.xyxy * float4(-_SampleOffset, -_SampleOffset, _SampleOffset,
_SampleOffset);
half4 s;
s = SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, uv + d.xy);
s += SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, uv + d.zy);
s += SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, uv + d.xw);
s += SAMPLE_TEXTURE2D_X(_CameraColorTexture, sampler_CameraColorTexture, uv + d.zw);
return s * 0.25h;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3150dab783854cd6b791d5db3be4a966
timeCreated: 1747582276

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1,156 @@
fileFormatVersion: 2
guid: 7f808d0c8608b954d8f20cb4132c3049
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: iOS
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
Shader "XuanXuan/Disturbance"
{
Properties
{
[MhGroup(Main)]_mainTex("Main", float) = 0
[MhTexture(Main)] _MaskMap("Mask Map", 2D) = "white" {}
[MhTexture(Main,_Strength,on)]_NoiseMap("Noise Map", 2D) = "white"{}
[HideInInspector]_Strength("Strength", Range(-0.2,0.2)) =0.1
[MhToggleKeyword(Main,_PARTICLE_CUSTOMDATA_ON)]_ParticleCustomDataOn("Particle customData Strength", float) = 0
[HideInInspector]_SurfaceType("surfaceType",float)=1
[HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
}
// The SubShader block containing the Shader code.
SubShader
{
// SubShader Tags define when and under which conditions a SubShader block or
// a pass is executed.
Tags
{
"RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "Queue" = "Transparent" "IgnoreProjector" = "True"
}
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
//ZTest Always
Cull Off
HLSLPROGRAM
//gpuInstancing on
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma target 3.5 DOTS_INSTANCING_ON
#pragma shader_feature_local_fragment _PARTICLE_CUSTOMDATA_ON
#pragma enable_d3d11_debug_symbols
// This line defines the name of the vertex shader.
#pragma vertex vert
// This line defines the name of the fragment shader.
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
// This example uses the Attributes structure as an input structure in
// the vertex shader.
struct Attributes
{
float4 positionOS : POSITION;
float4 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
// The positions in this struct must have the SV_POSITION semantic.
float4 positionHCS : SV_POSITION;
float4 uv :TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Texture2D _NoiseMap;
SAMPLER(sampler_NoiseMap);
Texture2D _MaskMap;
SAMPLER(sampler_MaskMap);
float _Strength;
CBUFFER_START(UnityPerMaterial)
float4 _NoiseMap_ST;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings OUT;
// Declaring the output object (OUT) with the Varyings struct.
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = IN.uv;
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
half2 screenSpaceUV = IN.positionHCS.xy / _ScaledScreenParams.xy;
const half2 noiseUV = screenSpaceUV * _NoiseMap_ST.xy + _NoiseMap_ST.zw;
half noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, noiseUV).r * 2 - 1;
half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, IN.uv.xy).r;
noise = lerp(0, noise, mask);
//noise = (noise * _Strength * 5) * 0.5 + 0.5;
noise = (noise * _Strength) * 1.25 + 0.5;
return half4(noise.xxx, 1.0);
}
ENDHLSL
}
}
customEditor "ShaderEditor.MhBaseShaderGUI"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1b530af6d4d97eb4c8f3725d4cd3e9b8
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
Shader "XuanXuan/FullScreenDisturbance"
{
Properties
{
_Strength("Strength", Range(-0.2,0.2)) =0
_BaseMap("Base Map", 2D) = "white"
//_Mask("Mask", 2D) = "white"
}
// The SubShader block containing the Shader code.
SubShader
{
// SubShader Tags define when and under which conditions a SubShader block or
// a pass is executed.
Tags
{
"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"
}
Pass
{
stencil
{
Ref 1
Comp equal
Pass keep
}
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// This line defines the name of the vertex shader.
#pragma vertex vert
// This line defines the name of the fragment shader.
#pragma fragment frag
Texture2D _BlitTexture;
SAMPLER(sampler_BlitTexture);
Texture2D _BaseMap;
SAMPLER(sampler_BaseMap);
Texture2D _Mask;
SAMPLER(simpler_Mask);
float _Strength;
struct Attributes
{
#if UNITY_ANY_INSTANCING_ENABLED
uint instanceID : INSTANCEID_SEMANTIC;
#endif
uint vertexID : VERTEXID_SEMANTIC;
};
struct Varyings
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
#if UNITY_ANY_INSTANCING_ENABLED
uint instanceID : CUSTOM_INSTANCE_ID;
#endif
};
Varyings vert(Attributes input)
{
Varyings output;
output.position = GetFullScreenTriangleVertexPosition(input.vertexID, UNITY_NEAR_CLIP_VALUE);
output.uv = output.position.xy * 0.5 + 0.5;
return output;
}
float4 frag(Varyings packedInput):SV_TARGET
{
float2 baseUV = packedInput.position / _ScreenParams.xy;
float3 noise = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, baseUV);
noise=lerp(0,noise,noise.b);
baseUV += noise.xy * _Strength;
return SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, baseUV);
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 126dad763ce350945945655d5c062248
ShaderImporter:
externalObjects: {}
defaultTextures:
- _BaseMap: {instanceID: 0}
- _Mask: {instanceID: 0}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e73bff430617bbc44ae5b87fb0fa9abf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
#ifndef POST_PROCESSING_FLAGS
#define POST_PROCESSING_FLAGS
#if defined(CUSTOM_POSTPROCESS)
uint _NBPostProcessFlags;
#define FLAG_BIT_NB_POSTPROCESS_ON (1 << 0)
#define FLAG_BIT_DISTORT_SPEED (1 << 1)
#define FLAG_BIT_OVERLAYTEXTURE (1 << 2)
#define FLAG_BIT_FLASH (1 << 3)
#define FLAG_BIT_CHORATICABERRAT (1 << 4)
#define FLAG_BIT_RADIALBLUR (1 << 5)
#define FLAG_BIT_VIGNETTE (1 << 6)
#define FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD (1 << 7)
#define FLAG_BIT_OVERLAYTEXTURE_MASKMAP (1 << 8)
#define FLAG_BIT_POST_DISTORT_SCREEN_UV (1 << 9)
#define FLAG_BIT_RADIALBLUR_BY_DISTORT (1 << 10)
#define FLAG_BIT_CHORATICABERRAT_BY_DISTORT (1 << 11)
bool CheckLocalFlags(uint bits)
{
return (_NBPostProcessFlags&bits) != 0;
}
#endif
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8d59b331ef0707e49a98c91244bd0c1a
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,377 @@
Shader "XuanXuan/Postprocess/NBPostProcessUber"
{
Properties
{
// [MainTexture] _BaseMap("Base Map", 2D) = "white"
_SpeedDistortMap("速度径向扭曲贴图", 2D) = "white"
_SpeedDistortVec("速度径向 x强度y位置z范围w速度",Vector) = (0,0,0,0)
_SpeedDistortVec2("速度径向 x:uvX速度 y:uvY速度",Vector) = (0,0,0,0)
_TextureOverlay("肌理附加图",2D) = "white"
_TextureOverlayIntensity("肌理附加强度",Float) = 0
_TextureOverlayAnim("机理图动画",Vector) = (0,0,0,0)
_TextureOverlayMask("肌理图蒙板",2D) = "white"
_InvertIntensity("反向强度",Float) = 0
_DeSaturateIntensity("饱和度强度",Float) = 0
_Contrast("对比度",Float) = 1
_FlashColor("闪颜色", Vector) = (1, 1, 1, 1)
[HideInInspector] _NBPostProcessFlags("_NBPostProcessFlags", Integer) = 0
_ChromaticAberrationVector("色散矢量",Vector) = (1,0,0,0)
_CustomScreenCenter("自定义屏幕中心",Vector) = (0.5,0.5,0,0)
_RadialBlurVec("径向模糊矢量 x强度",Vector) = (1,0,0,0)
_VignetteVec("暗角矢量 x强度,y圆度,z光滑度",Vector) = (1,0,0,0)
//不知道为什么这里写成Color老是出错。
_VignetteColor("暗角颜色",Vector) = (0.0,0.0,0.0,1.0)
}
// The SubShader block containing the Shader code.
SubShader
{
// SubShader Tags define when and under which conditions a SubShader block or
// a pass is executed.
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
// This line defines the name of the vertex shader.
#pragma vertex vert
// This line defines the name of the fragment shader.
#pragma fragment frag
#define CUSTOM_POSTPROCESS
// #define _POLARCOORDINATES
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "HLSL/PostProcessingFlags.hlsl"
#include "Packages/com.xuanxuan.render.utility/Shader/HLSL/XuanXuan_Utility.hlsl"
// This example uses the Attributes structure as an input structure in
// the vertex shader.
struct Attributes
{
float4 positionOS : POSITION;
};
struct Varyings
{
// The positions in this struct must have the SV_POSITION semantic.
float4 positionHCS : SV_POSITION;
half2 uv :TEXCOORD0;
};
TEXTURE2D(_ScreenColorCopy1);
SAMPLER(_linear_clamp);
SAMPLER(sampler_ScreenColorCopy1);
TEXTURE2D(_DisturbanceMaskTex);
SAMPLER(sampler_DisturbanceMaskTex);
Texture2D _SpeedDistortMap;
SAMPLER(sampler_SpeedDistortMap);
TEXTURE2D(_TextureOverlay);
SAMPLER(sampler_TextureOverlay);
TEXTURE2D(_TextureOverlayMask);
SAMPLER(sampler_TextureOverlayMask);
#if UNITY_VERSION < 202210
SAMPLER(sampler_LinearClamp);
#endif
CBUFFER_START(UnityPerMaterial)
float4 _SpeedDistortMap_ST;
half4 _SpeedDistortVec;
float4 _SpeedDistortVec2;
half4 _TextureOverlay_ST;
half _TextureOverlayIntensity;
half4 _TextureOverlayMask_ST;
half4 _TextureOverlayAnim;
half _InvertIntensity;
half _DeSaturateIntensity;
half _Contrast;
half3 _FlashColor;
half4 _ChromaticAberrationVec;
half4 _CustomScreenCenter;
half4 _RadialBlurVec;
half4 _VignetteVec;
half4 _VignetteColor;
CBUFFER_END
half4 SAMPLE_TEXTURE2D_CHORATICABERRAT(half2 screenUV,half2 distortUV,half2 blurVec,half distToCenter)
{
if(CheckLocalFlags(FLAG_BIT_CHORATICABERRAT_BY_DISTORT))
{
blurVec = blurVec*0.25*_ChromaticAberrationVec.x;
}
else
{
half intensity = 1;
half range = _ChromaticAberrationVec.z*0.5f;
intensity = NB_Remap(distToCenter,_ChromaticAberrationVec.y-range,_ChromaticAberrationVec.y+range,0,1);
blurVec = blurVec*0.25*_ChromaticAberrationVec.x*intensity;
}
half r = SAMPLE_TEXTURE2D_X(_ScreenColorCopy1, sampler_LinearClamp, screenUV + distortUV ).x;
half g = SAMPLE_TEXTURE2D_X(_ScreenColorCopy1, sampler_LinearClamp, blurVec + screenUV + distortUV ).y;
half b = SAMPLE_TEXTURE2D_X(_ScreenColorCopy1, sampler_LinearClamp, blurVec * 2.0 + screenUV + distortUV).z;
half a = dot(blurVec,blurVec)*100000;
return half4(r,g,b,a);
}
Varyings vert(Attributes IN)
{
// Declaring the output object (OUT) with the Varyings struct.
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
half4 clipVertex = OUT.positionHCS/OUT.positionHCS.w;
OUT.uv = ComputeScreenPos(clipVertex);
// Returning the output.
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
half2 screenUV = IN.uv;
half2 distortUV = 0;
half2 distortUVWithoutIntensity=0;
half4 color = 0;
half2 polarCoordinates = 0;
//half disturbanceMask = (SAMPLE_TEXTURE2D(_DisturbanceMaskTex, _linear_clamp, screenUV)) * 2 - 1 + 0.00392; //8位0.5校准
//disturbanceMask *= 0.4;
//half2 disturbanceMask = (SAMPLE_TEXTURE2D(_DisturbanceMaskTex, _linear_clamp, screenUV).xy) * 0.8 - 0.398432; //上面两行合并
half2 disturbanceMask = (SAMPLE_TEXTURE2D(_DisturbanceMaskTex, _linear_clamp, screenUV).xy) * 0.8 - 0.4; //上面两行合并
color.a = SimpleSmoothstep(0,0.01,abs(disturbanceMask.x + disturbanceMask.y));
screenUV += disturbanceMask;
UNITY_BRANCH
if (!CheckLocalFlags(FLAG_BIT_NB_POSTPROCESS_ON))
{
color.rgb = SAMPLE_TEXTURE2D(_ScreenColorCopy1, _linear_clamp, screenUV).rgb;
}
UNITY_BRANCH
if((CheckLocalFlags(FLAG_BIT_DISTORT_SPEED)& (!CheckLocalFlags(FLAG_BIT_POST_DISTORT_SCREEN_UV)))|CheckLocalFlags(FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD))
{
polarCoordinates= PolarCoordinates(screenUV,_CustomScreenCenter.xy);
}
UNITY_BRANCH
if(CheckLocalFlags(FLAG_BIT_DISTORT_SPEED))
{
_SpeedDistortMap_ST.zw += _SpeedDistortVec2.xy * _Time.y;
// return half4(polarCoordinates,0,1);
half2 distortSpeedUV;
if(CheckLocalFlags(FLAG_BIT_POST_DISTORT_SCREEN_UV))
{
distortSpeedUV = screenUV* _SpeedDistortMap_ST.xy+_SpeedDistortMap_ST.zw;
half2 noise = SAMPLE_TEXTURE2D(_SpeedDistortMap,sampler_SpeedDistortMap,distortSpeedUV);
noise = noise * 2-1+_SpeedDistortVec.w*0.1;
half distortStrength = _SpeedDistortVec.x * 0.2;
distortUVWithoutIntensity = noise;
distortUV = noise * distortStrength;
}
else
{
distortSpeedUV = polarCoordinates * _SpeedDistortMap_ST.xy + _SpeedDistortMap_ST.zw;
half noise = SAMPLE_TEXTURE2D(_SpeedDistortMap,sampler_SpeedDistortMap,distortSpeedUV);
noise *= SimpleSmoothstep(_SpeedDistortVec.y,_SpeedDistortVec.y+_SpeedDistortVec.z,(distortSpeedUV.y - _SpeedDistortMap_ST.w)/_SpeedDistortMap_ST.y);
half distortStrength = - _SpeedDistortVec.x * 0.2;
distortUV = normalize(screenUV-_CustomScreenCenter.xy)*noise;
distortUVWithoutIntensity = distortUV;
distortUV *= distortStrength;
}
color.a += dot(distortUV,distortUV)*100000;
}
else
{
distortUVWithoutIntensity = disturbanceMask;
}
// return half4(((dot(distortUV,distortUV)*100000)).rrr,1);
UNITY_BRANCH
if(CheckLocalFlags(FLAG_BIT_CHORATICABERRAT) || CheckLocalFlags(FLAG_BIT_RADIALBLUR))
{
float2 blurVec = 0;
half dist = 0;
if(!CheckLocalFlags(FLAG_BIT_CHORATICABERRAT_BY_DISTORT)|!CheckLocalFlags(FLAG_BIT_RADIALBLUR_BY_DISTORT))
{
blurVec = _CustomScreenCenter.xy - screenUV;
dist = dot(blurVec,blurVec)*4;
}
float2 choraticaBerratBlurVec;
if(CheckLocalFlags(FLAG_BIT_CHORATICABERRAT))
{
if(CheckLocalFlags(FLAG_BIT_CHORATICABERRAT_BY_DISTORT))
{
choraticaBerratBlurVec = distortUVWithoutIntensity;
}
else
{
choraticaBerratBlurVec = blurVec;
}
}
if(CheckLocalFlags(FLAG_BIT_RADIALBLUR))
{
float2 radialblurVec;
if(CheckLocalFlags(FLAG_BIT_RADIALBLUR_BY_DISTORT))
{
radialblurVec = distortUVWithoutIntensity*_RadialBlurVec.x;
}
else
{
_RadialBlurVec.z *= 0.5;
half rangeIntensity = NB_Remap(dist,_RadialBlurVec.y-_RadialBlurVec.z,_RadialBlurVec.y+_RadialBlurVec.z,0,1);
rangeIntensity = saturate(rangeIntensity);
radialblurVec = blurVec*_RadialBlurVec.x*rangeIntensity;
}
color.a += dot(blurVec,blurVec)*100;
half3 acumulateColor = half3(0, 0, 0);
int iteration = _RadialBlurVec.w;
[unroll(12)]
for(int i = 0;i<iteration;i++)
{
if(CheckLocalFlags(FLAG_BIT_CHORATICABERRAT))
{
//sample *3
acumulateColor += SAMPLE_TEXTURE2D_CHORATICABERRAT(screenUV,distortUV,choraticaBerratBlurVec,dist);
}
else
{
acumulateColor += SAMPLE_TEXTURE2D(_ScreenColorCopy1,_linear_clamp,screenUV + distortUV);
}
screenUV += radialblurVec;
}
color.rgb = acumulateColor / iteration;
}
else
{
half4 choraticaBerratColor = SAMPLE_TEXTURE2D_CHORATICABERRAT(screenUV,distortUV,choraticaBerratBlurVec,dist);
color.rgb = choraticaBerratColor.rgb;
color.a += choraticaBerratColor.a;
}
}
else
{
color.rgb = SAMPLE_TEXTURE2D(_ScreenColorCopy1,_linear_clamp,screenUV + distortUV);
}
// return half4(color.aaa,1);
UNITY_BRANCH
if(CheckLocalFlags(FLAG_BIT_OVERLAYTEXTURE))
{
half2 overlayTexUV;
if(CheckLocalFlags(FLAG_BIT_OVERLAYTEXTURE_POLLARCOORD))
{
overlayTexUV = polarCoordinates;
}
else
{
overlayTexUV = screenUV;
}
float2 overlayMainTexUV = TRANSFORM_TEX(overlayTexUV,_TextureOverlay);
overlayMainTexUV = UVOffsetAnimaiton(overlayMainTexUV,_TextureOverlayAnim.xy,_Time.y);
half4 overlayTexSample = SAMPLE_TEXTURE2D(_TextureOverlay,sampler_TextureOverlay,overlayMainTexUV);
half overlayTexMask = 1;
if (CheckLocalFlags(FLAG_BIT_OVERLAYTEXTURE_MASKMAP))
{
float2 overlayTexMaskUV = TRANSFORM_TEX(overlayTexUV,_TextureOverlayMask);
overlayTexMask = SAMPLE_TEXTURE2D(_TextureOverlayMask,sampler_TextureOverlayMask,overlayTexMaskUV);
}
color.rgb *= lerp(1,overlayTexSample.rgb,overlayTexSample.a*_TextureOverlayIntensity*overlayTexMask);
// return half4( lerp(overlayTexSample.rgb,1,overlayTexSample.a*_TextureOverlayIntensity),1);
color.a += _TextureOverlayIntensity;
}
UNITY_BRANCH
if(CheckLocalFlags(FLAG_BIT_FLASH))
{
color.xyz = RgbToHsv(color.rgb);
half3 colorHSV = color.xyz;
color.y *= _DeSaturateIntensity;
color.rgb = HsvToRgb(color.xyz);
//因为颜色空间的特殊原因,这里的转换运算可能会造成性能热点,后续考虑优化。
half3 invertColor = SRGBToLinear(1- LinearToSRGB(color.xyz));
color.rgb = lerp(color.rgb,invertColor,_InvertIntensity);
half3 endColor = lerp(color,_FlashColor,luminance(color.rgb));
color.rgb = lerp(color.rgb,endColor,_InvertIntensity);
color.rgb = lerp(half3(0.5,0.5,0.5),color.rgb,_Contrast);
color.a = 1;
}
UNITY_BRANCH
if(CheckLocalFlags(FLAG_BIT_VIGNETTE))
{
_VignetteVec.x *= _VignetteColor.a;
half2 screenVec = (_CustomScreenCenter.xy - screenUV)*_VignetteVec.x;
screenVec.x *= _VignetteVec.y;
half2 dist = dot(screenVec,screenVec);
dist = saturate(dist);
half factor = pow(1-dist,_VignetteVec.z) ;
color.rgb *= lerp(_VignetteColor,(1.0).xxx,factor);
// color.rgb *= saturate(factor);
color.a =1;
}
// return half4(_TextureOverlayIntensity.rrr,1);
// float finalIntensity = (_SpeedDistortVec.x+ _TextureOverlayIntensity +_InvertIntensity +(1- _DeSaturateIntensity)+_Contrast)*2;
// finalIntensity = saturate(finalIntensity);
// return half4(saturate(color.a).rrr,1);
return half4(color.rgb,saturate(color.a));
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5fd213d22763447c4aa106605e06184e
ShaderImporter:
externalObjects: {}
defaultTextures:
- _SpeedDistortMap: {fileID: 2800000, guid: 7f808d0c8608b954d8f20cb4132c3049, type: 3}
- _TextureOverlay: {instanceID: 0}
- _TextureOverlayMask: {instanceID: 0}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
{
"name": "com.xuanxuan.nb.postprocessing",
"version": "0.0.1",
"displayName": "NBPostProcessing",
"description": "NB\u540e\u5904\u7406",
"unity": "2019.1"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e9e4b9cfaabda4f4296d2f1a28bc3501
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: