一些特效
This commit is contained in:
100
Packages/NBPostProcessing/3DPostionShake.asset
Normal file
100
Packages/NBPostProcessing/3DPostionShake.asset
Normal 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
|
||||
8
Packages/NBPostProcessing/3DPostionShake.asset.meta
Normal file
8
Packages/NBPostProcessing/3DPostionShake.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3a1931bdb3088e4ebf4755df90c90e9
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBPostProcessing/Editor.meta
Normal file
8
Packages/NBPostProcessing/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b3052f0c1288a045a0be3d63f109623
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
356
Packages/NBPostProcessing/Editor/PostProcessingControllerGUI.cs
Normal file
356
Packages/NBPostProcessing/Editor/PostProcessingControllerGUI.cs
Normal 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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed187d8c0d9f5b14aa156ff45e7405c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Packages/NBPostProcessing/Editor/PostProcessingManagerGUI.cs
Normal file
70
Packages/NBPostProcessing/Editor/PostProcessingManagerGUI.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bf2aa095c38c4972ba5c008ae40a3f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12fb0c569d0951c40a3f4013cd8758b5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2
Packages/NBPostProcessing/README.md
Normal file
2
Packages/NBPostProcessing/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# NBPostProcessing
|
||||
NBPostProcessing
|
||||
7
Packages/NBPostProcessing/README.md.meta
Normal file
7
Packages/NBPostProcessing/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11345d4fc578e4c15a13b9e5a61107df
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBPostProcessing/Runtime.meta
Normal file
8
Packages/NBPostProcessing/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f0e3118134388949838b53cc48e9c89
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
483
Packages/NBPostProcessing/Runtime/NBPostProcess.cs
Normal file
483
Packages/NBPostProcessing/Runtime/NBPostProcess.cs
Normal 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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/NBPostProcessing/Runtime/NBPostProcess.cs.meta
Normal file
11
Packages/NBPostProcessing/Runtime/NBPostProcess.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5a1f9350d8fc2c46a372955ef0e73b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Packages/NBPostProcessing/Runtime/NBPostprocessFlags.cs
Normal file
36
Packages/NBPostProcessing/Runtime/NBPostprocessFlags.cs
Normal 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
|
||||
|
||||
|
||||
}
|
||||
11
Packages/NBPostProcessing/Runtime/NBPostprocessFlags.cs.meta
Normal file
11
Packages/NBPostProcessing/Runtime/NBPostprocessFlags.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be6a95b97f4bc3846bdada66138f6da1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
602
Packages/NBPostProcessing/Runtime/PostProcessingController.cs
Normal file
602
Packages/NBPostProcessing/Runtime/PostProcessingController.cs
Normal 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
|
||||
}
|
||||
@@ -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:
|
||||
720
Packages/NBPostProcessing/Runtime/PostProcessingManager.cs
Normal file
720
Packages/NBPostProcessing/Runtime/PostProcessingManager.cs
Normal 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
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe30e455c04f33342bb3d1c227855682
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
189
Packages/NBPostProcessing/Runtime/ScreenColorRenderPass.cs
Normal file
189
Packages/NBPostProcessing/Runtime/ScreenColorRenderPass.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff8358dc3f3531d4c92a43a49d07f36c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1f23b61b189bd949adfd0f7a353734f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBPostProcessing/Shader.meta
Normal file
8
Packages/NBPostProcessing/Shader.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b96c6f78e9ea0924b92677f2c4812124
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
238
Packages/NBPostProcessing/Shader/ColorBlit.shader
Normal file
238
Packages/NBPostProcessing/Shader/ColorBlit.shader
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Packages/NBPostProcessing/Shader/ColorBlit.shader.meta
Normal file
9
Packages/NBPostProcessing/Shader/ColorBlit.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e92fe624a4f13d4eadc7753e236006a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Packages/NBPostProcessing/Shader/ColorBufferBlit.shader
Normal file
105
Packages/NBPostProcessing/Shader/ColorBufferBlit.shader
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3150dab783854cd6b791d5db3be4a966
|
||||
timeCreated: 1747582276
|
||||
BIN
Packages/NBPostProcessing/Shader/DistortSpeedNoise.png
Normal file
BIN
Packages/NBPostProcessing/Shader/DistortSpeedNoise.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
156
Packages/NBPostProcessing/Shader/DistortSpeedNoise.png.meta
Normal file
156
Packages/NBPostProcessing/Shader/DistortSpeedNoise.png.meta
Normal 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:
|
||||
113
Packages/NBPostProcessing/Shader/Disturbance.shader
Normal file
113
Packages/NBPostProcessing/Shader/Disturbance.shader
Normal 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"
|
||||
}
|
||||
9
Packages/NBPostProcessing/Shader/Disturbance.shader.meta
Normal file
9
Packages/NBPostProcessing/Shader/Disturbance.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b530af6d4d97eb4c8f3725d4cd3e9b8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 126dad763ce350945945655d5c062248
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures:
|
||||
- _BaseMap: {instanceID: 0}
|
||||
- _Mask: {instanceID: 0}
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBPostProcessing/Shader/HLSL.meta
Normal file
8
Packages/NBPostProcessing/Shader/HLSL.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e73bff430617bbc44ae5b87fb0fa9abf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d59b331ef0707e49a98c91244bd0c1a
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
377
Packages/NBPostProcessing/Shader/NBPostProcessUber.shader
Normal file
377
Packages/NBPostProcessing/Shader/NBPostProcessUber.shader
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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:
|
||||
7
Packages/NBPostProcessing/package.json
Normal file
7
Packages/NBPostProcessing/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.postprocessing",
|
||||
"version": "0.0.1",
|
||||
"displayName": "NBPostProcessing",
|
||||
"description": "NB\u540e\u5904\u7406",
|
||||
"unity": "2019.1"
|
||||
}
|
||||
7
Packages/NBPostProcessing/package.json.meta
Normal file
7
Packages/NBPostProcessing/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9e4b9cfaabda4f4296d2f1a28bc3501
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1
Packages/NBShaders/.gitignore
vendored
Normal file
1
Packages/NBShaders/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.idea
|
||||
8
Packages/NBShaders/Editor.meta
Normal file
8
Packages/NBShaders/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af9e4a2cbc9cee94485138c3bc876c62
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2205
Packages/NBShaders/Editor/ParticleBaseGUI.cs
Normal file
2205
Packages/NBShaders/Editor/ParticleBaseGUI.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Packages/NBShaders/Editor/ParticleBaseGUI.cs.meta
Normal file
11
Packages/NBShaders/Editor/ParticleBaseGUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01d5272ee28d1384d9f555c579592a6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.shaders.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:0e3b0e6ce60c7a34094f8f9822c0b7f2",
|
||||
"GUID:8495541fcd41b0c40b5b6e6e7a7639d1",
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e03fab8dc9c256468083d9bc82a73c3
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Packages/NBShaders/LICENSE
Normal file
21
Packages/NBShaders/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 xuanshushu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
7
Packages/NBShaders/LICENSE.meta
Normal file
7
Packages/NBShaders/LICENSE.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b8d5ffb7acb5d647b3ad813acc372da
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2
Packages/NBShaders/README.md
Normal file
2
Packages/NBShaders/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# NBShaders
|
||||
This is a powerful and versatile Unity VFX shader.
|
||||
7
Packages/NBShaders/README.md.meta
Normal file
7
Packages/NBShaders/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: add0a5ef687222e46a7319724739db61
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBShaders/Runtime.meta
Normal file
8
Packages/NBShaders/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4684518ac782305428f8c0434c85d1c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Packages/NBShaders/Runtime/NBShaderSpriteHelper.cs
Normal file
90
Packages/NBShaders/Runtime/NBShaderSpriteHelper.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
// using Sirenix.OdinInspector;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class NBShaderSpriteHelper : MonoBehaviour
|
||||
{
|
||||
public Sprite sprite;
|
||||
// [ReadOnly]
|
||||
public SpriteRenderer spRenderer;
|
||||
// [ReadOnly]
|
||||
public Image image;
|
||||
|
||||
[InspectorButton("初始化","Init")]
|
||||
public bool ButtomInspector;
|
||||
|
||||
private Material mat;
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
if (TryGetComponent<SpriteRenderer>(out SpriteRenderer spr))
|
||||
{
|
||||
spRenderer = spr;
|
||||
sprite = spr.sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TryGetComponent<Image>(out Image im))
|
||||
{
|
||||
image = im;
|
||||
sprite = im.sprite;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (sprite)
|
||||
{
|
||||
Texture texture = sprite.texture;
|
||||
Rect rect = sprite.textureRect;
|
||||
// sharedMaterial.SetVector("_BaseMapReverseST",CalScaleOffset(spRenderer.sprite.textureRect,spRenderer.sprite.texture));
|
||||
|
||||
if (spRenderer)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
mat = spRenderer.material;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = spRenderer.sharedMaterial;
|
||||
}
|
||||
}
|
||||
else if(image)
|
||||
{
|
||||
mat = image.material;
|
||||
}
|
||||
|
||||
if (mat && mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
|
||||
{
|
||||
mat.SetVector("_MainTex_Reverse_ST",CalScaleOffset(rect,texture));
|
||||
Debug.Log(mat.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Vector4 CalScaleOffset(Rect textureRect,Texture texture)
|
||||
{
|
||||
//这是一个反向的scale offset。
|
||||
//算法:如果原scale offset。转换后会是 scaleAfter= 1 / scale , offsetAfter = - offset/scale;
|
||||
Vector2 scaleAfter = new Vector2(texture.width / textureRect.width, texture.height / textureRect.height);
|
||||
Vector2 offsetAfter = new Vector2(-(textureRect.x / texture.width) * scaleAfter.x,
|
||||
-(textureRect.y / texture.height) * scaleAfter.y);
|
||||
Vector4 scaleOffset = new Vector4(scaleAfter.x,scaleAfter.y,offsetAfter.x,offsetAfter.y);
|
||||
return scaleOffset;
|
||||
}
|
||||
}
|
||||
11
Packages/NBShaders/Runtime/NBShaderSpriteHelper.cs.meta
Normal file
11
Packages/NBShaders/Runtime/NBShaderSpriteHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58ec7ff2f9b58f5459946ac86028eacf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
664
Packages/NBShaders/Runtime/W9ParticleShaderFlags.cs
Normal file
664
Packages/NBShaders/Runtime/W9ParticleShaderFlags.cs
Normal file
@@ -0,0 +1,664 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class W9ParticleShaderFlags: ShaderFlagsBase
|
||||
{
|
||||
public const string FlagsName = "_W9ParticleShaderFlags";
|
||||
public static int FlagsId = Shader.PropertyToID(FlagsName);
|
||||
|
||||
|
||||
public const string Flags1Name = "_W9ParticleShaderFlags1";
|
||||
public static int Flags1Id = Shader.PropertyToID(Flags1Name);
|
||||
|
||||
public const string WrapFlagsName = "_W9ParticleShaderWrapFlags";
|
||||
public static int WrapFlagsId = Shader.PropertyToID(WrapFlagsName);
|
||||
|
||||
public const string foldOutFlagName = "_W9ParticleShaderGUIFoldToggle";
|
||||
public static int foldOutFlagId = Shader.PropertyToID(foldOutFlagName);
|
||||
|
||||
public const string foldOutFlagName1 = "_W9ParticleShaderGUIFoldToggle1";
|
||||
public static int foldOutFlagId1 = Shader.PropertyToID(foldOutFlagName1);
|
||||
|
||||
|
||||
protected override int GetShaderFlagsId(int index = 0)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return FlagsId;
|
||||
|
||||
case 1:
|
||||
return Flags1Id;
|
||||
|
||||
case 2:
|
||||
return WrapFlagsId;
|
||||
|
||||
case 3:
|
||||
return foldOutFlagId;
|
||||
|
||||
case 4:
|
||||
return foldOutFlagId1;
|
||||
|
||||
default:
|
||||
return FlagsId;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetShaderFlagsName(int index = 0)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return FlagsName;
|
||||
|
||||
case 1:
|
||||
return Flags1Name;
|
||||
|
||||
case 2:
|
||||
return WrapFlagsName;
|
||||
|
||||
case 3:
|
||||
return foldOutFlagName;
|
||||
|
||||
case 4:
|
||||
return foldOutFlagName1;
|
||||
|
||||
default:
|
||||
return FlagsName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public W9ParticleShaderFlags(Material material = null): base(material)
|
||||
{
|
||||
}
|
||||
public const int FLAG_BIT_SATURABILITY_ON = 1 << 0;
|
||||
public const int FLAG_BIT_PARTICLE_NOISE_CHORATICABERRAT_WITH_NOISE = 1 << 1;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_FADE_ON = 1 << 2;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_COLOR_ON = 1 << 3;
|
||||
public const int FLAG_BIT_PARTICLE_USETEXCOORD2 = 1 << 4;
|
||||
public const int FLAG_BIT_PARTICLE_DISTANCEFADE_ON = 1 << 5;
|
||||
public const int FLAG_BIT_PARTICLE_CHORATICABERRAT= 1 << 6;
|
||||
public const int FLAG_BIT_PARTILCE_MASKMAPROTATIONANIMATION_ON = 1 << 7;
|
||||
public const int FLAG_BIT_PARTICLE_POLARCOORDINATES_ON = 1 << 8;
|
||||
public const int FLAG_BIT_PARTICLE_UTWIRL_ON = 1 << 9;
|
||||
public const int FLAG_BIT_PARTICLE_LINEARTOGAMMA_ON = 1 << 10;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_ON = 1 << 11;
|
||||
public const int FLAG_BIT_PARTICLE_NOISEMAP_NORMALIZEED_ON = 1 << 12;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1Z_DISSOLVE_ON = 1 << 13;
|
||||
public const int FLAG_BIT_PARTICLE_UIEFFECT_ON = 1 << 14;
|
||||
public const int FLAG_BIT_PARTICLE_UNSCALETIME_ON = 1 << 15;
|
||||
public const int FLAG_BIT_PARTICLE_SCRIPTABLETIME_ON = 1 << 16;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1_ON = 1 << 17;
|
||||
public const int FLAG_BIT_PARTICLE_FRESNEL_INVERT_ON = 1 << 18;
|
||||
public const int FLAG_BIT_HUESHIFT_ON = 1 << 19;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2_ON = 1 << 20;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1X_MAINTEXOFFSETX = 1 << 21;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1Y_MAINTEXOFFSETY = 1 << 22;
|
||||
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1W_HUESHIFT = 1 << 23;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2X_MASKMAPOFFSETX = 1 << 24;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2Y_MASKMAPOFFSETY = 1 << 25;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2Z_FRESNELOFFSET = 1 << 26;
|
||||
public const int FLAG_BIT_PARTICLE_DISSOLVE_MASK = 1 << 27;
|
||||
public const int FLAG_BIT_PARTICLE_BACKCOLOR = 1 << 28;
|
||||
public const int FLAG_BIT_PARTICLE_PC_ONLYSPECIALFUNC = 1 << 29;
|
||||
public const int FLAG_BIT_PARTICLE_VERTEX_OFFSET_ON = 1 << 30;
|
||||
public const int FLAG_BIT_PARTICLE_VERTEX_OFFSET_NORMAL_DIR= 1 << 31;
|
||||
|
||||
public const int FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE= 1 << 0;
|
||||
public const int FLAG_BIT_PARTICLE_1_PARALLAX_MAPPING= 1 << 1;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1X_DISSOLVETEXOFFSETX= 1 << 2;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1Y_DISSOLVETEXOFFSETY = 1 << 3;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1Z_NOISE_INTENSITY = 1 << 4;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA1W_SATURATE = 1 << 5;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2X_VERTEXOFFSETX = 1 << 6;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2Y_VERTEXOFFSETY = 1 << 7;
|
||||
public const int FLAG_BIT_PARTICLE_CUSTOMDATA2W_CHORATICABERRAT_INTENSITY = 1 << 8;
|
||||
public const int FLAG_BIT_PARTICLE_1_IGNORE_VERTEX_COLOR = 1 << 9;
|
||||
public const int FLAG_BIT_PARTICLE_1_DISSOVLE_VORONOI = 1 << 10;
|
||||
public const int FLAG_BIT_PARTICLE_1_DISSOVLE_USE_RAMP = 1 << 11;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASK_MAP2 = 1 << 12;
|
||||
public const int FLAG_BIT_PARTICLE_1_MASK_MAP3 = 1 << 13;
|
||||
public const int FLAG_BIT_PARTICLE_1_NOISE_MASKMAP = 1 << 14;
|
||||
public const int FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER = 1 << 15;
|
||||
public const int FLAG_BIT_PARTICLE_1_CUSTOMDATA2Z_VERTEXOFFSET_INTENSITY= 1 << 16;
|
||||
public const int FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE= 1 << 17;
|
||||
public const int FLAG_BIT_PARTICLE_1_USE_TEXCOORD1= 1 << 18;
|
||||
public const int FLAG_BIT_PARTICLE_1_USE_TEXCOORD2= 1 << 19;
|
||||
public const int FLAG_BIT_PARTICLE_1_CYLINDER_CORDINATE= 1 << 20;
|
||||
public const int FLAG_BIT_PARTICLE_1_UV_FROM_MESH= 1 << 21;//3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE= 1 << 22;//3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM= 1 << 23;//3D条件下,如果不是来源于Mesh,就默认来源于粒子。
|
||||
public const int FLAG_BIT_PARTICLE_1_MAINTEX_CONTRAST= 1 << 24;
|
||||
public const int FLAG_BIT_PARTICLE_1_VERTEXOFFSET_START_FROM_ZERO= 1 << 25;
|
||||
public const int FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP= 1 << 26;
|
||||
public const int FLAG_BIT_PARTICLE_1_MAINTEX_COLOR_REFINE= 1 << 27;
|
||||
|
||||
|
||||
public const int FLAG_BIT_WRAPMODE_BASEMAP= 1 << 0;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP= 1 << 1;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP2= 1 << 2;
|
||||
public const int FLAG_BIT_WRAPMODE_NOISEMAP= 1 << 3;
|
||||
public const int FLAG_BIT_WRAPMODE_EMISSIONMAP= 1 << 4;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_MAP= 1 << 5;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP= 1 << 6;
|
||||
public const int FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP= 1 << 7;
|
||||
public const int FLAG_BIT_WRAPMODE_COLORBLENDMAP= 1 << 8;
|
||||
public const int FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP= 1 << 9;
|
||||
public const int FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP = 1 << 10;
|
||||
public const int FLAG_BIT_WRAPMODE_MASKMAP3= 1 << 11;
|
||||
public const int FLAG_BIT_WRAPMODE_NOISE_MASKMAP= 1 << 12;
|
||||
public const int FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP= 1 << 13;
|
||||
|
||||
public const int foldOutBitMeshOption = 1 << 0;
|
||||
public const int foldOutBitMainTexOption = 1 << 1;
|
||||
public const int foldOutBitBaseOption = 1 << 2;
|
||||
public const int foldOutBitFeatureOption = 1 << 3;
|
||||
public const int foldOutBitBaseMap = 1 << 4;
|
||||
public const int foldOutBitMask = 1 << 5;
|
||||
public const int foldOutBitMaskMap = 1 << 6;
|
||||
public const int foldOutBitMask2 = 1 << 7;
|
||||
public const int foldOutBitMask3 = 1 << 8;
|
||||
public const int foldOutBitTwril = 1 << 9;
|
||||
public const int foldOutBitPolar = 1 << 10;
|
||||
public const int foldOutBitHueShift = 1 << 11;
|
||||
public const int foldOutBitSaturability = 1 << 12;
|
||||
public const int foldOutBitDistanceFade = 1 << 13;
|
||||
public const int foldOutBitSoftParticles = 1 << 14;
|
||||
public const int foldOutBitMaskRotate = 1 << 15;
|
||||
public const int foldOutBitNoise = 1 << 16;
|
||||
public const int foldOutBitNoiseMap = 1 << 17;
|
||||
public const int foldOutBitNoiseMaskToggle = 1 << 18;
|
||||
public const int foldOutBitEmission= 1 << 19;
|
||||
public const int foldOutBitDistortionChoraticaberrat= 1 << 20;
|
||||
public const int foldOutDissolve= 1 << 21;
|
||||
public const int foldOutDissolveMap= 1 << 22;
|
||||
public const int foldOutDissolveVoronoi= 1 << 23;
|
||||
public const int foldOutDissolveRampMap= 1 << 24;
|
||||
public const int foldOutDissolveMask= 1 << 25;
|
||||
public const int foldOutColorBlend= 1 << 26;
|
||||
public const int foldOutFresnel= 1 << 27;
|
||||
public const int foldOutDepthOutline= 1 << 28;
|
||||
public const int foldOutVertexOffset= 1 << 29;
|
||||
public const int foldOutParallexMapping= 1 << 30;
|
||||
// public const int foldOutPortal= 1 << 31;
|
||||
|
||||
|
||||
|
||||
|
||||
public const int foldOutBit2UVModeMainTex = 1 << 0;
|
||||
public const int foldOutBit2UVModeMaskMap= 1 << 1;
|
||||
public const int foldOutBit2UVModeMaskMap2= 1 << 2;
|
||||
public const int foldOutBit2UVModeMaskMap3= 1 << 3;
|
||||
public const int foldOutBit2UVModeNoiseMap = 1 << 4;
|
||||
public const int foldOutBit2UVModeNoiseMaskMap = 1 << 5;
|
||||
public const int foldOutBit2UVModeEmissionMap = 1 << 6;
|
||||
public const int foldOutBit2UVModeDissolveMap = 1 << 7;
|
||||
public const int foldOutBit2UVModeDissolveMaskMap = 1 << 8;
|
||||
public const int foldOutBit2UVModeColorBlendMap = 1 << 9;
|
||||
public const int foldOutBit2UVModeVertexOffsetMap = 1 << 10;
|
||||
public const int foldOutBit2UVModeVertexOffsetMaskMap = 1 << 11;
|
||||
|
||||
//留一些位置给以后可能会增加的贴图。
|
||||
public const int foldOutPortal= 1 << 20;
|
||||
public const int foldOutZOffset= 1 << 21;
|
||||
public const int foldOutCustomStencilTest= 1 << 22;
|
||||
public const int foldOutTaOption = 1 << 23;
|
||||
public const int foldOutMianTexContrast= 1 << 24;
|
||||
public const int foldOutVertexOffsetMask= 1 << 25;
|
||||
public const int foldOutMainTexColorRefine= 1 << 26;
|
||||
|
||||
|
||||
#region CustomDataCodes
|
||||
|
||||
|
||||
|
||||
|
||||
public const string CustomDataFlag0Name = "_W9ParticleCustomDataFlag0";
|
||||
public const string CustomDataFlag1Name = "_W9ParticleCustomDataFlag1";
|
||||
public const string CustomDataFlag2Name = "_W9ParticleCustomDataFlag2";
|
||||
public const string CustomDataFlag3Name = "_W9ParticleCustomDataFlag3";
|
||||
public static int CustomDataFlag0Id = Shader.PropertyToID(CustomDataFlag0Name);
|
||||
public static int CustomDataFlag1Id = Shader.PropertyToID(CustomDataFlag1Name);
|
||||
public static int CustomDataFlag2Id = Shader.PropertyToID(CustomDataFlag2Name);
|
||||
public static int CustomDataFlag3Id = Shader.PropertyToID(CustomDataFlag3Name);
|
||||
|
||||
public enum CutomDataComponent
|
||||
{
|
||||
Off,
|
||||
CustomData1X,
|
||||
CustomData1Y,
|
||||
CustomData1Z,
|
||||
CustomData1W,
|
||||
CustomData2X,
|
||||
CustomData2Y,
|
||||
CustomData2Z,
|
||||
CustomData2W,
|
||||
}
|
||||
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_DISSOLVE_INTENSITY = 2 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_HUESHIFT = 3 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_X = 4 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_Y = 5 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_FRESNEL_OFFSET = 6 * 4;
|
||||
public const int FLAGBIT_POS_0_CUSTOMDATA_CHORATICABERRAT_INTENSITY = 7 * 4;
|
||||
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_X = 0 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_Y = 1 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_NOISE_INTENSITY = 2 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_SATURATE = 3 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_X = 4 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_Y = 5 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_VERTEXOFFSET_INTENSITY = 6 * 4;
|
||||
public const int FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_MASK_INTENSITY = 7 * 4;
|
||||
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_X = 0*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_Y = 1*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_X = 2*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_Y = 3*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_X= 4*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_Y= 5*4;
|
||||
public const int FLAGBIT_POS_2_CUSTOMDATA_MAINTEX_CONTRAST= 6*4;
|
||||
//---->这里还有一个坑可以用哦
|
||||
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_X= 0*4;
|
||||
public const int FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_Y= 1*4;
|
||||
|
||||
|
||||
public const int isCustomDataBit = 1 << 3;
|
||||
public const int Data12Bit = 1 << 2;//true CustomData1 / false CustomData2
|
||||
public const int DataXYorZWBit = 1 << 1;//true xy / false zw
|
||||
public const int DataXZorYWBit = 1 << 0;//true xz / false yw
|
||||
public const int CustomData1XBit = isCustomDataBit | Data12Bit | DataXYorZWBit | DataXZorYWBit;
|
||||
public const int CustomData1YBit = isCustomDataBit | Data12Bit | DataXYorZWBit ;
|
||||
public const int CustomData1ZBit = isCustomDataBit | Data12Bit | DataXZorYWBit;
|
||||
public const int CustomData1WBit = isCustomDataBit | Data12Bit;
|
||||
public const int CustomData2XBit = isCustomDataBit | DataXYorZWBit | DataXZorYWBit;
|
||||
public const int CustomData2YBit = isCustomDataBit | DataXYorZWBit;
|
||||
public const int CustomData2ZBit = isCustomDataBit | DataXZorYWBit;
|
||||
public const int CustomData2WBit = isCustomDataBit;
|
||||
|
||||
private int GetCustomDataFlagID(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0 :
|
||||
return CustomDataFlag0Id;
|
||||
|
||||
case 1 :
|
||||
return CustomDataFlag1Id;
|
||||
|
||||
case 2 :
|
||||
return CustomDataFlag2Id;
|
||||
case 3 :
|
||||
return CustomDataFlag3Id;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public string GetCustomDataFlagPropertyName(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0 :
|
||||
return CustomDataFlag0Name;
|
||||
|
||||
case 1 :
|
||||
return CustomDataFlag1Name;
|
||||
|
||||
case 2:
|
||||
return CustomDataFlag2Name;
|
||||
|
||||
case 3:
|
||||
return CustomDataFlag3Name;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CutomDataComponent GetCustomDataFlag(int dataBitPos, int dataIndex)
|
||||
{
|
||||
int bit = material.GetInteger(GetCustomDataFlagID(dataIndex));
|
||||
|
||||
bit = bit >> dataBitPos;
|
||||
bit &= 15; // binary 1111
|
||||
|
||||
if ((bit & isCustomDataBit) == 0)
|
||||
{
|
||||
return CutomDataComponent.Off;
|
||||
}
|
||||
else if (bit == CustomData1XBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1X;
|
||||
}
|
||||
else if (bit == CustomData1YBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1Y;
|
||||
}
|
||||
else if (bit == CustomData1ZBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1Z;
|
||||
}
|
||||
else if (bit == CustomData1WBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData1W;
|
||||
}
|
||||
else if (bit == CustomData2XBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2X;
|
||||
}
|
||||
else if (bit == CustomData2YBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2Y;
|
||||
}
|
||||
else if (bit == CustomData2ZBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2Z;
|
||||
}
|
||||
else if (bit == CustomData2WBit)
|
||||
{
|
||||
return CutomDataComponent.CustomData2W;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
Debug.Log("不可能存在的情况");
|
||||
return CutomDataComponent.Off;
|
||||
|
||||
}
|
||||
|
||||
public void SetCustomDataFlag(CutomDataComponent cutomDataComponent,int dataBitPos, int dataIndex)
|
||||
{
|
||||
int bit = 0;
|
||||
switch (cutomDataComponent)
|
||||
{
|
||||
case CutomDataComponent.Off:
|
||||
bit = 0;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1X:
|
||||
bit = CustomData1XBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1Y:
|
||||
bit = CustomData1YBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1Z:
|
||||
bit = CustomData1ZBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData1W:
|
||||
bit = CustomData1WBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2X:
|
||||
bit = CustomData2XBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2Y:
|
||||
bit = CustomData2YBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2Z:
|
||||
bit = CustomData2ZBit;
|
||||
break;
|
||||
case CutomDataComponent.CustomData2W:
|
||||
bit = CustomData2WBit;
|
||||
break;
|
||||
}
|
||||
bit = bit << dataBitPos;
|
||||
int clearBit = ~(15 << dataBitPos);//~ (1111 << dataBitPos)
|
||||
|
||||
int materialBit = material.GetInteger(GetCustomDataFlagID(dataIndex));
|
||||
materialBit = materialBit & clearBit;
|
||||
materialBit = materialBit | bit;
|
||||
material.SetInteger(GetCustomDataFlagID(dataIndex),materialBit);
|
||||
}
|
||||
|
||||
public bool IsCustomDataOn()
|
||||
{
|
||||
int prop0Flag = material.GetInteger(CustomDataFlag0Id);
|
||||
int prop1Flag = material.GetInteger(CustomDataFlag1Id);
|
||||
int prop2Flag = material.GetInteger(CustomDataFlag2Id);
|
||||
int prop3Flag = material.GetInteger(CustomDataFlag3Id);
|
||||
uint dataOnBit = 0b_1000_1000_1000_1000_1000_1000_1000_1000;//10001000100010001000100010001000;
|
||||
|
||||
return ((prop0Flag & dataOnBit) >0) || ((prop1Flag & dataOnBit)>0) || ((prop2Flag & dataOnBit)>0)||((prop3Flag & dataOnBit)>0);
|
||||
}
|
||||
|
||||
bool CheckCustomData(int dataIndex, int flagIndex)
|
||||
{
|
||||
int flagID = 0;
|
||||
switch (flagIndex)
|
||||
{
|
||||
case 0:
|
||||
flagID = CustomDataFlag0Id;
|
||||
break;
|
||||
case 1:
|
||||
flagID = CustomDataFlag1Id;
|
||||
break;
|
||||
case 2:
|
||||
flagID = CustomDataFlag2Id;
|
||||
break;
|
||||
case 3:
|
||||
flagID = CustomDataFlag3Id;
|
||||
break;
|
||||
}
|
||||
|
||||
int flag = material.GetInteger(flagID);
|
||||
int i = 0;
|
||||
while (i<8)
|
||||
{
|
||||
int bit = flag >> (4 * i);
|
||||
if (dataIndex == 1)
|
||||
{
|
||||
if ((bit & 0b_1000) > 0 && (bit & 0b_0100) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(dataIndex == 2)
|
||||
{
|
||||
if ((bit & 0b_1000) > 0 && (bit & 0b_0100) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsCustomData1On()
|
||||
{
|
||||
if (!IsCustomDataOn())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isCustomData1On = false;
|
||||
isCustomData1On |= CheckCustomData(1, 0);
|
||||
isCustomData1On |= CheckCustomData(1, 1);
|
||||
isCustomData1On |= CheckCustomData(1, 2);
|
||||
isCustomData1On |= CheckCustomData(1, 3);
|
||||
return isCustomData1On;
|
||||
|
||||
// int prop0Flag = material.GetInteger(CustomDataFlag0Id);
|
||||
//
|
||||
// int i = 0;
|
||||
// while (i<8)
|
||||
// {
|
||||
// int bit = prop0Flag >> (4 * i);
|
||||
// if ((bit & 0b_1000) > 0 && (bit & 0b_0100) > 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// i += 1;
|
||||
// }
|
||||
//
|
||||
// i = 0;
|
||||
// int prop1Flag = material.GetInteger(CustomDataFlag1Id);
|
||||
// while (i<8)
|
||||
// {
|
||||
// int bit = prop1Flag >> (4 * i);
|
||||
// if ((bit & 0b_1000) > 0 && (bit & 0b_0100) > 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// i += 1;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
public bool IsCustomData2On()
|
||||
{
|
||||
if (!IsCustomDataOn())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool isCustomData1On = false;
|
||||
isCustomData1On |= CheckCustomData(2, 0);
|
||||
isCustomData1On |= CheckCustomData(2, 1);
|
||||
isCustomData1On |= CheckCustomData(2, 2);
|
||||
isCustomData1On |= CheckCustomData(2, 3);
|
||||
return isCustomData1On;
|
||||
// int prop0Flag = material.GetInteger(CustomDataFlag0Id);
|
||||
//
|
||||
// int i = 0;
|
||||
// while (i<8)
|
||||
// {
|
||||
// int bit = prop0Flag >> (4 * i);
|
||||
// if ((bit & 0b_1000) > 0 && (bit & 0b_0100) == 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// i += 1;
|
||||
// }
|
||||
//
|
||||
// i = 0;
|
||||
// int prop1Flag = material.GetInteger(CustomDataFlag1Id);
|
||||
// while (i<8)
|
||||
// {
|
||||
// int bit = prop1Flag >> (4 * i);
|
||||
// if ((bit & 0b_1000) > 0 && (bit & 0b_0100) == 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// i += 1;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public const string UVModeFlag0Name = "_UVModeFlag0";
|
||||
public static int UVModeFlag0PropID = Shader.PropertyToID(UVModeFlag0Name);
|
||||
|
||||
public string GetUVModePropName(int dataIndex)
|
||||
{
|
||||
switch (dataIndex)
|
||||
{
|
||||
case 0:
|
||||
return UVModeFlag0Name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum UVMode
|
||||
{
|
||||
DefaultUVChannel, //0 0b_00
|
||||
SpecialUVChannel, //1 0b_01
|
||||
PolarOrTwirl, //2 0b_10
|
||||
Cylinder //3 0b_11
|
||||
}
|
||||
|
||||
// public enum MeshSourceMode
|
||||
// {
|
||||
// ParticleSystem,
|
||||
// Mesh,
|
||||
// RawImage,
|
||||
// Sprite
|
||||
// }
|
||||
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MAINTEX = 0 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP = 1 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP_2 = 2 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_MASKMAP_3 = 3 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_NOISE_MAP = 4 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_NOISE_MASK_MAP = 5 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_EMISSION_MAP = 6 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_DISSOLVE_MAP = 7 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_DISSOLVE_MASK_MAP = 8 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_COLOR_BLEND_MAP = 9 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MAP = 10 * 2;
|
||||
public const int FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MASKMAP = 11 * 2;
|
||||
|
||||
public int GetUVModeFlagPropID(int flagIndex)
|
||||
{
|
||||
switch (flagIndex)
|
||||
{
|
||||
case 0:
|
||||
return UVModeFlag0PropID;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetUVMode(UVMode mode, int uvModePos, int flagIndex = 0)
|
||||
{
|
||||
int uvModeFlagPropId = GetUVModeFlagPropID(flagIndex);
|
||||
int uvModeFlag = material.GetInteger(uvModeFlagPropId);
|
||||
|
||||
|
||||
int clearFlag = 0b_11 << uvModePos;
|
||||
clearFlag = ~ clearFlag;
|
||||
|
||||
uvModeFlag &= clearFlag;
|
||||
int modeBit = (int)mode << uvModePos;
|
||||
uvModeFlag |= modeBit;
|
||||
|
||||
material.SetInteger(uvModeFlagPropId,uvModeFlag);
|
||||
}
|
||||
|
||||
public UVMode GetUVMode(int uvModePos, int flagIndex = 0)
|
||||
{
|
||||
int uvModeFlagPropId = GetUVModeFlagPropID(flagIndex);
|
||||
int uvModeFlag = material.GetInteger(uvModeFlagPropId);
|
||||
uvModeFlag = uvModeFlag >> uvModePos;
|
||||
uvModeFlag &= 0b_11;
|
||||
return (UVMode)uvModeFlag;
|
||||
}
|
||||
|
||||
public bool CheckIsUVModeOn(UVMode mode)
|
||||
{
|
||||
uint uvModeFlag0 = (uint)material.GetInteger(UVModeFlag0PropID);
|
||||
|
||||
uint uvModeBit = (uint)mode;
|
||||
|
||||
bool isUvMode = false;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
uint checkBit = uvModeFlag0 >> (i * 2);
|
||||
checkBit = checkBit & 0b_11;
|
||||
// Debug.Log("i:"+i);
|
||||
// Debug.Log("uvModeFlag0:"+Convert.ToString(uvModeFlag0,2));
|
||||
// Debug.Log("checkBit:"+Convert.ToString(checkBit,2));
|
||||
// Debug.Log("uvModeBit:"+Convert.ToString(uvModeBit,2));
|
||||
if (checkBit == uvModeBit)
|
||||
{
|
||||
isUvMode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isUvMode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
11
Packages/NBShaders/Runtime/W9ParticleShaderFlags.cs.meta
Normal file
11
Packages/NBShaders/Runtime/W9ParticleShaderFlags.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b13c8a972207b57458dd444106acbf3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Packages/NBShaders/Runtime/com.xuanxuan.nb.shaders.asmdef
Normal file
16
Packages/NBShaders/Runtime/com.xuanxuan.nb.shaders.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.shaders",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e3b0e6ce60c7a34094f8f9822c0b7f2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBShaders/Shader.meta
Normal file
8
Packages/NBShaders/Shader.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fdc89efbf4a9bf4c9449cc01f16d08a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/NBShaders/Shader/HLSL.meta
Normal file
8
Packages/NBShaders/Shader/HLSL.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 944a1679494774748b2936893c18c9ce
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
227
Packages/NBShaders/Shader/HLSL/EffectFlags.hlsl
Normal file
227
Packages/NBShaders/Shader/HLSL/EffectFlags.hlsl
Normal file
@@ -0,0 +1,227 @@
|
||||
#ifndef EFFECT_FLAGS
|
||||
#define EFFECT_FLAGS
|
||||
|
||||
#define FLAG_BIT_SATURABILITY_ON (1 << 0)
|
||||
#define FLAG_BIT_PARTICLE_NOISE_CHORATICABERRAT_WITH_NOISE (1 << 1)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_FADE_ON (1 << 2)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_COLOR_ON (1 << 3)
|
||||
#define FLAG_BIT_PARTICLE_USETEXCOORD2 (1 << 4)
|
||||
#define FLAG_BIT_PARTICLE_DISTANCEFADE_ON (1 << 5)
|
||||
#define FLAG_BIT_PARTICLE_CHORATICABERRAT (1 << 6)
|
||||
#define FLAG_BIT_PARTILCE_MASKMAPROTATIONANIMATION_ON (1 << 7)
|
||||
#define FLAG_BIT_PARTICLE_POLARCOORDINATES_ON (1 << 8)
|
||||
#define FLAG_BIT_PARTICLE_UTWIRL_ON (1 << 9)
|
||||
#define FLAG_BIT_PARTICLE_LINEARTOGAMMA_ON (1 << 10)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_ON (1 << 11)
|
||||
#define FLAG_BIT_PARTICLE_NOISEMAP_NORMALIZEED_ON (1 << 12)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1Z_DISSOLVE_ON (1 << 13)
|
||||
#define FLAG_BIT_PARTICLE_UIEFFECT_ON (1 << 14)
|
||||
#define FLAG_BIT_PARTICLE_UNSCALETIME_ON (1 << 15)
|
||||
#define FLAG_BIT_PARTICLE_SCRIPTABLETIME_ON (1 << 16)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1_ON (1 << 17)
|
||||
#define FLAG_BIT_PARTICLE_FRESNEL_INVERT_ON (1 << 18)
|
||||
#define FLAG_BIT_HUESHIFT_ON (1 << 19)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2_ON (1 << 20)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1X_MAINTEXOFFSETX (1 << 21)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1Y_MAINTEXOFFSETY (1 << 22)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1W_HUESHIFT (1 << 23)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2X_MASKMAPOFFSETX (1 << 24)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2Y_MASKMAPOFFSETY (1 << 25)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2Z_FRESNELOFFSET (1 << 26)
|
||||
#define FLAG_BIT_PARTICLE_DISSOLVE_MASK (1 << 27)
|
||||
#define FLAG_BIT_PARTICLE_BACKCOLOR (1 << 28)
|
||||
#define FLAG_BIT_PARTICLE_PC_ONLYSPECIALFUNC (1 << 29)
|
||||
#define FLAG_BIT_PARTICLE_VERTEX_OFFSET_ON (1 << 30)
|
||||
#define FLAG_BIT_PARTICLE_VERTEX_OFFSET_NORMAL_DIR (1 << 31)
|
||||
// uint _W9ParticleShaderFlags;
|
||||
|
||||
#define FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE (1 << 0)
|
||||
#define FLAG_BIT_PARTICLE_1_PARALLAX_MAPPING (1 << 1)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1X_DISSOLVETEXOFFSETX (1 << 2)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1Y_DISSOLVETEXOFFSETY (1 << 3)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1Z_NOISE_INTENSITY (1 << 4)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA1W_SATURATE (1 << 5)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2X_VERTEXOFFSETX (1 << 6)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2Y_VERTEXOFFSETY (1 << 7)
|
||||
#define FLAG_BIT_PARTICLE_CUSTOMDATA2W_CHORATICABERRAT_INTENSITY (1 << 8)
|
||||
#define FLAG_BIT_PARTICLE_1_IGNORE_VERTEX_COLOR (1 << 9)
|
||||
#define FLAG_BIT_PARTICLE_1_DISSOVLE_VORONOI (1 << 10)
|
||||
#define FLAG_BIT_PARTICLE_1_DISSOVLE_USE_RAMP (1 << 11)
|
||||
#define FLAG_BIT_PARTICLE_1_MASK_MAP2 (1 << 12)
|
||||
#define FLAG_BIT_PARTICLE_1_MASK_MAP3 (1 << 13)
|
||||
#define FLAG_BIT_PARTICLE_1_NOISE_MASKMAP (1 << 14)
|
||||
#define FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER (1 << 15)
|
||||
#define FLAG_BIT_PARTICLE_1_CUSTOMDATA2Z_VERTEXOFFSET_INTENSITY (1 << 16)
|
||||
#define FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE (1 << 17)
|
||||
#define FLAG_BIT_PARTICLE_1_USE_TEXCOORD1 (1 << 18)
|
||||
#define FLAG_BIT_PARTICLE_1_USE_TEXCOORD2 (1 << 19)
|
||||
#define FLAG_BIT_PARTICLE_1_CYLINDER_CORDINATE (1 << 20)
|
||||
#define FLAG_BIT_PARTICLE_1_UV_FROM_MESH (1 << 21)
|
||||
#define FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE (1 << 22)
|
||||
#define FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM (1 << 23)
|
||||
#define FLAG_BIT_PARTICLE_1_MAINTEX_CONTRAST (1 << 24)
|
||||
#define FLAG_BIT_PARTICLE_1_VERTEXOFFSET_START_FROM_ZERO (1 << 25)
|
||||
#define FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP (1 << 26)
|
||||
#define FLAG_BIT_PARTICLE_1_MAINTEX_COLOR_REFINE (1 << 27)
|
||||
|
||||
|
||||
//WrapMode不能够超过16位(因为会占用x和x+16两个bit位)
|
||||
#define FLAG_BIT_WRAPMODE_BASEMAP (1 << 0)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP (1 << 1)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP2 (1 << 2)
|
||||
#define FLAG_BIT_WRAPMODE_NOISEMAP (1 << 3)
|
||||
#define FLAG_BIT_WRAPMODE_EMISSIONMAP (1 << 4)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_MAP (1 << 5)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP (1 << 6)
|
||||
#define FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP (1 << 7)
|
||||
#define FLAG_BIT_WRAPMODE_COLORBLENDMAP (1 << 8)
|
||||
#define FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP (1 << 9)
|
||||
#define FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP (1 << 10)
|
||||
#define FLAG_BIT_WRAPMODE_MASKMAP3 (1 << 11)
|
||||
#define FLAG_BIT_WRAPMODE_NOISE_MASKMAP (1 << 12)
|
||||
#define FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP (1 << 13)
|
||||
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_DISSOLVE_INTENSITY (2*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_HUESHIFT (3*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_X (4*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_Y (5*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_FRESNEL_OFFSET (6*4)
|
||||
#define FLAGBIT_POS_0_CUSTOMDATA_CHORATICABERRAT_INTENSITY (7*4)
|
||||
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_NOISE_INTENSITY (2*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_SATURATE (3*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_X (4*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_Y (5*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_VERTEXOFFSET_INTENSITY (6*4)
|
||||
#define FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_MASK_INTENSITY (7*4)
|
||||
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_X (0*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_Y (1*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_X (2*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_Y (3*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_X (4*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_Y (5*4)
|
||||
#define FLAGBIT_POS_2_CUSTOMDATA_MAINTEX_CONTRAST (6*4)
|
||||
//---->这里还有一个坑可以用哦
|
||||
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_X (0*4)
|
||||
#define FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_Y (1*4)
|
||||
|
||||
#define isCustomDataBit (1 << 3)
|
||||
#define Data12Bit (1 << 2)
|
||||
#define DataXYorZWBit (1 << 1)
|
||||
#define DataXZorYWBit (1 << 0)
|
||||
|
||||
#define FLAG_BIT_UVMODE_POS_0_MAINTEX (0*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP (1*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP_2 (2*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_MASKMAP_3 (3*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_NOISE_MAP (4*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_NOISE_MASK_MAP (5*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_EMISSION_MAP (6*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_DISSOLVE_MAP (7*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_DISSOLVE_MASK_MAP (8*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_COLOR_BLEND_MAP (9*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MAP (10*2)
|
||||
#define FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MASKMAP (11*2)
|
||||
|
||||
float GetCustomData(uint flagProperty,int flagPos,float orignValue,half4 cutstomData1,half4 customData2)
|
||||
{
|
||||
uint bit = flagProperty >> flagPos;
|
||||
|
||||
// bit &= 15;// binary 1111 这一步可能是没必要的。
|
||||
UNITY_BRANCH
|
||||
if((bit & isCustomDataBit) == 0)
|
||||
{
|
||||
return orignValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
half4 customData = 0;
|
||||
if((bit & Data12Bit))
|
||||
{
|
||||
customData = cutstomData1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
customData = customData2;
|
||||
}
|
||||
|
||||
if(bit & DataXYorZWBit)
|
||||
{
|
||||
if(bit & DataXZorYWBit)
|
||||
{
|
||||
return customData.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return customData.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bit & DataXZorYWBit)
|
||||
{
|
||||
return customData.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
return customData.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 999;//提示错误
|
||||
}
|
||||
|
||||
float2 GetUVByUVMode(uint flagProperty,int flagPos,float2 defaultUVChannel,float2 specialUVChannel,float2 polarOrTwirl,float2 cylinderUV)
|
||||
{
|
||||
flagProperty = flagProperty >> flagPos;
|
||||
flagProperty = flagProperty & 3;
|
||||
if(flagProperty == 0)
|
||||
{
|
||||
return defaultUVChannel;
|
||||
}
|
||||
if(flagProperty == 1)
|
||||
{
|
||||
return specialUVChannel;
|
||||
}
|
||||
if(flagProperty == 2)
|
||||
{
|
||||
return polarOrTwirl;
|
||||
}
|
||||
return cylinderUV;
|
||||
}
|
||||
|
||||
struct BaseUVs
|
||||
{
|
||||
float2 defaultUVChannel;
|
||||
float2 specialUVChannel;
|
||||
float2 uvAfterTwirlPolar;
|
||||
float2 cylinderUV;
|
||||
};
|
||||
|
||||
float2 GetUVByUVMode(uint flagProperty,int flagPos,BaseUVs baseUVs)
|
||||
{
|
||||
flagProperty = flagProperty >> flagPos;
|
||||
flagProperty = flagProperty & 3;
|
||||
if(flagProperty == 0)
|
||||
{
|
||||
return baseUVs.defaultUVChannel;
|
||||
}
|
||||
if(flagProperty == 1)
|
||||
{
|
||||
return baseUVs.specialUVChannel;
|
||||
}
|
||||
if(flagProperty == 2)
|
||||
{
|
||||
return baseUVs.uvAfterTwirlPolar;
|
||||
}
|
||||
return baseUVs.cylinderUV;
|
||||
}
|
||||
|
||||
#endif
|
||||
7
Packages/NBShaders/Shader/HLSL/EffectFlags.hlsl.meta
Normal file
7
Packages/NBShaders/Shader/HLSL/EffectFlags.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4918b275ae4dce948a5cedc6f3612066
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
743
Packages/NBShaders/Shader/HLSL/ParticlesUnlitForwardPassNew.hlsl
Normal file
743
Packages/NBShaders/Shader/HLSL/ParticlesUnlitForwardPassNew.hlsl
Normal file
@@ -0,0 +1,743 @@
|
||||
#ifndef PARTICLESUNLITFORWARDPASS
|
||||
#define PARTICLESUNLITFORWARDPASS
|
||||
|
||||
struct AttributesParticle//即URP语境下的appdata
|
||||
{
|
||||
float4 vertex: POSITION;
|
||||
float3 normalOS: NORMAL;
|
||||
half4 color: COLOR;
|
||||
#if defined(_FLIPBOOKBLENDING_ON)
|
||||
float4 texcoords: TEXCOORD0; //texcoords.zw就是粒子那边新建的UV2
|
||||
float3 texcoordBlend: TEXCOORD3;//注意,假如需要UI支持,則Canvas要開放相關Channel
|
||||
#else
|
||||
float4 texcoords: TEXCOORD0;
|
||||
#endif
|
||||
|
||||
#ifdef _PARALLAX_MAPPING
|
||||
float4 tangentOS : TANGENT;
|
||||
#endif
|
||||
|
||||
float4 Custom1: TEXCOORD1;
|
||||
float4 Custom2: TEXCOORD2;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsParticle//即URP语境下的v2f
|
||||
{
|
||||
float4 clipPos: SV_POSITION;
|
||||
|
||||
half4 color: COLOR;
|
||||
float4 texcoord: TEXCOORD0; // 主帖图 和 mask
|
||||
|
||||
#if defined (_EMISSION) || defined(_COLORMAPBLEND)
|
||||
float4 emissionColorBlendTexcoord: TEXCOORD1; // 流光
|
||||
#endif
|
||||
|
||||
#ifdef _NOISEMAP
|
||||
float4 noisemapTexcoord:TEXCOORD2;//Noise
|
||||
#endif
|
||||
|
||||
#if defined(_DISSOLVE)
|
||||
|
||||
float4 dissolveTexcoord:TEXCOORD15;
|
||||
float4 dissolveNoiseTexcoord: TEXCOORD5;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
float4 positionWS: TEXCOORD3;
|
||||
float4 positionOS: TEXCOORD12;
|
||||
|
||||
float4 texcoord2AndSpecialUV: TEXCOORD6; // UV2和SpecialUV
|
||||
|
||||
float4 positionNDC: TEXCOORD7;
|
||||
|
||||
|
||||
float4 VaryingsP_Custom1: TEXCOORD8;
|
||||
float4 VaryingsP_Custom2: TEXCOORD9;
|
||||
|
||||
|
||||
float4 normalWSAndAnimBlend: TEXCOORD10;
|
||||
|
||||
float3 fresnelViewDir :TEXCOORD11;
|
||||
|
||||
float3 viewDirWS :TEXCOORD13;
|
||||
float4 texcoordMaskMap2 : TEXCOORD14;
|
||||
|
||||
#ifdef _PARALLAX_MAPPING
|
||||
half3 tangentViewDir : TEXCOORD16;
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
bool isProcessUVInFrag()
|
||||
{
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_POLARCOORDINATES_ON) || CheckLocalFlags(FLAG_BIT_PARTICLE_UTWIRL_ON))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#if defined(_DEPTH_DECAL) || defined(_PARALLAX_MAPPING) || defined(_SCREEN_DISTORT_MODE)
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Vertex and Fragment functions //
|
||||
|
||||
|
||||
VaryingsParticle vertParticleUnlit(AttributesParticle input)
|
||||
{
|
||||
VaryingsParticle output = (VaryingsParticle)0;
|
||||
|
||||
output.VaryingsP_Custom1 = input.Custom1;
|
||||
output.VaryingsP_Custom2 = input.Custom2;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
time = _Time.y;
|
||||
|
||||
float4 positionOS = input.vertex;
|
||||
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_VERTEX_OFFSET_ON))
|
||||
{
|
||||
//因为极坐标和旋转会强制到Frag计算,所以顶点在这边特殊处理一遍。
|
||||
BaseUVs baseUVsForVertexOffset = ProcessBaseUVs(input.texcoords,0,output.VaryingsP_Custom1,output.VaryingsP_Custom2,positionOS);
|
||||
|
||||
_VertexOffset_Map_ST.z += GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_X,0,input.Custom1,input.Custom2);
|
||||
_VertexOffset_Map_ST.w += GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_VERTEX_OFFSET_Y,0,input.Custom1,input.Custom2);
|
||||
_VertexOffset_Vec.z = GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_VERTEXOFFSET_INTENSITY,_VertexOffset_Vec.z,input.Custom1,input.Custom2);
|
||||
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP))
|
||||
{
|
||||
_VertexOffset_MaskMap_ST.z += GetCustomData(_W9ParticleCustomDataFlag3,FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_X,0,input.Custom1,input.Custom2);
|
||||
_VertexOffset_MaskMap_ST.w += GetCustomData(_W9ParticleCustomDataFlag3,FLAGBIT_POS_3_CUSTOMDATA_VERTEX_OFFSET_MASK_Y,0,input.Custom1,input.Custom2);
|
||||
}
|
||||
|
||||
float2 vertexOffsetUVs = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MAP,baseUVsForVertexOffset);
|
||||
float2 vertexOffsetMaskUVs = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_VERTEX_OFFSET_MASKMAP,baseUVsForVertexOffset);
|
||||
|
||||
positionOS.xyz = VetexOffset(positionOS,vertexOffsetUVs,vertexOffsetMaskUVs,input.normalOS);
|
||||
}
|
||||
|
||||
|
||||
// position ws is used to compute eye depth in vertFading
|
||||
output.positionWS.xyz = mul(unity_ObjectToWorld, positionOS).xyz;
|
||||
output.positionOS.xyz = positionOS;
|
||||
|
||||
output.clipPos = TransformObjectToHClip(positionOS);
|
||||
|
||||
#ifdef _PARALLAX_MAPPING
|
||||
//视差贴图,需要在Tangent空间下计算。
|
||||
float3x3 objectToTangent =
|
||||
float3x3(
|
||||
input.tangentOS.xyz,
|
||||
cross(input.normalOS,input.tangentOS.xyz) * input.tangentOS.w,//Bitangent
|
||||
input.normalOS
|
||||
);
|
||||
output.tangentViewDir = mul(objectToTangent,GetObjectSpaceNormalizeViewDir(positionOS));
|
||||
#endif
|
||||
|
||||
float unityFogFactor = ComputeFogFactor(output.clipPos.z);
|
||||
|
||||
output.positionWS.w = unityFogFactor;
|
||||
|
||||
output.color = TryLinearize(input.color);
|
||||
|
||||
output.viewDirWS = GetWorldSpaceNormalizeViewDir(output.positionWS.xyz);
|
||||
output.normalWSAndAnimBlend.xyz = TransformObjectToWorldNormal(input.normalOS.xyz);
|
||||
|
||||
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_FRESNEL_ON))
|
||||
{
|
||||
output.fresnelViewDir = output.viewDirWS;
|
||||
}
|
||||
|
||||
output.texcoord.xy = input.texcoords.xy;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//顶点处理的原则:
|
||||
//Twirl和极坐标,贴花处理,在片段着色器层处理UV。
|
||||
//BaseMap,遮罩Mask,Noise,高光(自发光) 和极坐标处理相关。
|
||||
if(!isProcessUVInFrag())
|
||||
{
|
||||
|
||||
float2 specialUVInTexcoord3 = 0;
|
||||
//如果同时在粒子系统里开启序列帧融帧和特殊UV通道模式。
|
||||
#if _FLIPBOOKBLENDING_ON
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM) & (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD1)|CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD2)))
|
||||
{
|
||||
specialUVInTexcoord3 = input.texcoordBlend.yz;
|
||||
output.texcoord2AndSpecialUV.zw = specialUVInTexcoord3;
|
||||
}
|
||||
#endif
|
||||
ParticleUVs particleUVs = (ParticleUVs)0;
|
||||
float2 screenUV = 0;
|
||||
|
||||
ParticleProcessUV(input.texcoords, specialUVInTexcoord3,particleUVs,output.VaryingsP_Custom1,output.VaryingsP_Custom2,screenUV,output.positionOS.xyz);
|
||||
output.texcoord2AndSpecialUV.xy = particleUVs.animBlendUV;
|
||||
output.texcoord2AndSpecialUV.zw= particleUVs.specUV;
|
||||
output.texcoord.xy = particleUVs.mainTexUV;
|
||||
output.texcoord.zw = particleUVs.maskMapUV;
|
||||
|
||||
output.texcoordMaskMap2.xy = particleUVs.maskMap2UV;
|
||||
output.texcoordMaskMap2.zw = particleUVs.maskMap3UV;
|
||||
#if defined (_EMISSION) || defined(_COLORMAPBLEND)
|
||||
output.emissionColorBlendTexcoord.xy = particleUVs.emissionUV;
|
||||
output.emissionColorBlendTexcoord.zw = particleUVs.colorBlendUV;
|
||||
#endif
|
||||
|
||||
#ifdef _NOISEMAP
|
||||
output.noisemapTexcoord.xy = particleUVs.noiseMapUV;
|
||||
output.noisemapTexcoord.zw = particleUVs.noiseMaskMapUV;
|
||||
#endif
|
||||
#if defined(_DISSOLVE)
|
||||
output.dissolveTexcoord.xy = particleUVs.dissolve_uv;
|
||||
output.dissolveTexcoord.zw = particleUVs.dissolve_mask_uv;
|
||||
output.dissolveNoiseTexcoord.xy = particleUVs.dissolve_noise1_UV;
|
||||
output.dissolveNoiseTexcoord.zw = particleUVs.dissolve_noise2_UV;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
output.texcoord = input.texcoords;
|
||||
#if _FLIPBOOKBLENDING_ON
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM) & CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD2))
|
||||
{
|
||||
output.texcoord2AndSpecialUV.zw = input.texcoordBlend.yz;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef _FLIPBOOKBLENDING_ON
|
||||
//粒子帧融合的情况,兼容一下。
|
||||
output.normalWSAndAnimBlend.w = input.texcoordBlend.x;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UNITY_BRANCH
|
||||
if(needEyeDepth())
|
||||
{
|
||||
float4 ndc = output.clipPos*0.5f;
|
||||
output.positionNDC.xy = float2(ndc.x, ndc.y * _ProjectionParams.x) + ndc.w;
|
||||
output.positionNDC.zw = output.clipPos.zw;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////Fragment functions ////////////////////////
|
||||
|
||||
half4 fragParticleUnlit(VaryingsParticle input, half facing : VFACE): SV_Target
|
||||
{
|
||||
|
||||
input.viewDirWS = normalize(input.viewDirWS );
|
||||
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
|
||||
time = _Time.y;
|
||||
|
||||
float2 screenUV = input.clipPos.xy / _ScaledScreenParams.xy;
|
||||
|
||||
real sceneZBufferDepth = 0;
|
||||
real sceneZ = 0;
|
||||
|
||||
UNITY_BRANCH
|
||||
if(needSceneDepth())
|
||||
{
|
||||
#if UNITY_REVERSED_Z
|
||||
sceneZBufferDepth = SampleSceneDepth(screenUV);
|
||||
#else
|
||||
// Adjust z to match NDC for OpenGL
|
||||
sceneZBufferDepth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(screenUV));
|
||||
#endif
|
||||
sceneZ = (unity_OrthoParams.w == 0) ? LinearEyeDepth(sceneZBufferDepth, _ZBufferParams) : LinearDepthToEyeDepth(sceneZBufferDepth);//场景当前深度
|
||||
}
|
||||
|
||||
real thisZ = 0;
|
||||
if(needEyeDepth())
|
||||
{
|
||||
thisZ = LinearEyeDepth(input.positionNDC.z / input.positionNDC.w, _ZBufferParams);//当前Frag深度。
|
||||
}
|
||||
|
||||
|
||||
#ifdef _DEPTH_DECAL
|
||||
float3 fragWorldPos = ComputeWorldSpacePosition(screenUV, sceneZBufferDepth, UNITY_MATRIX_I_VP);
|
||||
float3 fragobjectPos = TransformWorldToObject(fragWorldPos);
|
||||
|
||||
float3 absFragObjectPos = abs(fragobjectPos);
|
||||
half clipValue = step(absFragObjectPos.x,0.5);
|
||||
clipValue *= step(absFragObjectPos.y,0.5);
|
||||
clipValue *= step(absFragObjectPos.z,0.5);
|
||||
half decalAlpha = NB_Remap (abs(fragobjectPos.y),0.1,0.5,1,0);
|
||||
decalAlpha *= clipValue;
|
||||
float2 decalUV = fragobjectPos.xz + 0.5;
|
||||
|
||||
#endif
|
||||
|
||||
float4 uv = input.texcoord;
|
||||
#ifdef _DEPTH_DECAL
|
||||
uv.xy = decalUV;
|
||||
#endif
|
||||
|
||||
float3 blendUv;
|
||||
blendUv.xy = input.texcoord2AndSpecialUV.xy;
|
||||
blendUv.z = input.normalWSAndAnimBlend.w;
|
||||
float2 MaskMapuv;
|
||||
float2 MaskMapuv2;
|
||||
float2 MaskMapuv3;
|
||||
float2 noiseMap_uv;
|
||||
float2 noiseMaskMap_uv;
|
||||
float2 colorBlendMap_uv;
|
||||
float2 emission_uv;
|
||||
float2 dissolve_uv;
|
||||
float2 dissolve_mask_uv;
|
||||
float4 dissolve_noise_uv;
|
||||
|
||||
//如果同时在粒子系统里开启序列帧融帧和特殊UV通道模式。
|
||||
|
||||
if(isProcessUVInFrag())
|
||||
{
|
||||
float2 specialUVInTexcoord3 = 0;
|
||||
#if _FLIPBOOKBLENDING_ON
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM) & (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD2)))
|
||||
{
|
||||
specialUVInTexcoord3 = input.texcoord2AndSpecialUV.zw;
|
||||
}
|
||||
|
||||
#endif
|
||||
ParticleUVs particleUVs = (ParticleUVs)0;
|
||||
ParticleProcessUV(uv,specialUVInTexcoord3,particleUVs,input.VaryingsP_Custom1,input.VaryingsP_Custom2,screenUV,input.positionOS.xyz);
|
||||
uv.xy = particleUVs.mainTexUV;
|
||||
blendUv.xy = particleUVs.animBlendUV;
|
||||
MaskMapuv = particleUVs.maskMapUV;
|
||||
MaskMapuv2 = particleUVs.maskMap2UV;
|
||||
MaskMapuv3 = particleUVs.maskMap3UV;
|
||||
emission_uv = particleUVs.emissionUV;
|
||||
dissolve_uv = particleUVs.dissolve_uv;
|
||||
dissolve_mask_uv = particleUVs.dissolve_mask_uv;
|
||||
colorBlendMap_uv = particleUVs.colorBlendUV;
|
||||
noiseMap_uv = particleUVs.noiseMapUV;
|
||||
noiseMaskMap_uv = particleUVs.noiseMaskMapUV;
|
||||
dissolve_noise_uv = float4(particleUVs.dissolve_noise1_UV,particleUVs.dissolve_noise2_UV);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MaskMapuv = input.texcoord.zw;
|
||||
MaskMapuv2 = input.texcoordMaskMap2.xy;
|
||||
MaskMapuv3 = input.texcoordMaskMap2.zw;
|
||||
#ifdef _NOISEMAP
|
||||
noiseMap_uv = input.noisemapTexcoord.xy;
|
||||
noiseMaskMap_uv = input.noisemapTexcoord.zw;
|
||||
#endif
|
||||
|
||||
#if defined (_EMISSION) || defined(_COLORMAPBLEND)
|
||||
emission_uv = input.emissionColorBlendTexcoord.xy;
|
||||
colorBlendMap_uv = input.emissionColorBlendTexcoord.zw;
|
||||
#endif
|
||||
|
||||
#ifdef _DISSOLVE
|
||||
dissolve_uv = input.dissolveTexcoord.xy;
|
||||
dissolve_mask_uv = input.dissolveTexcoord.zw;
|
||||
dissolve_noise_uv = input.dissolveNoiseTexcoord;
|
||||
#endif
|
||||
}
|
||||
half2 originUV = uv;
|
||||
|
||||
#ifdef _PARALLAX_MAPPING
|
||||
uv.xy = ParallaxOcclusionMapping(uv,input.tangentViewDir);
|
||||
#endif
|
||||
|
||||
half2 cum_noise = 0;
|
||||
half2 cum_noise_xy = 0.5;
|
||||
half noiseMask = 1;
|
||||
#if defined(_NOISEMAP)
|
||||
half4 noiseSample = SampleNoise(_NoiseOffset, _NoiseMap, noiseMap_uv, input.positionWS.xyz);
|
||||
cum_noise = noiseSample.xy;
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_NOISEMAP_NORMALIZEED_ON))
|
||||
{
|
||||
cum_noise = cum_noise * 2 - 1;
|
||||
}
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_NOISE_MASKMAP))
|
||||
{
|
||||
noiseMask= SampleTexture2DWithWrapFlags(_NoiseMaskMap,noiseMaskMap_uv,FLAG_BIT_WRAPMODE_NOISE_MASKMAP).r;
|
||||
noiseMask *= noiseSample.a;
|
||||
}
|
||||
_TexDistortion_intensity = GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_NOISE_INTENSITY,_TexDistortion_intensity,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
|
||||
_DistortionDirection.x += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_X,0,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
_DistortionDirection.y += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_NOISE_DIRECTION_Y,0,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
// 将扭曲放到post去做
|
||||
#if defined(_SCREEN_DISTORT_MODE)
|
||||
cum_noise_xy = cum_noise * _TexDistortion_intensity * _DistortionDirection.xy;
|
||||
cum_noise_xy = cum_noise_xy * 1.25 + 0.5;
|
||||
#endif
|
||||
|
||||
float2 mainTexNoise = cum_noise * noiseMask * _TexDistortion_intensity * _DistortionDirection.xy;
|
||||
uv.xy += mainTexNoise;//主贴图纹理扭曲
|
||||
blendUv.xy += mainTexNoise;
|
||||
#endif
|
||||
|
||||
// SampleAlbedo--------------------
|
||||
half4 albedo = 0;
|
||||
#if defined(_SCREEN_DISTORT_MODE)
|
||||
albedo = half4(cum_noise_xy, 1.0, noiseMask);
|
||||
#else
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_BACKCOLOR))
|
||||
{
|
||||
_BaseColor = facing > 0 ? _BaseColor : _BaseBackColor;
|
||||
}
|
||||
|
||||
|
||||
Texture2D baseMap;
|
||||
|
||||
#ifdef _SCREEN_DISTORT_MODE
|
||||
baseMap = _ScreenColorCopy1;
|
||||
#else
|
||||
baseMap = _BaseMap;
|
||||
#endif
|
||||
|
||||
|
||||
UNITY_BRANCH
|
||||
if (CheckLocalFlags(FLAG_BIT_PARTICLE_UIEFFECT_ON) & !CheckLocalFlags1(FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE))
|
||||
{
|
||||
albedo = BlendTexture(_MainTex, uv, blendUv) * _Color;
|
||||
}
|
||||
else if (CheckLocalFlags(FLAG_BIT_PARTICLE_CHORATICABERRAT))
|
||||
{
|
||||
|
||||
_DistortionDirection.z = GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_CHORATICABERRAT_INTENSITY,_DistortionDirection.z,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
_DistortionDirection.z *= 0.1;
|
||||
albedo = DistortionChoraticaberrat(baseMap,originUV,uv,_DistortionDirection.z,FLAG_BIT_WRAPMODE_BASEMAP);
|
||||
}
|
||||
else
|
||||
{
|
||||
albedo = BlendTexture(baseMap, uv, blendUv,FLAG_BIT_WRAPMODE_BASEMAP);
|
||||
|
||||
}
|
||||
albedo *= _BaseColor ;
|
||||
albedo.rgb *= _BaseColorIntensityForTimeline;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
half alpha = albedo.a;
|
||||
half3 result = albedo.rgb;
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_HUESHIFT_ON))
|
||||
{
|
||||
half3 hsv = RgbToHsv(result);
|
||||
_HueShift = GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_HUESHIFT,_HueShift,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
hsv.r += _HueShift;
|
||||
result = HsvToRgb(hsv);
|
||||
}
|
||||
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MAINTEX_CONTRAST))
|
||||
{
|
||||
_Contrast = GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_MAINTEX_CONTRAST,_Contrast,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
result.rgb = lerp(_ContrastMidColor,result.rgb,_Contrast);
|
||||
}
|
||||
|
||||
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MAINTEX_COLOR_REFINE))
|
||||
{
|
||||
half3 colorA = result.rgb*_BaseMapColorRefine.x;
|
||||
half3 colorB = pow(result.rgb,_BaseMapColorRefine.y)*_BaseMapColorRefine.z;
|
||||
result.rgb = lerp(colorA,colorB,_BaseMapColorRefine.w);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//流光部分
|
||||
half4 emission = half4(0, 0, 0,1);
|
||||
#if defined(_EMISSION)
|
||||
#ifdef _NOISEMAP
|
||||
emission_uv += cum_noise * _Emi_Distortion_intensity;
|
||||
#endif
|
||||
// emission = tex2D_TryLinearizeWithoutAlphaFX(_EmissionMap,emission_uv);
|
||||
emission = SampleTexture2DWithWrapFlags(_EmissionMap,emission_uv,FLAG_BIT_WRAPMODE_EMISSIONMAP);
|
||||
emission.xyz *= emission.a;
|
||||
_EmissionMapColor *= _EmissionMapColorIntensity;
|
||||
emission.xyz *= _EmissionMapColor;
|
||||
|
||||
#endif
|
||||
|
||||
result += emission;
|
||||
|
||||
//溶解部分
|
||||
#if defined(_DISSOLVE)
|
||||
#ifdef _NOISEMAP
|
||||
dissolve_uv += cum_noise * _DissolveOffsetRotateDistort.w;
|
||||
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_DISSOLVE_MASK))
|
||||
{
|
||||
dissolve_mask_uv += cum_noise * _DissolveOffsetRotateDistort.w;
|
||||
}
|
||||
#endif
|
||||
half dissolveValue;
|
||||
|
||||
dissolveValue = SampleTexture2DWithWrapFlags(_DissolveMap,dissolve_uv,FLAG_BIT_WRAPMODE_DISSOLVE_MAP);
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DISSOVLE_VORONOI))
|
||||
{
|
||||
half cell;
|
||||
half noise1;
|
||||
noise1 = SimplexNoise(dissolve_noise_uv.xy,_Time.y*_DissolveVoronoi_Vec2.z);
|
||||
|
||||
half noise2;
|
||||
Unity_Voronoi_float(dissolve_noise_uv.zw,_Time.y*_DissolveVoronoi_Vec2.w,_DissolveVoronoi_Vec.zw,noise2,cell);
|
||||
half overlayVoroni;
|
||||
|
||||
half dissolveSample = dissolveValue;
|
||||
Unity_Blend_HardLight_half(noise1,noise2,_DissolveVoronoi_Vec2.x,overlayVoroni);
|
||||
|
||||
Unity_Blend_HardLight_half(overlayVoroni,dissolveSample,_DissolveVoronoi_Vec2.y,dissolveValue);
|
||||
|
||||
|
||||
}
|
||||
|
||||
dissolveValue = SimpleSmoothstep(_Dissolve_Vec2.x,_Dissolve_Vec2.y,dissolveValue);
|
||||
|
||||
#ifdef _DISSOLVE_EDITOR_TEST //后续Test类的关键字要找机会排除
|
||||
return half4(dissolveValue.rrr,1);
|
||||
#endif
|
||||
|
||||
|
||||
half dissolveMaskValue = 0;
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_DISSOLVE_MASK))
|
||||
{
|
||||
dissolveMaskValue = SampleTexture2DWithWrapFlags(_DissolveMaskMap,dissolve_mask_uv,FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP);
|
||||
_Dissolve.z += GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_MASK_INTENSITY,0,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
dissolveMaskValue *= _Dissolve.z;
|
||||
dissolveValue = lerp(dissolveValue,1.01,dissolveMaskValue);
|
||||
}
|
||||
half originDissolve = dissolveValue;
|
||||
|
||||
_Dissolve.x += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_DISSOLVE_INTENSITY,0,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
|
||||
dissolveValue = dissolveValue-_Dissolve.x;
|
||||
half dissolveValueBeforeSoftStep = dissolveValue;
|
||||
half softStep = _Dissolve.w;
|
||||
dissolveValue = SimpleSmoothstep(0,softStep,(dissolveValue));
|
||||
|
||||
alpha *= dissolveValue;
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DISSOVLE_USE_RAMP))
|
||||
{
|
||||
half rampRange = 1-dissolveValueBeforeSoftStep ;
|
||||
rampRange = rampRange * _DissolveRampMap_ST.x +_DissolveRampMap_ST.z;
|
||||
|
||||
half4 rampSample = SampleTexture2DWithWrapFlags(_DissolveRampMap,half2(rampRange,0.5),FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP);
|
||||
result = lerp(result,rampSample.rgb*_DissolveRampColor.rgb,rampSample.a*_DissolveRampColor.a);
|
||||
}
|
||||
|
||||
half lineMask = 1 - smoothstep(0,softStep,alpha * (dissolveValueBeforeSoftStep - _Dissolve.y));
|
||||
result = lerp(result,_DissolveLineColor.rgb,lineMask*_DissolveLineColor.a);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//颜色渐变
|
||||
#ifdef _COLORMAPBLEND
|
||||
half4 colorBlend = SampleTexture2DWithWrapFlags(_ColorBlendMap,colorBlendMap_uv,FLAG_BIT_WRAPMODE_COLORBLENDMAP);
|
||||
colorBlend.rgb = colorBlend.rgb * _ColorBlendColor.rgb;
|
||||
result.rgb = lerp(result.rgb,result.rgb * colorBlend.rgb,_ColorBlendColor.a);
|
||||
#endif
|
||||
|
||||
//菲涅
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_FRESNEL_ON))
|
||||
{
|
||||
half fresnelValue = 0;
|
||||
if(!ignoreFresnel())
|
||||
{
|
||||
half3 fresnelDir = normalize(input.fresnelViewDir+_FresnelRotation.rgb);
|
||||
|
||||
half dotNV = dot(fresnelDir,input.normalWSAndAnimBlend.xyz) ;
|
||||
fresnelValue = dotNV;
|
||||
|
||||
|
||||
_FresnelUnit.x += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_FRESNEL_OFFSET,0,input.VaryingsP_Custom1,input.VaryingsP_Custom2);;
|
||||
|
||||
fresnelValue = NB_Remap(fresnelValue,_FresnelUnit.x,1,0,1);
|
||||
UNITY_BRANCH
|
||||
if(!CheckLocalFlags(FLAG_BIT_PARTICLE_FRESNEL_INVERT_ON))
|
||||
{
|
||||
fresnelValue = 1- fresnelValue;
|
||||
}
|
||||
fresnelValue = pow(fresnelValue,_FresnelUnit.y);
|
||||
|
||||
half fresnelHardness = (1 - _FresnelUnit.w)*0.5;
|
||||
|
||||
fresnelValue = smoothstep(0.5-fresnelHardness,0.5+fresnelHardness,fresnelValue);
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_FRESNEL_COLOR_ON))
|
||||
{
|
||||
float fresnelColorIntensity = fresnelValue*_FresnelColor.a*_FresnelUnit.z;
|
||||
|
||||
result = lerp(result,_FresnelColor.rgb,fresnelColorIntensity);
|
||||
alpha = max(alpha,fresnelColorIntensity);//颜色要不要不被主贴图Alpha影响呢?
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_FRESNEL_FADE_ON))
|
||||
{
|
||||
fresnelValue *= alpha;
|
||||
alpha = lerp(alpha,fresnelValue,_FresnelUnit.z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE))
|
||||
{
|
||||
half depthOutlineValue = 1- SoftParticles(_DepthOutline_Vec.x, _DepthOutline_Vec.y, sceneZ,thisZ);
|
||||
depthOutlineValue *= _DepthOutline_Color.a;
|
||||
half3 originResult = result;
|
||||
//如何在一个pass里,完美的给出两个颜色的Fade。这个问题,没有想清楚。
|
||||
result = lerp(result,_DepthOutline_Color.rgb,clamp(depthOutlineValue*3,0,1));
|
||||
result = lerp(result,originResult,clamp(alpha-depthOutlineValue,0,1));
|
||||
alpha = max(alpha,depthOutlineValue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//遮罩部分
|
||||
#if defined(_MASKMAP_ON)
|
||||
|
||||
#if defined(_NOISEMAP)
|
||||
MaskMapuv += cum_noise * _MaskDistortion_intensity; //加入扭曲效果
|
||||
#endif
|
||||
half4 maskmap1 = SampleTexture2DWithWrapFlags(_MaskMap, MaskMapuv,FLAG_BIT_WRAPMODE_MASKMAP);
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MASK_MAP2))
|
||||
{
|
||||
half maskMap2 = SampleTexture2DWithWrapFlags(_MaskMap2, MaskMapuv2,FLAG_BIT_WRAPMODE_MASKMAP2).r;
|
||||
maskmap1 *= maskMap2;
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MASK_MAP3))
|
||||
{
|
||||
half maskMap3 = SampleTexture2DWithWrapFlags(_MaskMap3, MaskMapuv3,FLAG_BIT_WRAPMODE_MASKMAP3).r;
|
||||
maskmap1 *= maskMap3;
|
||||
}
|
||||
|
||||
maskmap1.rgb = lerp(1,maskmap1.rgb,_MaskMapVec.x);
|
||||
maskmap1.rgb = saturate(maskmap1.rgb);
|
||||
|
||||
maskmap1.rgb *= maskmap1.a;//预乘
|
||||
|
||||
alpha *= maskmap1.r; //mask边缘
|
||||
#endif
|
||||
|
||||
|
||||
//可以看https://www.cyanilux.com/tutorials/depth/
|
||||
// float4 projectedPosition = input.positionNDC;
|
||||
// float thisZ1 = LinearEyeDepth(projectedPosition.z / projectedPosition.w, _ZBufferParams);
|
||||
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_DISTANCEFADE_ON))
|
||||
{
|
||||
half fade = DepthFactor(thisZ, _Fade.x, _Fade.y);
|
||||
alpha *= fade;
|
||||
}
|
||||
|
||||
|
||||
#if defined(_SOFTPARTICLES_ON)
|
||||
|
||||
half softAlpha = SoftParticles(SOFT_PARTICLE_NEAR_FADE, SOFT_PARTICLE_INV_FADE_DISTANCE, sceneZ,thisZ);
|
||||
alpha *= softAlpha;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_SATURABILITY_ON))
|
||||
{
|
||||
half3 resultWB = luminance(result);
|
||||
_Saturability = GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_SATURATE,_Saturability,input.VaryingsP_Custom1,input.VaryingsP_Custom2);
|
||||
result.rgb = lerp(resultWB.rgb, result.rgb, _Saturability);
|
||||
}
|
||||
|
||||
|
||||
//和粒子颜色信息运算。雨轩:乘顶点色。
|
||||
if(!CheckLocalFlags1(FLAG_BIT_PARTICLE_1_IGNORE_VERTEX_COLOR))
|
||||
{
|
||||
result *= input.color.rgb;
|
||||
alpha *= input.color.a;
|
||||
}
|
||||
// 程序额外的颜色
|
||||
result *= _ColorA.rgb;
|
||||
alpha *= _ColorA.a;
|
||||
// // alpha *= _ColorA * 0.8;
|
||||
|
||||
|
||||
#ifdef _DEPTH_DECAL
|
||||
alpha *= decalAlpha;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
half3 beforeFogResult = result;
|
||||
result = MixFog(result,input.positionWS.w);
|
||||
result = lerp(beforeFogResult, result, _fogintensity);
|
||||
|
||||
|
||||
|
||||
#ifndef _SCREEN_DISTORT_MODE
|
||||
result.rgb = result.rgb * alpha;
|
||||
#endif
|
||||
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_LINEARTOGAMMA_ON))
|
||||
{
|
||||
result.rgb = LinearToGammaSpace(result.rgb);
|
||||
}
|
||||
|
||||
|
||||
alpha *= _AlphaAll;
|
||||
|
||||
half4 color = half4(result, alpha);
|
||||
|
||||
#ifdef _ALPHATEST_ON
|
||||
clip(color.a - _Cutoff);
|
||||
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9187c1d488f62d9458d6ce67858a43b3
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
988
Packages/NBShaders/Shader/HLSL/ParticlesUnlitInputNew.hlsl
Normal file
988
Packages/NBShaders/Shader/HLSL/ParticlesUnlitInputNew.hlsl
Normal file
@@ -0,0 +1,988 @@
|
||||
#ifndef PARTICLESUNLITINPUT
|
||||
#define PARTICLESUNLITINPUT
|
||||
|
||||
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
|
||||
//---------------particleInput-------------------
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _SoftParticleFadeParams;
|
||||
float4 _CameraFadeParams;
|
||||
// #ifdef _INTERSECT_ON
|
||||
float _IntersectRadius;
|
||||
half4 _IntersectColor;
|
||||
// #endif
|
||||
half _Saturability;
|
||||
half _HueShift;
|
||||
half _Contrast;
|
||||
half3 _ContrastMidColor;
|
||||
half4 _BaseMapColorRefine;
|
||||
half _AlphaAll;
|
||||
float4 _BaseMap_ST;
|
||||
float4 _BaseMap_AnimationSheetBlend_ST;//20240826 暂时只是给AnimationSheetHelper用。
|
||||
half _AnimationSheetHelperBlendIntensity;
|
||||
float4 _MaskMap_ST;
|
||||
half4 _BaseColor;
|
||||
half4 _BaseBackColor;
|
||||
half _BaseColorIntensityForTimeline;
|
||||
half4 _EmissionMap_ST;
|
||||
half4 _NoiseMap_ST;
|
||||
half4 _NoiseMaskMap_ST;
|
||||
half4 _DistortionDirection;
|
||||
half4 _BaseColorAddSubDiff;
|
||||
half _fogintensity;
|
||||
half _Emi_Distortion_intensity;
|
||||
half _BaseMapUVRotation;
|
||||
float _MaskMapUVRotation;
|
||||
float _NoiseMapUVRotation;
|
||||
half _uvRapSoft;
|
||||
half4 _EmissionMapColor;
|
||||
half _EmissionMapColorIntensity;
|
||||
|
||||
half _EdgeFade;
|
||||
half4 _NoiseOffset;
|
||||
half4 _EmissionMapUVOffset;
|
||||
half _EmissionMapUVRotation;
|
||||
half _EmissionSelfAlphaWeight;
|
||||
half _TexDistortion_intensity;
|
||||
// //half _RJ_Distortion_intensity;
|
||||
// half _XianXingCH_UVRota;
|
||||
// half _jingxiangCH_dire;
|
||||
|
||||
half _MaskDistortion_intensity;
|
||||
half4 _BaseMapMaskMapOffset;
|
||||
half4 _MaskMapOffsetAnition;
|
||||
half4 _MaskMap3OffsetAnition;
|
||||
half4 _MaskMapVec;
|
||||
float4 _PCCenter;
|
||||
float4 _TWParameter;
|
||||
float _TWStrength;
|
||||
float4 _Fade;
|
||||
float _MaskMapRotationSpeed;
|
||||
|
||||
|
||||
half _FrePower;
|
||||
half _FresnelInOutSlider;
|
||||
half4 _FresnelRotation;
|
||||
half _FresnelSelfAlphaWeight;
|
||||
half4 _FresnelUnit;
|
||||
half4 _FresnelUnit2;
|
||||
half4 _DepthOutline_Vec;
|
||||
half4 _DepthOutline_Color;
|
||||
half4 _FresnelColor;
|
||||
half4 _ColorA;
|
||||
float4 _ClipRect;
|
||||
|
||||
float4 _CylinderMatrix0;
|
||||
float4 _CylinderMatrix1;
|
||||
float4 _CylinderMatrix2;
|
||||
float4 _CylinderMatrix3;
|
||||
|
||||
half4 _Color;
|
||||
float4 _UI_MainTex_ST;//在UI中,RawImage组件的功能和正常的TexST不一致,所以这里使用另外传的方式。
|
||||
float4 _MainTex_Reverse_ST;
|
||||
|
||||
half _Cutoff;
|
||||
|
||||
float4 _MaskMap2_ST;
|
||||
float4 _MaskMap3_ST;
|
||||
|
||||
float time;
|
||||
half _FresnelFadeDistance;
|
||||
|
||||
half4 LB_RT;
|
||||
|
||||
half4 _Dissolve;
|
||||
half4 _DissolveMap_ST;
|
||||
half4 _DissolveOffsetRotateDistort;
|
||||
half4 _DissolveMaskMap_ST;
|
||||
|
||||
half4 _DissolveLineColor;
|
||||
half4 _DissolveRampColor;
|
||||
float4 _DissolveVoronoi_Vec;
|
||||
half4 _DissolveVoronoi_Vec2;
|
||||
float4 _DissolveVoronoi_Vec3;
|
||||
float4 _DissolveVoronoi_Vec4;
|
||||
half4 _DissolveRampMap_ST;
|
||||
half4 _Dissolve_Vec2;
|
||||
|
||||
half4 _ColorBlendMap_ST;
|
||||
half2 _ColorBlendMapOffset;
|
||||
half4 _ColorBlendColor;
|
||||
|
||||
half3 _VertexOffset_Vec;
|
||||
half3 _VertexOffset_CustomDir;
|
||||
half4 _VertexOffset_Map_ST;
|
||||
|
||||
half4 _VertexOffset_MaskMap_ST;
|
||||
half3 _VertexOffset_MaskMap_Vec;
|
||||
|
||||
half _ParallaxMapping_Intensity;
|
||||
half4 _ParallaxMapping_Map_ST;
|
||||
half4 _ParallaxMapping_Vec;
|
||||
|
||||
uint _W9ParticleShaderFlags;
|
||||
|
||||
uint _W9ParticleShaderFlags1;
|
||||
|
||||
uint _W9ParticleShaderWrapFlags;
|
||||
|
||||
uint _W9ParticleCustomDataFlag0;
|
||||
uint _W9ParticleCustomDataFlag1;
|
||||
uint _W9ParticleCustomDataFlag2;
|
||||
uint _W9ParticleCustomDataFlag3;
|
||||
|
||||
uint _UVModeFlag0;
|
||||
|
||||
CBUFFER_END
|
||||
|
||||
|
||||
bool CheckLocalFlags(uint bits)
|
||||
{
|
||||
return (_W9ParticleShaderFlags&bits) != 0;
|
||||
}
|
||||
bool CheckLocalFlags1(uint bits)
|
||||
{
|
||||
return (_W9ParticleShaderFlags1&bits) != 0;
|
||||
}
|
||||
int CheckLocalWrapFlags(uint bits)
|
||||
{
|
||||
bool bit0 = (_W9ParticleShaderWrapFlags&bits) != 0;
|
||||
bool bit1 = (_W9ParticleShaderWrapFlags&(bits<<16)) != 0;
|
||||
if(!bit0 && !bit1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(bit0 && !bit1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(!bit0 && bit1)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if(bit0 && bit1)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
SamplerState sampler_linear_repeat;
|
||||
SamplerState sampler_linear_clamp;
|
||||
SamplerState sampler_linear_RepeatU_ClampV;
|
||||
SamplerState sampler_linear_ClampU_RepeatV;
|
||||
|
||||
half4 SampleTexture2DWithWrapFlags(Texture2D tex,float2 uv,uint bits,bool sampleLOD = false,int lod = 0)
|
||||
{
|
||||
const int wrapMode = CheckLocalWrapFlags(bits);
|
||||
switch (wrapMode)
|
||||
{
|
||||
case 0:
|
||||
if (sampleLOD)
|
||||
{
|
||||
return SAMPLE_TEXTURE2D_LOD(tex,sampler_linear_repeat,uv,lod);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return tex.Sample(sampler_linear_repeat,uv);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (sampleLOD)
|
||||
{
|
||||
return SAMPLE_TEXTURE2D_LOD(tex,sampler_linear_clamp,uv,lod);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return tex.Sample(sampler_linear_clamp,uv);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (sampleLOD)
|
||||
{
|
||||
return SAMPLE_TEXTURE2D_LOD(tex,sampler_linear_RepeatU_ClampV,uv,lod);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return tex.Sample(sampler_linear_RepeatU_ClampV,uv);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (sampleLOD)
|
||||
{
|
||||
return SAMPLE_TEXTURE2D_LOD(tex,sampler_linear_ClampU_RepeatV,uv,lod);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return tex.Sample(sampler_linear_ClampU_RepeatV,uv);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (sampleLOD)
|
||||
{
|
||||
return SAMPLE_TEXTURE2D_LOD(tex,sampler_linear_repeat,uv,lod);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return tex.Sample(sampler_linear_repeat,uv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "../HLSL/EffectFlags.hlsl"
|
||||
|
||||
|
||||
samplerCUBE _FresnelHDRITex;
|
||||
sampler2D _MainTex;
|
||||
|
||||
|
||||
|
||||
#define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x //<2F>궨<EFBFBD><EAB6A8>SOFT_PARTICLE_NEAR_FADE <20><>Ϊ_SoftParticleFadeParams<6D><73><EFBFBD>Ե<EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>~
|
||||
#define SOFT_PARTICLE_INV_FADE_DISTANCE _SoftParticleFadeParams.y
|
||||
|
||||
#define CAMERA_NEAR_FADE _CameraFadeParams.x
|
||||
#define CAMERA_INV_FADE_DISTANCE _CameraFadeParams.y
|
||||
|
||||
Texture2D _BaseMap;
|
||||
Texture2D _NoiseMap;
|
||||
Texture2D _NoiseMaskMap;
|
||||
Texture2D _EmissionMap;
|
||||
Texture2D _MaskMap;
|
||||
Texture2D _MaskMap2;
|
||||
Texture2D _MaskMap3;
|
||||
|
||||
#ifdef _SCREEN_DISTORT_MODE
|
||||
Texture2D _ScreenColorCopy1;
|
||||
#endif
|
||||
|
||||
// Pre-multiplied alpha helper
|
||||
#if defined(_ALPHAPREMULTIPLY_ON) //if( blend: One OneMinusSrcAlpha)
|
||||
#define ALBEDO_MUL albedo
|
||||
#else
|
||||
#define ALBEDO_MUL albedo.a
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SOFT_UI_FRAME
|
||||
sampler2D _SoftUIFrameMask;
|
||||
// half4 LB_RT;
|
||||
#endif
|
||||
|
||||
#ifdef _DISSOLVE
|
||||
Texture2D _DissolveMap;
|
||||
Texture2D _DissolveMaskMap;
|
||||
Texture2D _DissolveRampMap;
|
||||
#endif
|
||||
|
||||
# ifdef _COLORMAPBLEND
|
||||
Texture2D _ColorBlendMap;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
half4 tex2D_TryLinearizeWithoutAlphaFX(sampler2D tex, float2 uv)
|
||||
{
|
||||
half4 outColor = 0;
|
||||
|
||||
#if defined(PARTICLE)//UI下使用ParticleBase不需要做 Gamma2Linear 转换
|
||||
UNITY_FLATTEN
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_UIEFFECT_ON))
|
||||
{
|
||||
outColor = tex2D(tex, uv);
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = TryLinearizeWithoutAlpha(tex2D(tex, uv));
|
||||
}
|
||||
#endif
|
||||
return outColor;
|
||||
}
|
||||
//
|
||||
// Color blending fragment function
|
||||
float4 MixParticleColor(float4 baseColor, float4 particleColor, float4 colorAddSubDiff)
|
||||
{
|
||||
#if defined(_COLOROVERLAY_ON) // Overlay blend
|
||||
float4 output = baseColor;
|
||||
output.rgb = lerp(1 - 2 * (1 - baseColor.rgb) * (1 - particleColor.rgb), 2 * baseColor.rgb * particleColor.rgb, step(baseColor.rgb, 0.5));
|
||||
output.a *= particleColor.a;
|
||||
return output;
|
||||
#elif defined(_COLORCOLOR_ON) // Color blend
|
||||
half3 aHSL = RgbToHsv(baseColor.rgb);
|
||||
half3 bHSL = RgbToHsv(particleColor.rgb);
|
||||
half3 rHSL = half3(bHSL.x, bHSL.y, aHSL.z);
|
||||
return half4(HsvToRgb(rHSL), baseColor.a * particleColor.a);
|
||||
#elif defined(_COLORADDSUBDIFF_ON) // Additive, Subtractive and Difference blends based on 'colorAddSubDiff'
|
||||
float4 output = baseColor;
|
||||
output.rgb = baseColor.rgb + particleColor.rgb * colorAddSubDiff.x;
|
||||
output.rgb = lerp(output.rgb, abs(output.rgb), colorAddSubDiff.y);
|
||||
output.a *= particleColor.a;
|
||||
return output;
|
||||
#else // Default to Multiply blend
|
||||
return baseColor * particleColor;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Soft particles - returns alpha value for fading particles based on the depth to the background pixel
|
||||
float SoftParticles(float near, float far, float sceneZ,float thisZ)
|
||||
{
|
||||
float fade = 1;
|
||||
if (near > 0.0 || far > 0.0)
|
||||
{
|
||||
// fade = saturate(far * ((sceneZ - near) - thisZ));
|
||||
float dist = sceneZ - thisZ;
|
||||
fade = NB_Remap(dist, near,far,0,1);
|
||||
}
|
||||
return fade;
|
||||
}
|
||||
|
||||
|
||||
// Camera fade - returns alpha value for fading particles based on camera distance
|
||||
half CameraFade(float near, float far, float thisZ)
|
||||
{
|
||||
return saturate((thisZ - near) * far);
|
||||
}
|
||||
|
||||
//相交位置渐变功能
|
||||
half4 Intersect(float IntersectRadius,half4 IntersectColor,float sceneZ,float thisZ)
|
||||
{
|
||||
half fade = sceneZ - thisZ;
|
||||
fade =1- NB_Remap(fade,0,IntersectRadius,0,1);
|
||||
|
||||
half4 c = 0;
|
||||
c.rgb = IntersectColor.rgb;
|
||||
c.a = fade*IntersectColor.a;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
//遮挡穿透显示功能。
|
||||
half OccludeOpacity(half preAlpha,half _OccludeOpacity,half sceneZ,half thisZ)
|
||||
{
|
||||
half fakeZtest = step(thisZ,sceneZ);
|
||||
return lerp(preAlpha*_OccludeOpacity,preAlpha,fakeZtest);
|
||||
}
|
||||
|
||||
|
||||
// Sample a texture and do blending for texture sheet animation if needed
|
||||
half4 BlendTexture(sampler2D _Texture, float2 uv, float3 blendUv)
|
||||
{
|
||||
half4 color = tex2D_TryLinearizeWithoutAlphaFX(_Texture, uv);
|
||||
|
||||
half4 color2;
|
||||
#ifdef _FLIPBOOKBLENDING_ON
|
||||
color2 = tex2D_TryLinearizeWithoutAlphaFX(_Texture, blendUv.xy);
|
||||
color = lerp(color, color2, blendUv.z);
|
||||
#endif
|
||||
|
||||
// if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER))
|
||||
// {
|
||||
// color2 = tex2D_TryLinearizeWithoutAlphaFX(_Texture, blendUv.xy);
|
||||
// color = lerp(color, color2, blendUv.z);
|
||||
// }
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 BlendTexture(Texture2D _Texture, float2 uv, float3 blendUv,uint bits)
|
||||
{
|
||||
half4 color = SampleTexture2DWithWrapFlags(_Texture,uv,bits);
|
||||
half4 color2;
|
||||
#ifdef _FLIPBOOKBLENDING_ON
|
||||
color2 = SampleTexture2DWithWrapFlags(_Texture,blendUv.xy,bits);
|
||||
color = lerp(color, color2, blendUv.z);
|
||||
#endif
|
||||
|
||||
// if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER))
|
||||
// {
|
||||
// color2 = SampleTexture2DWithWrapFlags(_Texture, blendUv.xy,bits);
|
||||
// color = lerp(color, color2, blendUv.z);
|
||||
// }
|
||||
return color;
|
||||
}
|
||||
|
||||
float2 UVOffsetAnimaiton(float2 UV,half2 OffsetSpeed)
|
||||
{
|
||||
float2 newUV = float2(OffsetSpeed.x*time+UV.x,OffsetSpeed.y*time+UV.y);
|
||||
return newUV;
|
||||
}
|
||||
|
||||
// 采样噪波
|
||||
half4 SampleNoise(half4 NoiseOffset, Texture2D _Texture,float2 UV, half3 wordPos)
|
||||
{
|
||||
|
||||
float2 UV2 = float2(NoiseOffset.x * time + UV.x, NoiseOffset.y * time + UV.y); //_Time.y
|
||||
|
||||
half4 color = SampleTexture2DWithWrapFlags(_Texture, UV2 ,FLAG_BIT_WRAPMODE_NOISEMAP);
|
||||
// color.xy *= color.a;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
// // 替换颜色
|
||||
// half3 ReplaceColor_float(float3 In, float3 From, float3 To, float Range, float Fuzziness)
|
||||
// {
|
||||
// float Distance = distance(From, In);
|
||||
// half3 Out = lerp(To, In, saturate((Distance - Range) / max(Fuzziness, 0.001))); //e-f? 0.00001
|
||||
// return Out;
|
||||
// }
|
||||
|
||||
//漩涡 圆形区域内变形。圆圈中心处的像素会旋转指定角度;圆圈中其他像素的旋转会随着相对于中心距离的变化而减小,在圆圈边缘处减小为零
|
||||
float2 UTwirl(float2 UV, float2 Center, float Strength)
|
||||
{
|
||||
float2 delta = UV - Center;
|
||||
float angle = Strength * length(delta);
|
||||
float x = cos(angle) * delta.x - sin(angle) * delta.y;
|
||||
float y = sin(angle) * delta.x + cos(angle) * delta.y;
|
||||
return float2(x + Center.x , y + Center.y );
|
||||
|
||||
}
|
||||
|
||||
//Fresnel
|
||||
half4 Unity_FresnelEffect(float3 Normal, float3 ViewDir, float Power, float Dire,half fresnelPos)
|
||||
{
|
||||
// half aa = saturate(dot(normalize(Normal), (ViewDir)));
|
||||
half aa = dot(normalize(Normal), (ViewDir));
|
||||
aa = (aa+1)*0.5;
|
||||
aa = NB_Remap(aa,fresnelPos,1,0,1);
|
||||
aa = lerp(aa, (1 - aa), Dire);
|
||||
half Out = pow( aa, Power);
|
||||
return Out;
|
||||
}
|
||||
|
||||
half3 Rotation(half3 normalizedDirection,half3 rotation)
|
||||
{
|
||||
half4 Dir = half4(normalizedDirection,1);
|
||||
float4x4 M_RotationX = float4x4(
|
||||
|
||||
1,0,0,0,
|
||||
0,cos(rotation.x),sin(rotation.x),0,
|
||||
0,-sin(rotation.x),cos(rotation.x),0,
|
||||
0,0,0,1
|
||||
|
||||
);
|
||||
float4x4 M_RotationY = float4x4(
|
||||
|
||||
cos(rotation.y),0,sin(rotation.y),0,
|
||||
0,1,0,0,
|
||||
-sin(rotation.y),0,cos(rotation.y),0,
|
||||
0,0,0,1
|
||||
|
||||
);
|
||||
float4x4 M_RotationZ = float4x4(
|
||||
|
||||
cos(rotation.z),sin(rotation.z),0,0,
|
||||
-sin(rotation.z),cos(rotation.z),0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1
|
||||
|
||||
);
|
||||
|
||||
return mul(M_RotationZ,mul(M_RotationY,mul(M_RotationX,Dir)));
|
||||
|
||||
}
|
||||
|
||||
//----------------公告板功能-----------------//
|
||||
half3 BillBoard(float3 camPos, float3 vertexPos, int billboardType, int _ReverseZ)
|
||||
{
|
||||
float3 Z = normalize(mul(unity_WorldToObject, float4(_WorldSpaceCameraPos,1)));
|
||||
if(_ReverseZ == 1)
|
||||
{
|
||||
Z *= -1;
|
||||
}
|
||||
Z.y *= billboardType;
|
||||
|
||||
float3 Y = float3(0,1,0);
|
||||
float3 X = normalize(cross(Z,Y));
|
||||
Y = normalize(cross(X,Z));
|
||||
float4x4 M = float4x4(
|
||||
X.x, Y.x, Z.x, 0,
|
||||
X.y, Y.y, Z.y, 0,
|
||||
X.z, Y.z, Z.z, 0,
|
||||
0,0,0,1
|
||||
);
|
||||
float3 newPos = mul(M, vertexPos);
|
||||
return newPos;
|
||||
}
|
||||
|
||||
half3 BillBoardNormal(float3 camPos, float3 vertexPos, int billboardType, int _ReverseZ)
|
||||
{
|
||||
float3 Z = normalize(mul(unity_WorldToObject, float4(_WorldSpaceCameraPos,1)));
|
||||
if(_ReverseZ == 1)
|
||||
{
|
||||
Z *= -1;
|
||||
}
|
||||
Z.y *= billboardType;
|
||||
|
||||
float3 Y = float3(0,1,0);
|
||||
float3 X = normalize(cross(Y,Z));
|
||||
Y = normalize(cross(X,Z));
|
||||
float4x4 M = float4x4(
|
||||
X.x, Y.x, Z.x, 0,
|
||||
X.y, Y.y, Z.y, 0,
|
||||
X.z, Y.z, Z.z, 0,
|
||||
0,0,0,1
|
||||
);
|
||||
float3 newPos = -mul(M, vertexPos);
|
||||
return newPos;
|
||||
}
|
||||
|
||||
|
||||
float2 ParticleUVCommonProcess(float2 originUVAfterTwirlPolar,float4 scaleTilling,float2 offset = float2(0,0),float rotation = 0,float2 rotationCenter = float2(0.5,0.5))
|
||||
{
|
||||
float2 uv = originUVAfterTwirlPolar;
|
||||
uv = Rotate_Radians_float(uv,rotationCenter,rotation);
|
||||
uv = uv*scaleTilling.xy + scaleTilling.zw;
|
||||
|
||||
uv = UVOffsetAnimaiton(uv,offset);
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
struct ParticleUVs
|
||||
{
|
||||
float2 mainTexUV;
|
||||
float2 specUV;
|
||||
float2 animBlendUV;
|
||||
float2 maskMapUV;
|
||||
float2 maskMap2UV;
|
||||
float2 maskMap3UV;
|
||||
float2 emissionUV;
|
||||
float2 dissolve_uv;
|
||||
float2 dissolve_mask_uv;
|
||||
float2 dissolve_noise1_UV;
|
||||
float2 dissolve_noise2_UV;
|
||||
float2 colorBlendUV;
|
||||
float2 noiseMapUV;
|
||||
float2 noiseMaskMapUV;
|
||||
};
|
||||
|
||||
BaseUVs ProcessBaseUVs(float4 meshTexcoord0, float2 specialUVInTexcoord3,float4 VaryingsP_Custom1,float4 VaryingsP_Custom2,float3 postionOS)
|
||||
{
|
||||
//UV2的内容在外边就决定好。
|
||||
float2 defaultUVChannel = meshTexcoord0.xy;
|
||||
float2 specialUVChannel = meshTexcoord0.zw;
|
||||
#if _FLIPBOOKBLENDING_ON
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_IS_PARTICLE_SYSTEM) & CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD2))
|
||||
{
|
||||
specialUVChannel = specialUVInTexcoord3;
|
||||
}
|
||||
#else
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_UV_FROM_MESH))
|
||||
{
|
||||
//Mesh条件下开启使用特殊UV通道的情况
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD1))
|
||||
{
|
||||
specialUVChannel = VaryingsP_Custom1.xy;
|
||||
}
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_USE_TEXCOORD2))
|
||||
{
|
||||
specialUVChannel = VaryingsP_Custom2.xy;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//只有在粒子系统下开启特殊通道的情况,会在面板层引导合并相关内容。UI/Mesh不开启特殊通道没有意义。
|
||||
specialUVChannel = meshTexcoord0.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE))
|
||||
{
|
||||
defaultUVChannel = defaultUVChannel*_MainTex_Reverse_ST.xy +_MainTex_Reverse_ST.zw;
|
||||
}
|
||||
//TODO:补写MeshUV的实现
|
||||
float2 cylinderUV = meshTexcoord0.xy;
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_CYLINDER_CORDINATE))
|
||||
{
|
||||
float4x4 _CylinderUVMatrix = float4x4(_CylinderMatrix0,_CylinderMatrix1,_CylinderMatrix2,_CylinderMatrix3);
|
||||
postionOS = mul(_CylinderUVMatrix,float4(postionOS,1));
|
||||
cylinderUV = CylinderCoordinate(postionOS);
|
||||
}
|
||||
|
||||
float2 UVAfterTwirlPolar = defaultUVChannel;
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_UTWIRL_ON))
|
||||
{
|
||||
UVAfterTwirlPolar = UTwirl(defaultUVChannel,_TWParameter.xy, _TWStrength);
|
||||
}
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_POLARCOORDINATES_ON))
|
||||
{
|
||||
float2 UVAfterTwirl = UVAfterTwirlPolar;
|
||||
UVAfterTwirlPolar = PolarCoordinates(UVAfterTwirlPolar,_PCCenter.xy);
|
||||
UVAfterTwirlPolar = lerp(UVAfterTwirl,UVAfterTwirlPolar,_PCCenter.z);
|
||||
}
|
||||
BaseUVs baseUVs = (BaseUVs)0;
|
||||
baseUVs.defaultUVChannel = defaultUVChannel;
|
||||
baseUVs.specialUVChannel = specialUVChannel;
|
||||
baseUVs.uvAfterTwirlPolar = UVAfterTwirlPolar;
|
||||
baseUVs.cylinderUV = cylinderUV;
|
||||
return baseUVs;
|
||||
}
|
||||
|
||||
void ParticleProcessUV(float4 meshTexcoord0, float2 specialUVInTexcoord3,inout ParticleUVs particleUVs,float4 VaryingsP_Custom1,float4 VaryingsP_Custom2,float2 screenUV,float3 postionOS)
|
||||
{
|
||||
BaseUVs baseUVs= ProcessBaseUVs(meshTexcoord0,specialUVInTexcoord3,VaryingsP_Custom1,VaryingsP_Custom2,postionOS);
|
||||
|
||||
particleUVs.specUV = baseUVs.specialUVChannel;
|
||||
float2 baseMapUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_MAINTEX,baseUVs);
|
||||
|
||||
#ifdef _FLIPBOOKBLENDING_ON //开启序列帧融合
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_ANIMATION_SHEET_HELPER))
|
||||
{
|
||||
//走AnimationSheetHelper脚本的情况,永远和baseMap同步。
|
||||
particleUVs.animBlendUV = baseMapUV*_BaseMap_AnimationSheetBlend_ST.xy+_BaseMap_AnimationSheetBlend_ST.zw;
|
||||
}
|
||||
else
|
||||
{
|
||||
//走粒子的情况
|
||||
particleUVs.animBlendUV = meshTexcoord0.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _SCREEN_DISTORT_MODE
|
||||
particleUVs.mainTexUV = screenUV;
|
||||
#else
|
||||
baseMapUV = Rotate_Radians_float(baseMapUV, half2(0.5, 0.5), _BaseMapUVRotation); //主贴图旋转
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_UIEFFECT_ON) & !CheckLocalFlags1(FLAG_BIT_PARTICLE_1_UIEFFECT_BASEMAP_MODE))
|
||||
{
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_UIEFFECT_SPRITE_MODE))
|
||||
{
|
||||
float2 originUV = meshTexcoord0.xy;//精灵主贴图不调整。
|
||||
particleUVs.mainTexUV = originUV*_UI_MainTex_ST.xy+_UI_MainTex_ST.zw;
|
||||
}
|
||||
else
|
||||
{
|
||||
particleUVs.mainTexUV = baseMapUV*_UI_MainTex_ST.xy+_UI_MainTex_ST.zw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
baseMapUV.x += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_X,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
baseMapUV.y += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_MAINTEX_OFFSET_Y,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
particleUVs.mainTexUV = TRANSFORM_TEX(baseMapUV, _BaseMap); //主帖图UV重复和偏移
|
||||
}
|
||||
particleUVs.mainTexUV = UVOffsetAnimaiton(particleUVs.mainTexUV,_BaseMapMaskMapOffset.xy);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MASKMAP_ON)
|
||||
|
||||
float2 MaskMapuv = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_MASKMAP,baseUVs);
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTILCE_MASKMAPROTATIONANIMATION_ON))
|
||||
{
|
||||
_MaskMapUVRotation += time * _MaskMapRotationSpeed;
|
||||
}
|
||||
|
||||
MaskMapuv= Rotate_Radians_float(MaskMapuv, half2(0.5, 0.5), _MaskMapUVRotation);
|
||||
|
||||
MaskMapuv = TRANSFORM_TEX(MaskMapuv, _MaskMap);
|
||||
|
||||
MaskMapuv.x += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_X,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
MaskMapuv.y += GetCustomData(_W9ParticleCustomDataFlag0,FLAGBIT_POS_0_CUSTOMDATA_MASK_OFFSET_Y,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
|
||||
MaskMapuv = UVOffsetAnimaiton(MaskMapuv,_MaskMapOffsetAnition.xy);
|
||||
particleUVs.maskMapUV = MaskMapuv;
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MASK_MAP2))
|
||||
{
|
||||
float2 maskMap2UV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_MASKMAP_2,baseUVs);
|
||||
maskMap2UV = maskMap2UV * _MaskMap2_ST.xy + _MaskMap2_ST.zw;
|
||||
|
||||
maskMap2UV = UVOffsetAnimaiton(maskMap2UV,_MaskMapOffsetAnition.zw);
|
||||
particleUVs.maskMap2UV = maskMap2UV;
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_MASK_MAP3))
|
||||
{
|
||||
float2 maskMap3UV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_MASKMAP_3,baseUVs);
|
||||
maskMap3UV = maskMap3UV* _MaskMap3_ST.xy + _MaskMap3_ST.zw;
|
||||
|
||||
maskMap3UV = UVOffsetAnimaiton(maskMap3UV,_MaskMap3OffsetAnition.xy);
|
||||
particleUVs.maskMap3UV = maskMap3UV;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_EMISSION)
|
||||
float2 emissionUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_EMISSION_MAP,baseUVs);
|
||||
particleUVs.emissionUV = ParticleUVCommonProcess(emissionUV,_EmissionMap_ST,_EmissionMapUVOffset.xy,_EmissionMapUVRotation);
|
||||
#endif
|
||||
|
||||
#if defined(_DISSOLVE)
|
||||
// if(CheckLocalFlags1(FLAG_BIT_PARTICLE_CUSTOMDATA1X_DISSOLVETEXOFFSETX))
|
||||
// {
|
||||
// _DissolveMap_ST.z += VaryingsP_Custom1.x;
|
||||
// }
|
||||
// if(CheckLocalFlags1(FLAG_BIT_PARTICLE_CUSTOMDATA1Y_DISSOLVETEXOFFSETY))
|
||||
// {
|
||||
// _DissolveMap_ST.w += VaryingsP_Custom1.y;
|
||||
// }
|
||||
_DissolveMap_ST.z += GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_X,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
_DissolveMap_ST.w += GetCustomData(_W9ParticleCustomDataFlag1,FLAGBIT_POS_1_CUSTOMDATA_DISSOLVE_OFFSET_Y,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
|
||||
float2 dissolveUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_DISSOLVE_MAP,baseUVs);
|
||||
particleUVs.dissolve_uv = ParticleUVCommonProcess(dissolveUV,_DissolveMap_ST,_DissolveOffsetRotateDistort.xy,_DissolveOffsetRotateDistort.z);
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_DISSOLVE_MASK))
|
||||
{
|
||||
float2 dissolveMaskUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_DISSOLVE_MASK_MAP,baseUVs);
|
||||
particleUVs.dissolve_mask_uv = ParticleUVCommonProcess(dissolveMaskUV,_DissolveMaskMap_ST,float2(0,0),_DissolveOffsetRotateDistort.z);
|
||||
}
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DISSOVLE_VORONOI))
|
||||
{
|
||||
float2 halfUV = dissolveUV;
|
||||
// halfUV.x = abs(halfUV.x-0.5);//20240729不明白当时为什么要做这个ABS处理。先注销掉看看。
|
||||
_DissolveVoronoi_Vec4.x += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_X,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
_DissolveVoronoi_Vec4.y += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE1_OFFSET_Y,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
_DissolveVoronoi_Vec4.z += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_X,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
_DissolveVoronoi_Vec4.w += GetCustomData(_W9ParticleCustomDataFlag2,FLAGBIT_POS_2_CUSTOMDATA_DISSOLVE_NOISE2_OFFSET_Y,0,VaryingsP_Custom1,VaryingsP_Custom2);
|
||||
particleUVs.dissolve_noise1_UV = halfUV * _DissolveVoronoi_Vec.xy + _DissolveVoronoi_Vec4.xy + time*_DissolveVoronoi_Vec3.xy;
|
||||
particleUVs.dissolve_noise2_UV = halfUV * _DissolveVoronoi_Vec.zw + _DissolveVoronoi_Vec4.zw + time*_DissolveVoronoi_Vec3.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _COLORMAPBLEND
|
||||
float2 colorBlendUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_COLOR_BLEND_MAP,baseUVs);
|
||||
particleUVs.colorBlendUV = ParticleUVCommonProcess(colorBlendUV,_ColorBlendMap_ST,_ColorBlendMapOffset.xy);
|
||||
#endif
|
||||
|
||||
half cum_noise = 0;
|
||||
|
||||
//TODO
|
||||
|
||||
#if defined(_NOISEMAP)
|
||||
|
||||
//和ParticleUVCommonProcess相比,此处没有UV动画,NoiseMap的UV流动在最终的SampleNoise中进行
|
||||
float2 noiseMapUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_NOISE_MAP,baseUVs);
|
||||
particleUVs.noiseMapUV = ParticleUVCommonProcess(noiseMapUV,_NoiseMap_ST,half2(0,0),_NoiseMapUVRotation);
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_NOISE_MASKMAP))
|
||||
{
|
||||
float2 noiseMaskMapUV = GetUVByUVMode(_UVModeFlag0,FLAG_BIT_UVMODE_POS_0_NOISE_MASK_MAP,baseUVs);
|
||||
particleUVs.noiseMaskMapUV = ParticleUVCommonProcess(noiseMaskMapUV,_NoiseMaskMap_ST,half2(0,0),0);
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Texture2D _VertexOffset_Map;
|
||||
Texture2D _VertexOffset_MaskMap;
|
||||
|
||||
// half3 _VertexOffset_Vec;
|
||||
// half3 _VertexOffset_CustomDir;
|
||||
// half4 _VertexOffset_Map_ST;
|
||||
|
||||
half3 VetexOffset(half3 positionOS,half2 originUV,half2 originMaskUV,half3 normalOS)
|
||||
{
|
||||
half2 uv = TRANSFORM_TEX(originUV,_VertexOffset_Map);
|
||||
uv = UVOffsetAnimaiton(uv,_VertexOffset_Vec.xy);
|
||||
// half vertexOffsetSample = tex2Dlod(_VertexOffset_Map,half4(uv,0,0));
|
||||
half vertexOffsetSample = SampleTexture2DWithWrapFlags(_VertexOffset_Map,uv,FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP,true,0);
|
||||
// UNITY_BRANCH
|
||||
// if(CheckLocalWrapFlags(FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP))
|
||||
// {
|
||||
// vertexOffsetSample = SAMPLE_TEXTURE2D_LOD(_VertexOffset_Map,sampler_linear_clamp,uv,0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vertexOffsetSample = SAMPLE_TEXTURE2D_LOD(_VertexOffset_Map,sampler_linear_repeat,uv,0);
|
||||
// }
|
||||
|
||||
if (!CheckLocalFlags1(FLAG_BIT_PARTICLE_1_VERTEXOFFSET_START_FROM_ZERO))
|
||||
{
|
||||
vertexOffsetSample = vertexOffsetSample*2-1;
|
||||
}
|
||||
|
||||
half3 finalPos;
|
||||
half vertexOffsetMask = 1;
|
||||
if (CheckLocalFlags1(FLAG_BIT_PARTICLE_1_VERTEXOFFSET_MASKMAP))
|
||||
{
|
||||
half2 maskUV = TRANSFORM_TEX(originMaskUV,_VertexOffset_MaskMap);
|
||||
maskUV = UVOffsetAnimaiton(maskUV,_VertexOffset_MaskMap_Vec.xy);
|
||||
half vertexOffsetMaskSample = SampleTexture2DWithWrapFlags(_VertexOffset_MaskMap,maskUV,FLAG_BIT_WRAPMODE_VERTEXOFFSET_MASKMAP,true,0);
|
||||
vertexOffsetMask = lerp(1,vertexOffsetMaskSample,_VertexOffset_MaskMap_Vec.z);
|
||||
}
|
||||
|
||||
UNITY_BRANCH
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_VERTEX_OFFSET_NORMAL_DIR))
|
||||
{
|
||||
finalPos = positionOS + normalOS*_VertexOffset_Vec.z*vertexOffsetSample*vertexOffsetMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
finalPos = positionOS + _VertexOffset_CustomDir*_VertexOffset_Vec.z*vertexOffsetSample*vertexOffsetMask;
|
||||
}
|
||||
|
||||
|
||||
return finalPos;
|
||||
|
||||
}
|
||||
|
||||
//向UV横向两边的色散。
|
||||
half4 DistortionChoraticaberrat(Texture2D baseTexture,half2 originUV, half2 uvAfterNoise,half ChoraticaberratIntensity,uint bits)
|
||||
{
|
||||
half2 delta = half2(originUV.x *2-1,0);
|
||||
|
||||
if(CheckLocalFlags(FLAG_BIT_PARTICLE_NOISE_CHORATICABERRAT_WITH_NOISE))
|
||||
{
|
||||
half2 NoiseIntensity = uvAfterNoise - originUV;
|
||||
half noiseXIntensity = abs(NoiseIntensity.x);
|
||||
delta *= ChoraticaberratIntensity*noiseXIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta *= ChoraticaberratIntensity;
|
||||
}
|
||||
|
||||
half2 ra = SampleTexture2DWithWrapFlags(baseTexture,uvAfterNoise,bits).xw;
|
||||
ra.r *= ra.y;
|
||||
half2 ga = SampleTexture2DWithWrapFlags(baseTexture,uvAfterNoise - delta,bits).yw;
|
||||
ga.r *= ga.y;
|
||||
half2 ba = SampleTexture2DWithWrapFlags(baseTexture,uvAfterNoise - delta*2,bits).zw;
|
||||
ba.r *= ba.y;
|
||||
return half4(ra.r,ga.r,ba.r,clamp(ra.y*0.5+ga.y*0.5+ba.y*0.5,0,1));
|
||||
}
|
||||
|
||||
bool needSceneDepth()
|
||||
{
|
||||
#if defined(_DEPTH_DECAL) || defined(_SOFTPARTICLES_ON)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool needEyeDepth()
|
||||
{
|
||||
#if defined(_SOFTPARTICLES_ON)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if(CheckLocalFlags1(FLAG_BIT_PARTICLE_1_DEPTH_OUTLINE)||CheckLocalFlags(FLAG_BIT_PARTICLE_DISTANCEFADE_ON))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ignoreFresnel()
|
||||
{
|
||||
#if defined(PARTICLE_BACKFACE_PASS)
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
Texture2D _ParallaxMapping_Map;
|
||||
|
||||
half2 ParallaxMappingSimple(half2 texCoords, half3 viewDir)
|
||||
{
|
||||
float height = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map,texCoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r;
|
||||
height *= _ParallaxMapping_Intensity;
|
||||
viewDir = normalize(viewDir);
|
||||
viewDir.xy /= (viewDir.z);
|
||||
texCoords -= viewDir.xy * height;
|
||||
return texCoords;
|
||||
}
|
||||
|
||||
half2 ParallaxMappingPeelDepth(half2 texCoords, half3 viewDir)
|
||||
{
|
||||
const float minLayers = 2;
|
||||
const float maxLayers = 32;
|
||||
float numLayers = lerp(maxLayers, minLayers, abs(dot(half3(0.0, 0.0, 1.0), viewDir)));//视线越垂直于表面,层数越少,反之越多。
|
||||
float layerDepth = 1/numLayers;
|
||||
float currentLayerDepth = 0;
|
||||
// viewDir.xy/=viewDir.z;
|
||||
half2 p = viewDir.xy*_ParallaxMapping_Intensity;
|
||||
half2 deltaTexcoord = p/numLayers;
|
||||
|
||||
half2 currentTexcoords = texCoords;
|
||||
float currentMapDepthValue = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map,currentTexcoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r;
|
||||
|
||||
[loop]
|
||||
while (currentLayerDepth < currentMapDepthValue )
|
||||
{
|
||||
currentTexcoords -= deltaTexcoord;
|
||||
currentMapDepthValue = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map,currentTexcoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r;
|
||||
currentLayerDepth += layerDepth;
|
||||
}
|
||||
|
||||
return currentTexcoords;
|
||||
|
||||
}
|
||||
half2 ParallaxOcclusionMapping(half2 texCoords, half3 viewDir)
|
||||
{
|
||||
// number of depth layers
|
||||
// const float minLayers = 10;
|
||||
// const float maxLayers = 10;
|
||||
const float minLayers = _ParallaxMapping_Vec.x;
|
||||
const float maxLayers = _ParallaxMapping_Vec.y;
|
||||
float numLayers = lerp(maxLayers, minLayers, abs(dot(half3(0.0, 0.0, 1.0), viewDir)));
|
||||
// calculate the size of each layer
|
||||
float layerDepth = 1.0 / numLayers;
|
||||
// depth of current layer
|
||||
float currentLayerDepth = 0.0;
|
||||
// the amount to shift the texture coordinates per layer (from vector P)
|
||||
half2 P = viewDir.xy / viewDir.z * _ParallaxMapping_Intensity;
|
||||
half2 deltaTexCoords = P / numLayers;
|
||||
|
||||
// get initial values
|
||||
half2 currentTexCoords = texCoords;
|
||||
float currentDepthMapValue = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map, currentTexCoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r;
|
||||
currentLayerDepth = clamp(currentLayerDepth,0,1);
|
||||
|
||||
int i = 0;
|
||||
[loop]
|
||||
while(currentLayerDepth < currentDepthMapValue && i<numLayers)
|
||||
{
|
||||
// shift texture coordinates along direction of P
|
||||
currentTexCoords -= deltaTexCoords;
|
||||
// get depthmap value at current texture coordinates
|
||||
currentDepthMapValue = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map, currentTexCoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r;
|
||||
// get depth of next layer
|
||||
currentLayerDepth += layerDepth;
|
||||
i++;
|
||||
}
|
||||
|
||||
// -- parallax occlusion mapping interpolation from here on
|
||||
// get texture coordinates before collision (reverse operations)
|
||||
half2 prevTexCoords = currentTexCoords + deltaTexCoords;
|
||||
|
||||
// get depth after and before collision for linear interpolation
|
||||
float afterDepth = currentDepthMapValue - currentLayerDepth;
|
||||
float beforeDepth = SampleTexture2DWithWrapFlags(_ParallaxMapping_Map, prevTexCoords,FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP).r - currentLayerDepth + layerDepth;
|
||||
|
||||
// interpolation of texture coordinates
|
||||
float weight = afterDepth / (afterDepth - beforeDepth);
|
||||
half2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
|
||||
|
||||
return finalTexCoords;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03da5256bb8bf0b4496b10ee6b449be4
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
512
Packages/NBShaders/Shader/ParticleBase.shader
Normal file
512
Packages/NBShaders/Shader/ParticleBase.shader
Normal file
@@ -0,0 +1,512 @@
|
||||
Shader "Effects/NBShader"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MeshSourceMode("Mesh来源模式",Float) = 0
|
||||
_UIEffect_Toggle("UI模式_Toggle",Float) = 0
|
||||
_DistortionBothDirection_Toggle("__DistortionBothDirection_Toggle",Float) = 0
|
||||
_DistanceFade_Toggle("_DistanceFade_Toggle",Float) = 0
|
||||
_ChangeSaturability_Toggle("__ChangeSaturability_Toggle",Float) = 0
|
||||
_Mask_Toggle("__Mask_Toggle",Float) = 0
|
||||
_Mask_RotationToggle("__Mask_RotationToggle",Float) = 0
|
||||
_Mask2_Toggle("__Mask2_Toggle",Float) = 0
|
||||
_Mask3_Toggle("__Mask3_Toggle",Float) = 0
|
||||
_BaseBackColor_Toggle("__BaseBackColor_Toggle",Float) = 0
|
||||
_UseUV1_Toggle("__UseUV1_Toggle",Float) = 0
|
||||
_TransparentMode("_TransparentMode",Float) = 1
|
||||
_ForceZWriteToggle("_ForceZWriteToggle",Float) = 0
|
||||
|
||||
_Dissolve_Toggle("__Dissolve_Toggle",Float) = 0
|
||||
_DissolveMask_Toggle("__DissolveMask_Toggle",Float) = 0
|
||||
_DissolveVoronoi_Toggle("__DissolveVoronoi_Toggle",Float) = 0
|
||||
_Dissolve_useRampMap_Toggle("__Dissolve_useRampMap_Toggle",Float) = 0
|
||||
_Dissolve_Test_Toggle("__Dissolve_Test_Toggle",Float) = 0
|
||||
|
||||
|
||||
_ColorBlendMap_Toggle("__ColorBlendMap_Toggle",Float) = 0
|
||||
_FresnelMode("__FresnelMode",Float) = 0
|
||||
_InvertFresnel_Toggle("__InvertFresnel_Toggle",Float) = 0
|
||||
_HueShift_Toggle("__HueShift_Toggle",Float) = 0
|
||||
_BackFaceColor_Toggle("_BackFaceColor_Toggle",Float) = 0
|
||||
_BackFristPassToggle("_BackFirstPassToggle",Float) = 0
|
||||
|
||||
_PolarCordinateOnlySpecialFunciton_Toggle("极坐标仅对特殊功能生效_Toggle",Float) = 0
|
||||
|
||||
_CustomData1X_MainTexOffsetX_Toggle("_CustomData1X_MainTexOffsetX_Toggle",Float) = 0
|
||||
_CustomData1Y_MainTexOffsetY_Toggle("_CustomData1Y_MainTexOffsetY_Toggle",Float) = 0
|
||||
_CustomData1Z_Dissolve_Toggle("_CustomData1Z_Dissolve_Toggle",Float) = 0
|
||||
_CustomData1W_HueShift_Toggle("_CustomData1W_HueShift_Toggle",Float) = 0
|
||||
_CustomData2X_MaskMapOffsetX_Toggle("_CustomData2X_MaskMapOffsetX_Toggle",Float) = 0
|
||||
_CustomData2Y_MaskMapOffsetY_Toggle("_CustomData2Y_MaskMapOffsetY_Toggle",Float) = 0
|
||||
_CustomData2Z_FresnelOffset_Toggle("_CustomData2Z_FresnelOffset_Toggle",Float) = 0
|
||||
_CustomData2W_Toggle("_CustomData2W_Toggle",Float) = 0
|
||||
|
||||
// [PerRendererData] [MainTexture] _MainTex("Sprite Texture-ignore", 2D) = "white" {}
|
||||
[PerRendererData] _MainTex ("Sprite Texture-ignore", 2D) = "white" {}
|
||||
_Color("颜色贴图叠加", Color) = (1,1,1,1)
|
||||
_UI_MainTex_ST("UI模式主贴图 xy:UV缩放 zw:UV偏移",vector) = (1,1,0,0)
|
||||
_MainTex_Reverse_ST("MainTex_Reverse_ST-ignore",Vector) = (1,1,0,0)
|
||||
|
||||
_BaseMap ("主贴图 xy:UV缩放 zw:UV偏移", 2D) = "white" { }
|
||||
_BaseMapMaskMapOffset ("xy主贴图偏移速度", vector) = (0, 0, 0, 0)
|
||||
|
||||
_BaseMapUVRotation ("主贴图旋转", Range(0, 360)) = 0
|
||||
[HDR]_BaseColor ("主贴图颜色_hdr", Color) = (1, 1, 1, 1)//HDR颜色不需要做Gamma Linear转换,Unity默认用Linear颜色
|
||||
// _BaseColor ("Base Color", Color) = (1, 1, 1, 1)//HDR颜色不需要做Gamma Linear转换,Unity默认用Linear颜色
|
||||
[HDR]_BaseBackColor ("背面颜色_hdr", Color) = (1, 1, 1, 1)//HDR颜色不需要做Gamma Linear转换,Unity默认用Linear颜色
|
||||
_BaseColorIntensityForTimeline("整体颜色强度", Range(0,10)) = 1 //独立出来是以为Timeline K颜色的时候会很奇怪的影响色相
|
||||
_Saturability("饱和度", range(0,1)) = 0
|
||||
_Contrast_Toggle("__Contrast_Toggle",Float) = 0
|
||||
_Contrast("对比度", Float) = 1
|
||||
_ContrastMidColor ("对比度中值颜色", Color) = (0.5, 0.5, 0.5, 1)//HDR颜色不需要做Gamma Linear转换,Unity默认用Linear颜色
|
||||
_HueShift("色相",Range(0,1)) = 0
|
||||
_BaseMapColorRefine_Toggle ("__BaseMapColorRefine_Toggle",Float) = 0
|
||||
_BaseMapColorRefine("主贴图颜色Refine",Vector) = (1,1,2,1)
|
||||
_AlphaAll("整体透明度",Range(0,1)) = 1
|
||||
_IgnoreVetexColor_Toggle("_IgnoreVetexColor_Toggle",Float) = 0
|
||||
|
||||
_SpecialUVChannelMode("特殊UV通道选择",Float) = 0
|
||||
|
||||
_CylinderUVRotate("圆柱UV旋转",Vector) = (0,0,90,0)
|
||||
_CylinderUVPosOffset("圆柱UV位置偏移",Vector) = (0,0,0,0)
|
||||
_CylinderMatrix0("圆柱偏移矩阵0",Vector) = (0,0,0,0)
|
||||
_CylinderMatrix1("圆柱偏移矩阵1",Vector) = (0,0,0,0)
|
||||
_CylinderMatrix2("圆柱偏移矩阵2",Vector) = (0,0,0,0)
|
||||
_CylinderMatrix3("圆柱偏移矩阵3",Vector) = (0,0,0,0)
|
||||
|
||||
_Cutoff ("裁剪位置", float) = 0
|
||||
|
||||
//时间缩放影响开关----------
|
||||
[HideInInspector] _TimeMode("__TimeMode",float) = 0.0
|
||||
|
||||
|
||||
// MaskMap------------
|
||||
_MaskMap ("遮罩贴图 xy:UV缩放 zw:UV偏移", 2D) = "white" { }
|
||||
_MaskMap2 ("遮罩2贴图 xy:UV缩放 zw:UV偏移", 2D) = "white"{}
|
||||
_MaskMap3 ("遮罩3贴图 xy:UV缩放 zw:UV偏移", 2D) = "white"{}
|
||||
_MaskMapOffsetAnition("xy:遮罩偏移速度,zw:遮罩2偏移速度", vector) = (0,0,0,0)
|
||||
_MaskMap3OffsetAnition("xy:遮罩3偏移速度", vector) = (0,0,0,0)
|
||||
_MaskMapUVRotation ("遮罩旋转", Range(0, 360)) = 0.0
|
||||
_MaskDistortion_intensity ("遮罩扭曲强度", float) = 0.0
|
||||
_MaskMapRotationSpeed("遮罩旋转速度", float) = 0.0
|
||||
_MaskMapVec("x整体遮罩强度",Vector) = (1,0,0,0)
|
||||
|
||||
// 擦除----------------
|
||||
//[Header(ChaChu(Anima For CustomData.z).......)]
|
||||
//[KeywordEnum(NoChange,XianXing, JingXiang, Self)] _ch ("ChaChu mode", Float) = 0
|
||||
[HideInInspector] _Chachu ("__Chachu_ignore", Float) = 0.0
|
||||
_EdgeFade ("EdgeFade_ignore", Range(0, 1)) = 0.05
|
||||
_XianXingCH_UVRota ("XianXingCH_UVRota_ignore", float) = 0
|
||||
_jingxiangCH_dire ("Direction_ignore", Range(0, 1)) = 0
|
||||
|
||||
// 漩涡 -------------------
|
||||
//[Toggle(_JIZUOBIAO)] _N121 ("JIZUOBIAO?", float) = 0
|
||||
[HideInInspector] _UTwirlEnabled ("__UTwirlEnabled", Float) = 0.0
|
||||
_TWParameter ("xy:旋转扭曲中心", vector) = (0.5, 0.5, 0, 0)
|
||||
_TWStrength ("旋转扭曲强度", float) = 0
|
||||
|
||||
|
||||
// 极坐标 -------------------
|
||||
//[Toggle(_JIZUOBIAO)] _N121 ("JIZUOBIAO?", float) = 0
|
||||
[HideInInspector]_PolarCoordinatesEnabled ("__PolarCoordinatesEnabled", Float) = 0.0
|
||||
_PCCenter ("xy:极坐标中心 z:极坐标强度", vector) = (0.5, 0.5, 1, 0)//位置坐标用的前两个分量,z分量给强度。
|
||||
|
||||
|
||||
// 噪波 --------------
|
||||
//[Toggle(_NOISEMAP)]_N ("NOISEMAP?", float) =0
|
||||
[HideInInspector] _noisemapEnabled ("__noisemapEnabled", Float) = 0.0
|
||||
[HideInInspector] _noiseMaskMap_Toggle ("__noiseMaskMap_Toggle", Float) = 0.0
|
||||
_NoiseMap ("扭曲贴图 xy:UV缩放 zw:UV偏移", 2D) = "white" { }
|
||||
_NoiseMaskMap ("扭曲遮罩贴图 xy:UV缩放 zw:UV偏移", 2D) = "white" { }
|
||||
_NoiseMapUVRotation("扭曲旋转",Range(0,360)) = 0
|
||||
_NoiseOffset ("xy:扭曲偏移速度 ", vector) = (0, 0, 0, 0)//w分量为本地uv坐标到世界坐标的变化
|
||||
_TexDistortion_intensity ("扭曲强度", float) = 0.5
|
||||
_DistortionDirection ("扭曲方向xy, 色散强度z", vector) = (1,1,0,0)
|
||||
_Distortion_Choraticaberrat_Toggle("扭曲色散开关_Toggle",Float) = 0
|
||||
_Distortion_Choraticaberrat_WithNoise_Toggle("色散受扭曲影响_Toggle",Float) = 1
|
||||
|
||||
|
||||
|
||||
// 流光 ----------
|
||||
//[Header(LiuGuang(Anima For CustomData.w).......)]
|
||||
//[Toggle(_EMISSION)]_N1 ("EMISSION?", float) = 0
|
||||
[HideInInspector] _EmissionEnabled ("__EmissionEnabled", Float) = 0.0
|
||||
_EmissionMap ("流光贴图 xy:UV缩放 zw:UV偏移", 2D) = "white" { }
|
||||
_EmissionMapUVRotation ("流光贴图旋转", Range(0, 360)) = 0
|
||||
_Emi_Distortion_intensity ("流光贴图扭转强度", float) = 0
|
||||
_EmissionMapUVOffset ("xy:流光贴图偏移速度", vector) = (0, 0, 0, 0)
|
||||
_EmissionSelfAlphaWeight ("__EmissionSelfAlphaWeight_ignore", float) = 0
|
||||
_uvRapSoft ("LiuuvRapSoft-ignore", Range(0, 1)) = 0
|
||||
[HDR]_EmissionMapColor ("流光贴图颜色_hdr", Color) = (1, 1, 1, 1)
|
||||
_EmissionMapColorIntensity("流光颜色强度", float) = 1
|
||||
|
||||
// Rongjie ------------------
|
||||
// [Header(RongJie(Anima For CustomData.y).......)]
|
||||
// [Toggle(_DISSOLVE)]_RJ ("RONGJIE?", float) = 0
|
||||
_Dissolve ("x:溶解强度 y:溶解描边范围 z:局部控制强度 w:溶解硬度, _DissolveWidth", vector) = (0.5, 0.1, 1, 0.1)
|
||||
_DissolveMap("溶解贴图 xy:UV缩放 zw:UV偏移",2D) = "grey"{}
|
||||
_DissolveMaskMap("局部溶解蒙版 xy:UV缩放 zw:UV偏移",2D) = "white"{}
|
||||
_DissolveOffsetRotateDistort("xy:溶解贴图偏移速度 z:溶解贴图旋转",Vector) = (0,0,0,0)
|
||||
[HDR]_DissolveLineColor("溶解描边颜色_hdr",Color) = (0,0,0,1)
|
||||
_DissolveVoronoi_Vec("xy:噪波1缩放,zw:噪波2缩放",Vector) = (1,1,2,2)
|
||||
_DissolveVoronoi_Vec2("x:噪波1和噪波2混合系数(圆尖),y:噪波整体和溶解贴图混合系数,z:噪波1速度,w:噪波2速度",Vector) = (1,1,2,2)
|
||||
_DissolveVoronoi_Vec3("xy:噪波1偏移速度,zw:噪波2偏移速度",Vector) = (0,0,0,0)
|
||||
_DissolveVoronoi_Vec4("xy:噪波1偏移,zw:噪波2偏移",Vector) = (0,0,0,0)
|
||||
_Dissolve_Vec2("溶解丝滑度(溶解值黑白调整)黑色X,白色Y",Vector) = (0,1,0,0)
|
||||
_DissolveRampMap("溶解Ramp图",2D) = "white"{}
|
||||
[HDR]_DissolveRampColor("溶解Ramp颜色_hdr",Color) = (1,1,1,1)
|
||||
|
||||
//颜色渐变贴图--------
|
||||
_ColorBlendMap("颜色渐变贴图 xy:UV缩放 zw:UV偏移",2D) = "white"{}
|
||||
[HDR]_ColorBlendColor("颜色渐变叠加_hdr",Color) = (1,1,1,1)
|
||||
_ColorBlendMapOffset("xy:颜色渐变贴图偏移动画",Vector) = (0,0,0,0)
|
||||
|
||||
_CustomData1X ("ignore", float) = 0
|
||||
_CustomData1Y ("ignore", float) = 0
|
||||
//因为希望本Shader兼容CanvasRender,由于Canvas渲染只会传递TEXCOORD通道的xy分量(zw分量忽略)的特性,所以强制让CustomedData只传递xy分量。
|
||||
_CustomData2X ("ignore", float) = 0
|
||||
|
||||
// -------------------------------------
|
||||
// Particle specific 属于粒子特殊的属性
|
||||
[ToggleOff] _CustomData ("__CustomData_Toggle", Float) = 0.0 //Toggleoff 和 Toggle 的区别
|
||||
[ToggleOff] _FlipbookBlending ("__flipbookblending_Toggle", Float) = 0.0 //Toggleoff 和 Toggle 的区别
|
||||
// _SoftParticlesNearFadeDistance ("Soft Particles Near Fade", Float) = 0.0
|
||||
// _SoftParticlesFarFadeDistance ("Soft Particles Far Fade", Float) = 1.0
|
||||
//[Toggle] _Fading ("Fading? =Default(1,2,0,0)", Float) = 0.0
|
||||
_CameraNearFadeDistance ("Camera Near Fade-ignore", Float) = 1.0
|
||||
_CameraFarFadeDistance ("Camera Far Fade-ignore", Float) = 2.0
|
||||
//临时
|
||||
_fogintensity ("雾影响强度", Range(0, 1)) = 1
|
||||
// -------------------------------------
|
||||
// Hidden properties - Generic 通用的隐藏属性
|
||||
[HideInInspector] _Blend ("__mode-ignore", Float) = 0.0
|
||||
[HideInInspector] _AlphaClip ("__clip-ignore", Float) = 0.0
|
||||
[HideInInspector] _SrcBlend ("__src-ignore", Float) = 1.0
|
||||
[HideInInspector] _DstBlend ("__dst-ignore", Float) = 0.0
|
||||
[HideInInspector] _Cull ("__cull-ignore", Float) = 2.0
|
||||
[HideInInspector] _ZTest ("__ztest-ignore", Float) = 4.0 //默认值LEqual
|
||||
[HideInInspector] _ZWrite("__ZWrite-ignore", Float) = 0 //默认值LEqual
|
||||
// [HideInInspector] _ZTestt ("__ztestt", Float) = 4.0//雨轩:注释掉了。。。这是个什么鬼。。。
|
||||
|
||||
|
||||
|
||||
_CustomStencilTest ("__CustomStencilTest-ignore", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("__StencilComp-ignore", Float) = 8
|
||||
_Stencil("Stencil ID-ignore", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)]_StencilOp("Stencil Operation-ignore", Float) = 0
|
||||
_StencilWriteMask ("Stencil Write Mask-ignore", Float) = 255
|
||||
_StencilReadMask ("Stencil Read Mask-ignore", Float) = 255
|
||||
_ColorMask("Color Mask-ignore", Float) = 15
|
||||
|
||||
//[HideInInspector] _ZTestO ("__ztest0", Float) = 1.0
|
||||
_FresnelFadeDistance ("菲涅尔透明乘数", float) = 1
|
||||
_FresnelUnit("菲涅尔通用", Vector) = (0,0.5,1,0.5)
|
||||
|
||||
_DepthOutline_Toggle("深度描边",Float) = 0
|
||||
[HDR]_DepthOutline_Color("深度描边颜色_hdr",Color) = (1,1,1,1)
|
||||
_DepthOutline_Vec("菲涅尔深度描边参数",Vector) = (0,0.5,0,0)
|
||||
// _DepthOutline_withoutFresnel_Toggle("深度描边关闭菲涅尔",Float) = 0
|
||||
// _FresnelUnit2("菲涅尔通用2", Vector) = (0,1,0,0)
|
||||
|
||||
_DepthDecal_Toggle("深度贴花",Float) = 0
|
||||
|
||||
_VertexOffset_Toggle("顶点偏移",Float) = 0
|
||||
_VertexOffset_Map("顶点偏移贴图",2D) = "white"{}
|
||||
_VertexOffset_Vec("xy:顶点偏移动画z:顶点偏移强度",Vector) = (0,0,1,0)
|
||||
_VertexOffset_NormalDir_Toggle("顶点偏移自定义方向开关",Float) = 0
|
||||
_VertexOffset_StartFromZero("顶点偏移从零开始开关",Float) = 0
|
||||
_VertexOffset_CustomDir("顶点偏移自定义方向",Vector) = (1,1,1,0)
|
||||
|
||||
_VertexOffset_Mask_Toggle("顶点偏移遮罩开关",Float) = 0
|
||||
_VertexOffset_MaskMap("顶点偏移遮罩贴图",2D) = "white"{}
|
||||
_VertexOffset_MaskMap_Vec("xy:顶点偏移遮罩动画z:顶点偏移遮罩强度",Vector) = (0,0,1,0)
|
||||
|
||||
|
||||
_ParallaxMapping_Toggle("视差",Float) = 0
|
||||
_ParallaxMapping_Map("视差贴图",2D) = "white"{}
|
||||
_ParallaxMapping_Intensity("视差强度",Float) = 1
|
||||
_ParallaxMapping_Vec("遮蔽视差层数 x:最小值,y:最大值",Vector) = (5,30,0,0)
|
||||
|
||||
|
||||
// Particle specific 粒子特殊的隐藏属性
|
||||
[HideInInspector] _ColorMode ("_ColorMode", Float) = 0.0
|
||||
[HideInInspector] _BaseColorAddSubDiff ("_ColorMode", Vector) = (0, 0, 0, 0)
|
||||
[HideInInspector] _SoftParticlesEnabled ("__softparticlesenabled", Float) = 0.0
|
||||
[HideInInspector] _CameraFadingEnabled ("__camerafadingenabled", Float) = 0.0
|
||||
[HideInInspector] _SoftParticleFadeParams ("xy:软粒子远近裁剪面", Vector) = (0, 0, 0, 0)
|
||||
[HideInInspector] _CameraFadeParams ("__camerafadeparams_ignore", Vector) = (0, 0, 0, 0)
|
||||
[HideInInspector] _IntersectEnabled("__IntersectEnabled_ignore",Float) = 0.0
|
||||
[HideInInspector] _IntersectRadius("__IntersectRadius_ignore",Float) = 0.3
|
||||
[HideInInspector] _IntersectColor("__IntersectColor_ignore",Color) = (1,1,1,1)
|
||||
|
||||
[HideInInspector] _ScreenDistortModeToggle("_ScreenDistortModeToggle",Float) = 0
|
||||
|
||||
|
||||
|
||||
// Editmode props 编辑模式下的PropFlags?
|
||||
[HideInInspector] _QueueBias ("Queue偏移_QueueBias", Float) =0
|
||||
|
||||
// ObsoleteProperties 弃用的属性????
|
||||
[HideInInspector] _FlipbookMode ("flipbook mode", Float) = 0
|
||||
[HideInInspector] _Mode ("mode", Float) = 0
|
||||
// [HideInInspector] _Color ("color", Color) = (1, 1, 1, 1)
|
||||
|
||||
[HideInInspector]_fresnelEnabled ("__fresnelEnabled", Float) = 0.0
|
||||
[NoScaleOffset]_FresnelHDRITex("__FresnelHDRITex_ignore",Cube) = "white"{}
|
||||
[HDR]_FresnelColor ("菲涅尔颜色_hdr", COLOR) = (1, 1, 1, 1)
|
||||
_FresnelRotation("菲涅尔方向偏移",vector) = (0,0,0,0.5)
|
||||
_FresnelInOutSlider ("direction-ignore", Range(0, 1)) = 1
|
||||
_FrePower ("FrePower-ignore", Range(0,1)) = 0.5
|
||||
_FresnelSelfAlphaWeight("__FresnelSelfAlphaWeight-ignore",float) = 0
|
||||
//用于程序控制透明属性
|
||||
[HideInInspector] _ColorA ("ColorA-ignore", Color) = (1,1,1,1)
|
||||
|
||||
_Portal_Toggle("模板视差开关",Float) = 0
|
||||
_Portal_MaskToggle("模板视差蒙版开关",Float) = 0
|
||||
|
||||
//基于深度的a通道控制
|
||||
[HideInInspector] _Fade("xy:近距离透明过度范围", Vector) = (2,4,0,0)
|
||||
|
||||
[HideInInspector] _InspectorData("__InspectorData-ignore",vector) = (1,1,0,0)
|
||||
|
||||
[Header(ZOffset)]
|
||||
_ZOffset_Toggle("深度偏移_Toggle",Float) = 0
|
||||
_offsetFactor("深度偏移Sacle-ignore", range(-2000,2000)) = 0
|
||||
_offsetUnits("深度偏移单位距离-ignore", range(-2000,2000)) = 0
|
||||
|
||||
[HideInInspector] _W9ParticleShaderFlags("_W9ParticleShaderFlags", Integer) = 0
|
||||
[HideInInspector] _W9ParticleShaderFlags1("_W9ParticleShaderFlags1", Integer) = 0
|
||||
[HideInInspector] _W9ParticleShaderWrapFlags("_W9ParticleShaderWrapFlags", Integer) = 0
|
||||
[HideInInspector] _W9ParticleCustomDataFlag0("_W9ParticleCustomDataFlag0", Integer) = 0
|
||||
[HideInInspector] _W9ParticleCustomDataFlag1("_W9ParticleCustomDataFlag1", Integer) = 0
|
||||
[HideInInspector] _W9ParticleCustomDataFlag2("_W9ParticleCustomDataFlag2", Integer) = 0
|
||||
[HideInInspector] _W9ParticleCustomDataFlag3("_W9ParticleCustomDataFlag3", Integer) = 0
|
||||
[HideInInspector] _UVModeFlag0("_UVModeFlag0", Integer) = 0
|
||||
[HideInInspector] _W9ParticleShaderGUIFoldToggle("_W9ParticleShaderGUIFoldToggle", Integer) = 31//前5个开关默认打开
|
||||
[HideInInspector] _W9ParticleShaderGUIFoldToggle1("_W9ParticleShaderGUIFoldToggle1", Integer) = 255//这边默认全开
|
||||
|
||||
// _offsetUnits("深度偏移单位距离-ignore", range(-2000,2000)) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
//BlendOp[_BlendOp] //考虑注释~
|
||||
Blend[_SrcBlend][_DstBlend]
|
||||
ZWrite [_ZWrite]//粒子不写入深度缓冲
|
||||
ZTest[_ZTest]
|
||||
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 预渲染反面Pass,基本理念。先剔除正面棉片,渲染反面面片(一般在后),然后常规Pass再渲染正面(一般在前)
|
||||
// 这样可以应对大部分的特效半透明渲染的次序问题。
|
||||
// URP下的多Pass渲染,需要使用特定的LightModeTag:
|
||||
// https://zhuanlan.zhihu.com/p/469589277#:~:text=%E6%B3%A8%E6%84%8F%E7%AC%AC%E4%BA%8C%E4%B8%AA%E5%85%89%E7%85%A7pass%E7%9A%84%E5%85%89%E7%85%A7tag%E4%B8%BA%20%22LightMode%22%20%3D%20%22SRPDefaultUnlit%22%EF%BC%8C%E8%BF%99%E6%98%AF%E5%9B%A0%E4%B8%BA%E5%BF%85%E9%A1%BB%E8%AE%BE%E7%BD%AE%E4%B8%BA%E7%89%B9%E5%AE%9A%E7%9A%84%E5%87%A0%E4%B8%AALightMode%20%E6%89%8D%E8%83%BD%E6%AD%A3%E7%A1%AE%E8%A2%AB%E6%B8%B2%E6%9F%93%E3%80%82%E5%85%B7%E4%BD%93%E5%93%AA%E5%87%A0%E4%B8%AA%20LightMode%20%E8%A7%81URP%E5%8C%85%E9%87%8C%E7%9A%84%20Runtime/Passes%20%E9%87%8C%E7%9A%84%20DrawObjectsPass.cs%E8%84%9A%E6%9C%AC%EF%BC%8C%E9%87%8C%E9%9D%A2%E6%9C%89%E5%A6%82%E4%B8%8B%E4%BB%A3%E7%A0%81%EF%BC%9A
|
||||
// 开关Pass,同样也需要用到LightTag
|
||||
// https://blog.csdn.net/shaoy1234567/article/details/106494878
|
||||
|
||||
Pass
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"LightMode" = "SRPDefaultUnlit" "Queue"="Opaque"
|
||||
}
|
||||
offset [_offsetFactor], [_offsetUnits]
|
||||
Name "SRPDefaultUnlit"
|
||||
Cull Front
|
||||
|
||||
HLSLPROGRAM
|
||||
#define PARTICLE
|
||||
#pragma target 4.5
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
#pragma exclude_renderers d3d9
|
||||
// -------------------------------------
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _ _SCREEN_DISTORT_MODE
|
||||
#pragma shader_feature_local _ _MASKMAP_ON
|
||||
// #pragma shader_feature_local _MASKMAP
|
||||
// #pragma shader_feature_local _MASKMAP2
|
||||
//#pragma shader_feature_local _NOISEMAP
|
||||
#pragma shader_feature_local _NOISEMAP
|
||||
//#pragma shader_feature_local _EMISSION //流光
|
||||
#pragma shader_feature_local _EMISSION
|
||||
//#pragma shader_feature_local _ _DISSOLVE //溶解
|
||||
#pragma shader_feature_local _DISSOLVE
|
||||
//后续Test类的关键字要找机会排除
|
||||
#pragma shader_feature_local _DISSOLVE_EDITOR_TEST
|
||||
#pragma shader_feature_local _COLORMAPBLEND//颜色渐变
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT//UI 2D遮罩
|
||||
// #pragma shader_feature_local _ _CH_XIANXING _CH_JINGXIANG _CH_SELF //线性擦除 径向擦除 mask擦除
|
||||
#pragma shader_feature_local _PARCUSTOMDATA_ON
|
||||
|
||||
//用于特效层关键字
|
||||
// #pragma shader_feature_local _UIEFFECT_ON
|
||||
|
||||
#pragma shader_feature_local _ FRESNEL_CUBEMAP FRESNEL_REFLECTIONPROBE
|
||||
|
||||
|
||||
// #pragma multi_compile _ _UIPARTICLE_ON//用于UIParticle组件动态更改参数//暂时注释掉,觉得没什么意义
|
||||
#pragma multi_compile _ SOFT_UI_FRAME//用于UI软蒙版
|
||||
// -------------------------------------
|
||||
// Particle Keywords
|
||||
//#pragma shader_feature_local _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON //设置alpah Add 。。组合
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
//#pragma shader_feature_local _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON //粒子颜色和材质颜色的混合运算 暂时先不要了
|
||||
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
|
||||
#pragma shader_feature_local _SOFTPARTICLES_ON
|
||||
// #pragma shader_feature_local _OCCLUDEOPACITY_ON
|
||||
// #pragma shader_feature_local _ _SATURABILITY_ON
|
||||
|
||||
//UnscaleTime用于接收项目传的公开不受缩放影响的Time值
|
||||
#pragma shader_feature_local _UNSCALETIME
|
||||
//scriptableTime用于程序每帧传值
|
||||
#pragma shader_feature_local _SCRIPTABLETIME
|
||||
//#pragma shader_feature_local _DISTORTION_ON
|
||||
#pragma shader_feature_local _NOISEMAP_NORMALIZEED
|
||||
|
||||
#pragma shader_feature_local _DEPTH_DECAL
|
||||
#pragma shader_feature_local _PARALLAX_MAPPING
|
||||
|
||||
#pragma shader_feature_local _STENCIL_WITHOUT_PLAYER
|
||||
|
||||
// -------------------------------------
|
||||
// Unity defined keywords
|
||||
// 之后进行优化时再说。
|
||||
#pragma multi_compile_fog
|
||||
// #define FOG_EXP2 1
|
||||
|
||||
|
||||
// #if defined(_SOFTPARTICLES_ON)
|
||||
// #define NEED_EYE_DEPTH
|
||||
// #endif
|
||||
|
||||
#define PARTICLE_BACKFACE_PASS
|
||||
|
||||
#pragma vertex vertParticleUnlit
|
||||
#pragma fragment fragParticleUnlit
|
||||
|
||||
// #include "UnityCG.cginc"
|
||||
// #include "AutoLight.cginc"
|
||||
// #include "UnityUI.cginc"
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
|
||||
#include "Packages/com.xuanxuan.render.utility/Shader/HLSL/XuanXuan_Utility.hlsl"
|
||||
#include "HLSL/ParticlesUnlitInputNew.hlsl"
|
||||
#include "HLSL/ParticlesUnlitForwardPassNew.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Forward pass.
|
||||
Pass
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"LightMode" = "UniversalForward"
|
||||
} //Queue设置是希望特效渲染在场景透明物体前面
|
||||
offset [_offsetFactor], [_offsetUnits]
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#define PARTICLE
|
||||
//20240228 target3.0 顶点着色器限制16个输出。提高版本
|
||||
#pragma target 4.5
|
||||
|
||||
// -------------------------------------
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _ _SCREEN_DISTORT_MODE
|
||||
#pragma shader_feature_local _ _MASKMAP_ON
|
||||
// #pragma shader_feature_local _MASKMAP
|
||||
// #pragma shader_feature_local _MASKMAP2
|
||||
//#pragma shader_feature_local _NOISEMAP
|
||||
#pragma shader_feature_local _NOISEMAP
|
||||
//#pragma shader_feature_local _EMISSION //流光
|
||||
#pragma shader_feature_local _EMISSION
|
||||
//#pragma shader_feature_local _ _DISSOLVE //溶解
|
||||
#pragma shader_feature_local _DISSOLVE
|
||||
//后续Test类的关键字要找机会排除
|
||||
#pragma shader_feature_local _DISSOLVE_EDITOR_TEST
|
||||
#pragma shader_feature_local _COLORMAPBLEND//颜色渐变
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT//UI 2D遮罩
|
||||
// #pragma shader_feature_local _ _CH_XIANXING _CH_JINGXIANG _CH_SELF //线性擦除 径向擦除 mask擦除
|
||||
#pragma shader_feature_local _PARCUSTOMDATA_ON
|
||||
|
||||
//用于特效层关键字
|
||||
// #pragma shader_feature_local _UIEFFECT_ON
|
||||
|
||||
#pragma shader_feature_local _ FRESNEL_CUBEMAP FRESNEL_REFLECTIONPROBE
|
||||
|
||||
|
||||
// #pragma multi_compile _ _UIPARTICLE_ON//用于UIParticle组件动态更改参数//暂时注释掉,觉得没什么意义
|
||||
#pragma multi_compile _ SOFT_UI_FRAME//用于UI软蒙版
|
||||
// -------------------------------------
|
||||
// Particle Keywords
|
||||
//#pragma shader_feature_local _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON //设置alpah Add 。。组合
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
//#pragma shader_feature_local _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON //粒子颜色和材质颜色的混合运算 暂时先不要了
|
||||
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
|
||||
#pragma shader_feature_local _SOFTPARTICLES_ON
|
||||
// #pragma shader_feature_local _OCCLUDEOPACITY_ON
|
||||
// #pragma shader_feature_local _ _SATURABILITY_ON
|
||||
|
||||
//UnscaleTime用于接收项目传的公开不受缩放影响的Time值
|
||||
#pragma shader_feature_local _UNSCALETIME
|
||||
//scriptableTime用于程序每帧传值
|
||||
#pragma shader_feature_local _SCRIPTABLETIME
|
||||
//#pragma shader_feature_local _DISTORTION_ON
|
||||
#pragma shader_feature_local _NOISEMAP_NORMALIZEED
|
||||
|
||||
#pragma shader_feature_local _DEPTH_DECAL
|
||||
#pragma shader_feature_local _PARALLAX_MAPPING
|
||||
|
||||
#pragma shader_feature_local _STENCIL_WITHOUT_PLAYER
|
||||
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
// Unity defined keywords
|
||||
// 之后进行优化时再说。
|
||||
#pragma multi_compile_fog
|
||||
// #define FOG_EXP2 1
|
||||
|
||||
#pragma vertex vertParticleUnlit
|
||||
#pragma fragment fragParticleUnlit
|
||||
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
// The DeclareDepthTexture.hlsl file contains utilities for sampling the Camera
|
||||
// depth texture.
|
||||
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
|
||||
#include "Packages/com.xuanxuan.render.utility/Shader/HLSL/XuanXuan_Utility.hlsl"
|
||||
|
||||
#include "HLSL/ParticlesUnlitInputNew.hlsl"
|
||||
#include "HLSL/ParticlesUnlitForwardPassNew.hlsl"
|
||||
|
||||
|
||||
ENDHLSL
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CustomEditor "ParticleBaseGUI"
|
||||
}
|
||||
9
Packages/NBShaders/Shader/ParticleBase.shader.meta
Normal file
9
Packages/NBShaders/Shader/ParticleBase.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7184a95c20fc1a441a8815af4c795ccd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Packages/NBShaders/Shader/StencilConfig.asset
Normal file
75
Packages/NBShaders/Shader/StencilConfig.asset
Normal file
@@ -0,0 +1,75 @@
|
||||
%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: 9177edf81a5b2354490ec4d66c4c069d, type: 3}
|
||||
m_Name: StencilConfig
|
||||
m_EditorClassIdentifier: Assembly-CSharp-Editor:stencilTestHelper:StencilValuesConfig
|
||||
Config:
|
||||
- key: Disturbance
|
||||
Values:
|
||||
DefaultQueue: 3000
|
||||
Ref: 0
|
||||
Comp: 8
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticalBasePortal
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 200
|
||||
Comp: 3
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticalBasePortalMask
|
||||
Values:
|
||||
DefaultQueue: 2000
|
||||
Ref: 200
|
||||
Comp: 8
|
||||
Pass: 2
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticleBaseDecal
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 2
|
||||
Comp: 7
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticleBaseDefault
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 0
|
||||
Comp: 8
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
- key: ParticleWithoutPlayer
|
||||
Values:
|
||||
DefaultQueue: 3100
|
||||
Ref: 5
|
||||
Comp: 5
|
||||
Pass: 0
|
||||
Fail: 0
|
||||
ZFail: 0
|
||||
ReadMask: 255
|
||||
WriteMask: 255
|
||||
8
Packages/NBShaders/Shader/StencilConfig.asset.meta
Normal file
8
Packages/NBShaders/Shader/StencilConfig.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7093501998f1b24483fa6c8eddcf8fb
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Packages/NBShaders/package.json
Normal file
7
Packages/NBShaders/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "com.xuanxuan.nb.shaders",
|
||||
"version": "0.0.1",
|
||||
"displayName": "NBShaders",
|
||||
"description": "NB特效渲染相关功能",
|
||||
"unity": "2019.1"
|
||||
}
|
||||
7
Packages/NBShaders/package.json.meta
Normal file
7
Packages/NBShaders/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48379e0a1548d0744956d75379b0c724
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Packages/XuanXuanRenderUtility/Editor.meta
Normal file
3
Packages/XuanXuanRenderUtility/Editor.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd758a702a9040fcb8614b232817cff9
|
||||
timeCreated: 1721290722
|
||||
100
Packages/XuanXuanRenderUtility/Editor/BinaryIntAttribute.cs
Normal file
100
Packages/XuanXuanRenderUtility/Editor/BinaryIntAttribute.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
// using Unity.Properties;
|
||||
|
||||
public class BinaryIntAttribute : PropertyAttribute
|
||||
{
|
||||
public int binaryBits;
|
||||
public bool showInputFiled;
|
||||
public int tabNums;
|
||||
|
||||
|
||||
public BinaryIntAttribute(int Bits = 32,bool showInput = false,int tab = 0)
|
||||
{
|
||||
binaryBits = Bits;
|
||||
showInputFiled = showInput;
|
||||
tabNums = tab;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(BinaryIntAttribute))]
|
||||
public class BinaryIntDrawer : PropertyDrawer
|
||||
{
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
GUIStyle richTextStyle = EditorStyles.label;
|
||||
richTextStyle.richText = true;
|
||||
BinaryIntAttribute binaryIntAttribute = (BinaryIntAttribute)attribute;
|
||||
// int value = property.intValue;
|
||||
// int largestBit = 0;
|
||||
// for (int i = 0; i < 32; i++)
|
||||
// {
|
||||
// if ((~value & (1 << i)) == 0)
|
||||
// {
|
||||
// largestBit = i;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int addZeroCount = 0;
|
||||
// if (largestBit < binaryIntAttribute.binaryBits)
|
||||
// {
|
||||
// addZeroCount = binaryIntAttribute.binaryBits - largestBit - 1;
|
||||
// }
|
||||
//
|
||||
// string addZeroString = "";
|
||||
// for (int i = 0; i < addZeroCount; i++)
|
||||
// {
|
||||
// addZeroString += "0";
|
||||
// }
|
||||
// string binary = addZeroString+Convert.ToString(property.intValue, 2);
|
||||
string binary = DrawBinaryInt(property.intValue, binaryIntAttribute.binaryBits);
|
||||
|
||||
string tabs = "";
|
||||
for (int i = 0; i < binaryIntAttribute.tabNums; i++)
|
||||
{
|
||||
tabs += "\t";
|
||||
}
|
||||
|
||||
if (binaryIntAttribute.showInputFiled)
|
||||
{
|
||||
string labelText = property.displayName + tabs + "<mspace=1em>" + binary + "</mspace>";
|
||||
Rect intRect = EditorGUI.PrefixLabel(position,new GUIContent(labelText),richTextStyle);
|
||||
property.intValue = EditorGUI.IntField( intRect,property.intValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField(property.displayName + tabs);
|
||||
EditorGUILayout.LabelField(binary);
|
||||
}
|
||||
}
|
||||
|
||||
public static string DrawBinaryInt(int value ,int binaryBits)
|
||||
{
|
||||
int largestBit = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if ((~value & (1 << i)) == 0)
|
||||
{
|
||||
largestBit = i;
|
||||
}
|
||||
}
|
||||
|
||||
int addZeroCount = 0;
|
||||
if (largestBit < binaryBits)
|
||||
{
|
||||
addZeroCount = binaryBits - largestBit - 1;
|
||||
}
|
||||
|
||||
string addZeroString = "";
|
||||
for (int i = 0; i < addZeroCount; i++)
|
||||
{
|
||||
addZeroString += "0";
|
||||
}
|
||||
string binary = addZeroString+Convert.ToString(value, 2);
|
||||
return binary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4517deaf5f31a5848b6a58304d1f516f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,236 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// #if UNITY_EDITOR
|
||||
[CustomEditor(typeof(MaterialPropertyAgent))]
|
||||
public class MaterialPropertyAgentInspector : UnityEditor.Editor
|
||||
{
|
||||
private MaterialPropertyAgent agent;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
agent = (MaterialPropertyAgent)target;
|
||||
}
|
||||
|
||||
private GUIContent materialIndexContent = new GUIContent("材质序号:", "只有模型模式下需要使用,谨慎修改");
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
if (!agent.isGetByComponet)
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("customRenderer"),new GUIContent("指定Renderer"));
|
||||
}
|
||||
if (agent.isRendererMode)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
int lastIndex = agent.materialIndex;
|
||||
agent.materialIndex = EditorGUILayout.IntField(materialIndexContent ,agent.materialIndex);
|
||||
if (lastIndex != agent.materialIndex)
|
||||
{
|
||||
agent.initMatAndShaderByMaterialIndexChange();
|
||||
}
|
||||
EditorGUILayout.LabelField("材质名:"+agent.mat.name+"\t"+"Shader名:"+agent.shader.name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
DrawPropertyData(ref agent.data0, "Data0", serializedObject.FindProperty("data0"));
|
||||
DrawPropertyData(ref agent.data1, "Data1", serializedObject.FindProperty("data1"));
|
||||
DrawPropertyData(ref agent.data2, "Data2", serializedObject.FindProperty("data2"));
|
||||
DrawPropertyData(ref agent.data3, "Data3", serializedObject.FindProperty("data3"));
|
||||
DrawPropertyData(ref agent.data4, "Data4", serializedObject.FindProperty("data4"));
|
||||
DrawPropertyData(ref agent.data5, "Data5", serializedObject.FindProperty("data5"));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("添加"))
|
||||
{
|
||||
agent.addProperteData();
|
||||
}
|
||||
if (GUILayout.Button("全部删除"))
|
||||
{
|
||||
agent.removeAllProperty();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(agent);
|
||||
if (!agent.isGetByComponet && agent.mat)
|
||||
{
|
||||
if(matEditor) DestroyImmediate(matEditor);
|
||||
matEditor = (MaterialEditor)CreateEditor(agent.mat);
|
||||
}
|
||||
}
|
||||
|
||||
if (!agent.isGetByComponet && agent.mat)
|
||||
{
|
||||
DrawMaterialInspector(matEditor,agent.mat);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawPropertyData(ref MaterialPropertyAgent.PropertyData data, string dataLabel, SerializedProperty property)
|
||||
{
|
||||
EditorGUI.BeginProperty(EditorGUILayout.GetControlRect(false, 0f), GUIContent.none, property);
|
||||
if (data.isActive)
|
||||
{
|
||||
EditorGUILayout.LabelField(dataLabel, EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
float originLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 80;
|
||||
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropNameArr);
|
||||
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropDescripArr);
|
||||
// string dataDesript = data.descripName;
|
||||
if (GUILayout.Button(data.descripName, EditorStyles.popup))
|
||||
{
|
||||
int dataIndexInAgent = data.dataIndexInAgent;
|
||||
|
||||
StringListSerchProvider provider = ScriptableObject.CreateInstance<StringListSerchProvider>();
|
||||
provider.Initialize(agent.shaderPropDescripsForSerch, (x) =>
|
||||
{
|
||||
if (x != null)
|
||||
{
|
||||
AfterShaderPropSerch(dataIndexInAgent,x);
|
||||
}
|
||||
});
|
||||
SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)), provider);
|
||||
// SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)),
|
||||
// new StringListSerchProvider(agent.shaderPropDescripsForSerch, (x) =>
|
||||
// {
|
||||
// if (x != null)
|
||||
// {
|
||||
// AfterShaderPropSerch(dataIndexInAgent,x);
|
||||
// }
|
||||
// }));
|
||||
}
|
||||
|
||||
|
||||
|
||||
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = originLabelWidth;
|
||||
switch (data.type)
|
||||
{
|
||||
case MaterialPropertyAgent.shaderPropertyType.Color:
|
||||
SerializedProperty colorProp = property.FindPropertyRelative("colorValue");
|
||||
if (data.descripName.ToLower().Contains("hdr"))
|
||||
{
|
||||
colorProp.colorValue = EditorGUILayout.ColorField(new GUIContent(data.propName + " :") , colorProp.colorValue,true,true,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
colorProp.colorValue = EditorGUILayout.ColorField(data.propName + " :", colorProp.colorValue);
|
||||
}
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Vector:
|
||||
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
|
||||
SerializedProperty vecProp = property.FindPropertyRelative("vecValue");
|
||||
if (data.type == MaterialPropertyAgent.shaderPropertyType.Vector)
|
||||
{
|
||||
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + " :", vecProp.vector4Value);
|
||||
}
|
||||
else if (data.type == MaterialPropertyAgent.shaderPropertyType.TexEnv)
|
||||
{
|
||||
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + ":", vecProp.vector4Value);
|
||||
|
||||
}
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Float:
|
||||
case MaterialPropertyAgent.shaderPropertyType.Range:
|
||||
SerializedProperty floatProp = property.FindPropertyRelative("floatValue");
|
||||
if (data.type == MaterialPropertyAgent.shaderPropertyType.Float)
|
||||
{
|
||||
floatProp.floatValue = EditorGUILayout.FloatField(data.propName + ":", floatProp.floatValue);
|
||||
}
|
||||
else if (data.type == MaterialPropertyAgent.shaderPropertyType.Range)
|
||||
{
|
||||
floatProp.floatValue = EditorGUILayout.Slider(data.propName + ":", floatProp.floatValue, data.rangMin, data.rangMax);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
|
||||
{
|
||||
data.isActive = false;
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
// EditorGUILayout.Space();
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
//因为Action不能有Ref。所以有了这个丑陋的HardCode
|
||||
public void AfterShaderPropSerch(int dataIndexInAgent, string propertyDesrpt)
|
||||
{
|
||||
switch (dataIndexInAgent)
|
||||
{
|
||||
case 0:
|
||||
AfterShaderPropSerch(ref agent.data0,propertyDesrpt);
|
||||
break;
|
||||
case 1:
|
||||
AfterShaderPropSerch(ref agent.data1,propertyDesrpt);
|
||||
break;
|
||||
case 2:
|
||||
AfterShaderPropSerch(ref agent.data2,propertyDesrpt);
|
||||
break;
|
||||
case 3:
|
||||
AfterShaderPropSerch(ref agent.data3,propertyDesrpt);
|
||||
break;
|
||||
case 4:
|
||||
AfterShaderPropSerch(ref agent.data4,propertyDesrpt);
|
||||
break;
|
||||
case 5:
|
||||
AfterShaderPropSerch(ref agent.data5,propertyDesrpt);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void AfterShaderPropSerch(ref MaterialPropertyAgent.PropertyData data, string propertyDesrpt)
|
||||
{
|
||||
int preservedIndex = data.index;
|
||||
// string propname = data.propName;
|
||||
data.index = Array.FindIndex(agent.shaderPropDescripArr, x=> x.Equals(propertyDesrpt) );
|
||||
// Debug.Log();
|
||||
if (preservedIndex != data.index)//证明用户进行了更改
|
||||
{
|
||||
if (!agent.isCanUsedIndex(data.index))
|
||||
{
|
||||
//TODO给一个报错提示
|
||||
Debug.LogError("材质属性已经存在:" + ShaderUtil.GetPropertyDescription(agent.shader, data.index));
|
||||
data.index = agent.getCanUsedIndex();
|
||||
}
|
||||
//此处进行内容刷新
|
||||
data.setValueByPropChange();
|
||||
}
|
||||
}
|
||||
|
||||
private MaterialEditor matEditor;
|
||||
void DrawMaterialInspector(MaterialEditor editor,Material mat)
|
||||
{
|
||||
if (editor != null && mat != null)
|
||||
{
|
||||
// Draw the material's foldout and the material shader field
|
||||
// Required to call _materialEditor.OnInspectorGUI ();
|
||||
editor.DrawHeader();
|
||||
// We need to prevent the user to edit Unity default materials
|
||||
bool isDefaultMaterial = !AssetDatabase.GetAssetPath (mat).StartsWith ("Assets");
|
||||
using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) {
|
||||
|
||||
// Draw the material properties
|
||||
// Works only if the foldout of _materialEditor.DrawHeader () is open
|
||||
editor.OnInspectorGUI ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// #endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9544bec10c84ecca289bece4a630d65
|
||||
timeCreated: 1702126025
|
||||
732
Packages/XuanXuanRenderUtility/Editor/ShaderGUIHelper.cs
Normal file
732
Packages/XuanXuanRenderUtility/Editor/ShaderGUIHelper.cs
Normal file
@@ -0,0 +1,732 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.AnimatedValues;
|
||||
// using UnityEditor.Rendering.Universal.ShaderGUI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor
|
||||
{
|
||||
public class ShaderGUIHelper
|
||||
{
|
||||
public class ShaderPropertyPack
|
||||
{
|
||||
public MaterialProperty property;
|
||||
public string name;
|
||||
}
|
||||
|
||||
private List<Material> mats;
|
||||
private MaterialEditor matEditor;
|
||||
public List<ShaderPropertyPack> ShaderPropertyPacks = new List<ShaderPropertyPack>();
|
||||
public ShaderFlagsBase[] shaderFlags = null;
|
||||
|
||||
|
||||
public void Init(MaterialEditor materialEditor, MaterialProperty[] properties,
|
||||
ShaderFlagsBase[] shaderFlags_in = null, List<Material> mats_in = null)
|
||||
{
|
||||
shaderFlags = shaderFlags_in;
|
||||
ShaderPropertyPacks.Clear();
|
||||
|
||||
mats = mats_in;
|
||||
Shader shader = mats[0].shader;
|
||||
matEditor = materialEditor;
|
||||
for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
|
||||
{
|
||||
ShaderPropertyPack pack = new ShaderPropertyPack();
|
||||
pack.name = ShaderUtil.GetPropertyName(shader, i);
|
||||
for (int index = 0; index < properties.Length; ++index)
|
||||
{
|
||||
if (properties[index] != null && properties[index].name == pack.name)
|
||||
{
|
||||
pack.property = properties[index];
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index == properties.Length - 1)
|
||||
{
|
||||
Debug.LogError(pack.name + "找不到Properties");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShaderPropertyPacks.Add(pack);
|
||||
}
|
||||
}
|
||||
|
||||
AnimBool trueAnimBool = new AnimBool(true);
|
||||
|
||||
public void DrawBigBlock(String label, Action drawBlock)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
var origFontStyle = EditorStyles.label.fontStyle;
|
||||
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||
EditorGUILayout.LabelField(label);
|
||||
EditorStyles.label.fontStyle = origFontStyle;
|
||||
drawBlock();
|
||||
GuiLine();
|
||||
}
|
||||
|
||||
public void DrawBigBlockFoldOut(ref AnimBool foldOutAnimBool, String label, Action drawBlock)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var rect = EditorGUILayout.GetControlRect();
|
||||
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
|
||||
// EditorGUI.DrawRect(foldoutRect,Color.red);
|
||||
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
|
||||
// EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
|
||||
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
|
||||
FontStyle origFontStyle = EditorStyles.label.fontStyle;
|
||||
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
EditorStyles.label.fontStyle = origFontStyle;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
float faded = foldOutAnimBool.faded;
|
||||
if (faded == 0) faded = 0.00001f;
|
||||
EditorGUILayout.BeginFadeGroup(faded);
|
||||
EditorGUI.indentLevel++;
|
||||
drawBlock();
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
GuiLine();
|
||||
}
|
||||
|
||||
public void DrawBigBlockWithToggle(String label, string propertyName, int flagBitsName = 0, int flagIndex = 0,
|
||||
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
|
||||
Action<bool> drawBlock = null)
|
||||
{
|
||||
|
||||
DrawToggle(label, propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, shaderPassName2,
|
||||
isIndentBlock: true, FontStyle.Bold, drawBlock: drawBlock);
|
||||
GuiLine();
|
||||
|
||||
}
|
||||
|
||||
public void DrawToggleFoldOut(ref AnimBool foldOutAnimBool, String label, string propertyName = null,
|
||||
int flagBitsName = 0,
|
||||
int flagIndex = 0, string shaderKeyword = null, string shaderPassName = null, bool isIndentBlock = true,
|
||||
FontStyle fontStyle = FontStyle.Normal,
|
||||
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
|
||||
{
|
||||
if (fontStyle == FontStyle.Bold)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var rect = EditorGUILayout.GetControlRect();
|
||||
var toggleRect = GetRectAfterLabelWidth(rect);
|
||||
|
||||
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
|
||||
foldoutRect.width = toggleRect.x - foldoutRect.x;
|
||||
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
|
||||
|
||||
bool isToggle = false;
|
||||
// 必须先画Toggle,不然按钮会被FoldOut和Label覆盖。
|
||||
DrawToggle("", propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, isIndentBlock: false,
|
||||
fontStyle: FontStyle.Normal, rect: toggleRect, drawBlock:
|
||||
toggle => { isToggle = toggle; }, drawEndChangeCheck: isEndChangeToggle =>
|
||||
{
|
||||
if (drawEndChangeCheck != null)
|
||||
{
|
||||
drawEndChangeCheck(isEndChangeToggle);
|
||||
}
|
||||
});
|
||||
|
||||
// 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(!isToggle);
|
||||
drawBlock?.Invoke(isToggle);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
if (isIndentBlock) EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
public void DrawToggle(String label, string propertyName = null, int flagBitsName = 0, int flagIndex = 0,
|
||||
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
|
||||
bool isIndentBlock = true, FontStyle fontStyle = FontStyle.Normal, Rect rect = new Rect(),
|
||||
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
|
||||
{
|
||||
if (propertyName != null && GetProperty(propertyName) == null)
|
||||
return;
|
||||
|
||||
if (fontStyle == FontStyle.Bold)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
bool isToggle = false;
|
||||
|
||||
if (propertyName != null)
|
||||
{
|
||||
isToggle = GetProperty(propertyName).floatValue > 0.5f ? true : false;
|
||||
}
|
||||
else if (flagBitsName != 0 && shaderFlags[0] != null)
|
||||
{
|
||||
isToggle = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex);
|
||||
}
|
||||
else if (shaderKeyword != null)
|
||||
{
|
||||
isToggle = mats[0].IsKeywordEnabled(shaderKeyword);
|
||||
}
|
||||
else if (shaderPassName != null)
|
||||
{
|
||||
isToggle = mats[0].GetShaderPassEnabled(shaderPassName);
|
||||
}
|
||||
else if (shaderPassName2 != null)
|
||||
{
|
||||
isToggle = mats[0].GetShaderPassEnabled(shaderPassName2);
|
||||
}
|
||||
|
||||
if (propertyName != null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mats.Count; i++)
|
||||
{
|
||||
if (isToggle)
|
||||
{
|
||||
if (shaderKeyword != null)
|
||||
{
|
||||
mats[i].EnableKeyword(shaderKeyword);
|
||||
}
|
||||
|
||||
if (shaderPassName != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName, true);
|
||||
}
|
||||
|
||||
if (shaderPassName2 != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shaderKeyword != null)
|
||||
{
|
||||
mats[i].DisableKeyword(shaderKeyword);
|
||||
}
|
||||
|
||||
if (shaderPassName != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName, false);
|
||||
}
|
||||
|
||||
if (shaderPassName2 != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName2, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var origFontStyle = EditorStyles.label.fontStyle;
|
||||
EditorStyles.label.fontStyle = fontStyle;
|
||||
if (rect.width > 0) //给FoldOut功能使用。
|
||||
{
|
||||
isToggle = EditorGUI.Toggle(rect, isToggle, EditorStyles.toggle);
|
||||
}
|
||||
else
|
||||
{
|
||||
isToggle = EditorGUILayout.Toggle(label, isToggle);
|
||||
}
|
||||
|
||||
EditorStyles.label.fontStyle = origFontStyle;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
for (int i = 0; i < mats.Count; i++)
|
||||
{
|
||||
if (isToggle)
|
||||
{
|
||||
if (propertyName != null)
|
||||
{
|
||||
GetProperty(propertyName).floatValue = 1;
|
||||
}
|
||||
|
||||
if (flagBitsName != 0 && shaderFlags[i] != null)
|
||||
{
|
||||
shaderFlags[i].SetFlagBits(flagBitsName, index: flagIndex);
|
||||
}
|
||||
|
||||
if (shaderKeyword != null)
|
||||
{
|
||||
mats[i].EnableKeyword(shaderKeyword);
|
||||
}
|
||||
|
||||
if (shaderPassName != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName, true);
|
||||
}
|
||||
|
||||
if (shaderPassName2 != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propertyName != null)
|
||||
{
|
||||
GetProperty(propertyName).floatValue = 0;
|
||||
}
|
||||
|
||||
if (flagBitsName != 0 && shaderFlags[i] != null)
|
||||
{
|
||||
shaderFlags[i].ClearFlagBits(flagBitsName, index: flagIndex);
|
||||
}
|
||||
|
||||
if (shaderKeyword != null)
|
||||
{
|
||||
mats[i].DisableKeyword(shaderKeyword);
|
||||
}
|
||||
|
||||
if (shaderPassName != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName, false);
|
||||
}
|
||||
|
||||
if (shaderPassName2 != null)
|
||||
{
|
||||
mats[i].SetShaderPassEnabled(shaderPassName2, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawEndChangeCheck?.Invoke(isToggle);
|
||||
}
|
||||
|
||||
if (isIndentBlock) EditorGUI.indentLevel++;
|
||||
drawBlock?.Invoke(isToggle);
|
||||
if (isIndentBlock) EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
|
||||
public void DrawSlider(string label, string propertyName, float minValue, float maxValue,
|
||||
Action<float> drawBlock = null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
float f = GetProperty(propertyName).floatValue;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
GetProperty(propertyName).floatValue = f;
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(f);
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
|
||||
public void DrawFloat(string label, string propertyName, bool isReciprocal = false,
|
||||
Action<float> drawBlock = null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
float f = GetProperty(propertyName).floatValue;
|
||||
if (isReciprocal) f = 1 / f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
f = EditorGUILayout.FloatField(label, f);
|
||||
if (isReciprocal) f = 1 / f;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
GetProperty(propertyName).floatValue = f;
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(f);
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public void DrawVector4In2Line(string propertyName, string firstLineLabel = null, string secondLineLabel = null,
|
||||
Action drawBlock = null)
|
||||
{
|
||||
MaterialProperty property = GetProperty(propertyName);
|
||||
EditorGUI.showMixedValue = property.hasMixedValue;
|
||||
|
||||
|
||||
Vector2 xy = new Vector2(property.vectorValue.x, property.vectorValue.y);
|
||||
Vector2 zw = new Vector2(property.vectorValue.z, property.vectorValue.w);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
if (firstLineLabel != null)
|
||||
{
|
||||
xy = EditorGUILayout.Vector2Field(firstLineLabel, xy);
|
||||
}
|
||||
|
||||
if (secondLineLabel != null)
|
||||
{
|
||||
zw = EditorGUILayout.Vector2Field(secondLineLabel, zw);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
property.vectorValue = new Vector4(xy.x, xy.y, zw.x, zw.y);
|
||||
}
|
||||
|
||||
drawBlock?.Invoke();
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
}
|
||||
|
||||
float GetCompInVec4(Vector4 vec, string comp)
|
||||
{
|
||||
float f = 0;
|
||||
switch (comp)
|
||||
{
|
||||
case "x":
|
||||
f = vec.x;
|
||||
break;
|
||||
case "y":
|
||||
f = vec.y;
|
||||
break;
|
||||
case "z":
|
||||
f = vec.z;
|
||||
break;
|
||||
case "w":
|
||||
f = vec.w;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Vector4 SetCompInVec4(Vector4 vec, string comp, float value)
|
||||
{
|
||||
switch (comp)
|
||||
{
|
||||
case "x":
|
||||
vec.x = value;
|
||||
break;
|
||||
case "y":
|
||||
vec.y = value;
|
||||
break;
|
||||
case "z":
|
||||
vec.z = value;
|
||||
break;
|
||||
case "w":
|
||||
vec.w = value;
|
||||
break;
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
public void DrawVector4MinMaxSlider(string propertyName, string Lable, string minChannel, string maxChanel,
|
||||
float minValue = 0f, float maxValue = 1f, Action<float> drawBlock = null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
Vector4 vec = GetProperty(propertyName).vectorValue;
|
||||
float minChannelVal = GetCompInVec4(vec, minChannel);
|
||||
float maxChanelVal = GetCompInVec4(vec, maxChanel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
using (EditorGUILayout.HorizontalScope scope = new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel(Lable);
|
||||
minChannelVal =
|
||||
EditorGUILayout.FloatField(minChannelVal, new GUILayoutOption[] { GUILayout.Width(80) });
|
||||
EditorGUILayout.MinMaxSlider(ref minChannelVal, ref maxChanelVal, minValue, maxValue);
|
||||
maxChanelVal = EditorGUILayout.FloatField(maxChanelVal, new GUILayoutOption[] { GUILayout.Width(80) });
|
||||
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
vec = SetCompInVec4(vec, minChannel, minChannelVal);
|
||||
vec = SetCompInVec4(vec, maxChanel, maxChanelVal);
|
||||
GetProperty(propertyName).vectorValue = vec;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
}
|
||||
|
||||
public void DrawVector4Componet(string label, string propertyName, string channel, bool isSlider,
|
||||
float minValue = 0, float maxValue = 1, float powerSlider = 1, float multiplier = 1,
|
||||
bool isReciprocal = false, Action<float> drawBlock = null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
Vector4 vec = GetProperty(propertyName).vectorValue;
|
||||
float f = GetCompInVec4(vec, channel);
|
||||
f *= multiplier;
|
||||
if (isReciprocal) f = 1 / f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
if (isSlider)
|
||||
{
|
||||
if (powerSlider > 1)
|
||||
{
|
||||
f = PowerSlider(EditorGUILayout.GetControlRect(new GUILayoutOption[] { GUILayout.Height(18) }),
|
||||
new GUIContent(label), f, minValue, maxValue, powerSlider);
|
||||
}
|
||||
else
|
||||
{
|
||||
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f = EditorGUILayout.FloatField(label, f);
|
||||
}
|
||||
|
||||
if (isReciprocal) f = 1 / f;
|
||||
f /= multiplier;
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
GetProperty(propertyName).vectorValue = SetCompInVec4(vec, channel, f);
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(f);
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public void DrawVector4XYZComponet(string label, string propertyName, Action<Vector3> drawBlock = null)
|
||||
{
|
||||
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
|
||||
Vector4 originVec = GetProperty(propertyName).vectorValue;
|
||||
Vector3 vec = originVec;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
vec = EditorGUILayout.Vector3Field(label, vec);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
GetProperty(propertyName).vectorValue = new Vector4(vec.x, vec.y, vec.z, originVec.w);
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(vec);
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public enum SamplerWarpMode
|
||||
{
|
||||
Repeat,
|
||||
Clamp,
|
||||
RepeatX_ClampY,
|
||||
ClampX_RepeatY
|
||||
}
|
||||
|
||||
public Rect GetRectAfterLabelWidth(Rect rect, bool ignoreIndent = false)
|
||||
{
|
||||
Rect rectAfterLabelWidth = MaterialEditor.GetRectAfterLabelWidth(rect); //右边缘是准的。
|
||||
Rect leftAlignedFieldRect = MaterialEditor.GetLeftAlignedFieldRect(rect); //左边缘是准的,实际有2f空隙。
|
||||
float x = leftAlignedFieldRect.x + 2f;
|
||||
float width = rectAfterLabelWidth.x + rectAfterLabelWidth.width - x;
|
||||
|
||||
var newRec = new Rect(x, rectAfterLabelWidth.y, width, rectAfterLabelWidth.height);
|
||||
|
||||
if (ignoreIndent)
|
||||
{
|
||||
float indent = (float)EditorGUI.indentLevel * 15f;
|
||||
newRec.x -= indent;
|
||||
newRec.width += indent;
|
||||
}
|
||||
|
||||
// // EditorGUI.DrawRect(leftRect,Color.red);
|
||||
// float biasWidth = EditorGUI.indentLevel * 15f - 2f;
|
||||
// leftRect.x -= biasWidth;
|
||||
// leftRect.width += biasWidth;
|
||||
// EditorGUI.DrawRect(leftRect,Color.green);
|
||||
return newRec;
|
||||
}
|
||||
|
||||
public void DrawTextureFoldOut(ref AnimBool foldOutAnimBool, string label, string texturePropertyName,
|
||||
string colorPropertyName = null, bool drawScaleOffset = true, bool drawWrapMode = false,
|
||||
int flagBitsName = 0, int flagIndex = 2, Action<Texture> drawBlock = null)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var rect = EditorGUILayout.GetControlRect();
|
||||
var foldoutRect = new Rect(rect.x, rect.y, rect.width - MaterialEditor.GetRectAfterLabelWidth(rect).width,
|
||||
rect.height);
|
||||
var textureThumbnialRect = new Rect(rect.x + 2f, rect.y, 14f, rect.height);
|
||||
var labelRect = new Rect(rect.x + 35f, rect.y, rect.width - 18f, rect.height);
|
||||
Texture texture =
|
||||
matEditor.TexturePropertyMiniThumbnail(textureThumbnialRect, GetProperty(texturePropertyName), "", "");
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
|
||||
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
|
||||
if (colorPropertyName != null)
|
||||
{
|
||||
Rect colorPropRect = GetRectAfterLabelWidth(rect, true);
|
||||
// colorPropRect.x -= EditorGUI.indentLevel
|
||||
Color color = matEditor.ColorProperty(colorPropRect, GetProperty(colorPropertyName), "");
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
float faded = foldOutAnimBool.faded;
|
||||
if (faded == 0) faded = 0.00001f;
|
||||
EditorGUILayout.BeginFadeGroup(faded);
|
||||
EditorGUI.BeginDisabledGroup(texture == null);
|
||||
|
||||
DrawAfterTexture(true, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName, flagIndex,
|
||||
drawBlock);
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
}
|
||||
|
||||
public void DrawTexture(string label, string texturePropertyName, string colorPropertyName = null,
|
||||
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
|
||||
Action<Texture> drawBlock = null)
|
||||
{
|
||||
bool hasTexture = mats[0].GetTexture(texturePropertyName) != null;
|
||||
matEditor.TexturePropertySingleLine(new GUIContent(label), GetProperty(texturePropertyName),
|
||||
GetProperty(colorPropertyName));
|
||||
DrawAfterTexture(hasTexture, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName,
|
||||
flagIndex, drawBlock);
|
||||
}
|
||||
|
||||
public void DrawAfterTexture(bool hasTexture, string label, string texturePropertyName,
|
||||
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
|
||||
Action<Texture> drawBlock = null)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUI.BeginDisabledGroup(!hasTexture);
|
||||
if (drawWrapMode)
|
||||
{
|
||||
//这个多选材质就不出现了,不好处理
|
||||
if (mats.Count == 1)
|
||||
{
|
||||
int tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex) ? 1 : 0;
|
||||
tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName << 16, index: flagIndex)
|
||||
? tmpWrapMode + 2
|
||||
: tmpWrapMode;
|
||||
tmpWrapMode = EditorGUILayout.Popup(new GUIContent(label + "循环模式"), tmpWrapMode,
|
||||
Enum.GetNames(typeof(SamplerWarpMode)));
|
||||
switch (tmpWrapMode)
|
||||
{
|
||||
case 0:
|
||||
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
|
||||
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
|
||||
break;
|
||||
case 1:
|
||||
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
|
||||
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
|
||||
break;
|
||||
case 2:
|
||||
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
|
||||
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
|
||||
break;
|
||||
case 3:
|
||||
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
|
||||
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drawScaleOffset)
|
||||
{
|
||||
matEditor.TextureScaleOffsetProperty(GetProperty(texturePropertyName));
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(GetProperty(texturePropertyName).textureValue);
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
|
||||
public void DrawPopUp(string label, string propertyName, string[] options, string[] toolTips = null,
|
||||
Action<float> drawBlock = null)
|
||||
{
|
||||
MaterialProperty property = GetProperty(propertyName);
|
||||
if (property == null) return;
|
||||
EditorGUI.showMixedValue = property.hasMixedValue;
|
||||
|
||||
float mode = property.floatValue;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GUIContent[] optionGUIContents = new GUIContent[options.Length];
|
||||
for (int i = 0; i < optionGUIContents.Length; i++)
|
||||
{
|
||||
if (toolTips != null && toolTips.Length == options.Length)
|
||||
{
|
||||
optionGUIContents[i] = new GUIContent(options[i], toolTips[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionGUIContents[i] = new GUIContent(options[i]);
|
||||
}
|
||||
}
|
||||
|
||||
mode = EditorGUILayout.Popup(new GUIContent(label), (int)mode, optionGUIContents);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
property.floatValue = mode;
|
||||
}
|
||||
|
||||
drawBlock?.Invoke(mode);
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public MaterialProperty GetProperty(string propertyName)
|
||||
{
|
||||
foreach (ShaderPropertyPack pack in ShaderPropertyPacks)
|
||||
{
|
||||
if (pack.name == propertyName)
|
||||
{
|
||||
return pack.property;
|
||||
}
|
||||
}
|
||||
|
||||
// Debug.LogError("材质球" + mat.name + "找不到属性" + propertyName, mat);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void DrawRenderQueue(MaterialProperty queueBiasProp)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("Queue:" + mats[0].renderQueue);
|
||||
int QueueBias = (int)queueBiasProp.floatValue;
|
||||
QueueBias = EditorGUILayout.IntField("QueueBias:", QueueBias);
|
||||
queueBiasProp.floatValue = QueueBias;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void GuiLine(int i_height = 1)
|
||||
{
|
||||
|
||||
Rect rect = EditorGUILayout.GetControlRect(false, i_height);
|
||||
rect.height = i_height;
|
||||
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
|
||||
}
|
||||
|
||||
public static float PowerSlider(Rect position, GUIContent label, float value, float leftValue, float rightValue,
|
||||
float power)
|
||||
{
|
||||
var editorGuiType = typeof(EditorGUI);
|
||||
var methodInfo = editorGuiType.GetMethod(
|
||||
"PowerSlider",
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static,
|
||||
null,
|
||||
new[] { typeof(Rect), typeof(GUIContent), typeof(float), typeof(float), typeof(float), typeof(float) },
|
||||
null);
|
||||
if (methodInfo != null)
|
||||
{
|
||||
return (float)methodInfo.Invoke(null,
|
||||
new object[] { position, label, value, leftValue, rightValue, power });
|
||||
}
|
||||
|
||||
return leftValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9279ba81938dc1548b9e9d8297bdcd57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
147
Packages/XuanXuanRenderUtility/Editor/StencilTestHelper.cs
Normal file
147
Packages/XuanXuanRenderUtility/Editor/StencilTestHelper.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
// using Sirenix.OdinInspector;
|
||||
// using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
namespace stencilTestHelper
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class StencilValues
|
||||
{
|
||||
public int DefaultQueue = 2000;
|
||||
[BinaryInt(8,true,2)]
|
||||
public int Ref = 0;
|
||||
public CompareFunction Comp = CompareFunction.Always;
|
||||
public StencilOp Pass = StencilOp.Keep;
|
||||
public StencilOp Fail = StencilOp.Keep;
|
||||
public StencilOp ZFail = StencilOp.Keep;
|
||||
[BinaryInt(8,true,1)]
|
||||
public int ReadMask = 255;
|
||||
[BinaryInt(8,true,1)]
|
||||
public int WriteMask = 255;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class StencilTestHelper
|
||||
{
|
||||
// private static StencilValuesConfig stencilValuesConfig;
|
||||
public class StencilPropertyNames
|
||||
{
|
||||
public string stencil = "_Stencil";
|
||||
public string stencilComp = "_StencilComp";
|
||||
public string stencilOp = "_StencilOp";
|
||||
public string stencilWriteMask = "_StencilWriteMask";
|
||||
public string stencilReadMask = "_StencilReadMask";
|
||||
public string stencilZFail = "_StencilZFail";
|
||||
public string stencilFail = "_StencilFail";
|
||||
|
||||
public StencilPropertyNames()
|
||||
{
|
||||
}
|
||||
|
||||
public StencilPropertyNames(string stencilName, string stencilCompName, string stencilOpName,
|
||||
string stencilWriteMaskName, string stencilReadMaskName, string stencilZFailName,
|
||||
string stencilFailName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(stencilName))
|
||||
{
|
||||
stencil = stencilName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilCompName))
|
||||
{
|
||||
stencilComp = stencilCompName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilOpName))
|
||||
{
|
||||
stencilOp = stencilOpName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilWriteMaskName))
|
||||
{
|
||||
stencilWriteMask = stencilWriteMaskName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilReadMaskName))
|
||||
{
|
||||
stencilReadMask = stencilReadMaskName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilZFailName))
|
||||
{
|
||||
stencilZFail = stencilZFailName;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilFailName))
|
||||
{
|
||||
stencilFail = stencilFailName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static StencilPropertyNames defaultStencilPropertyNames = new StencilPropertyNames();
|
||||
|
||||
// public static void SetMaterialStencil(Material mat,StencilValues stencilValues,out int defaultQueue)
|
||||
public static void SetMaterialStencil(Material mat, string stencilConfigKey,StencilValuesConfig stencilValuesConfig, out int defaultQueue,StencilPropertyNames stencilPropertyNames = null)
|
||||
{
|
||||
if (stencilValuesConfig == null)
|
||||
{
|
||||
Debug.LogError(mat.name+": 缺少模板预设,设置Stencil失败");
|
||||
// stencilValuesConfig =
|
||||
// AssetDatabase.LoadAssetAtPath<StencilValuesConfig>(
|
||||
// "Assets/AddressableAssets/Shader/StencilConfig.asset");
|
||||
}
|
||||
|
||||
|
||||
if (stencilPropertyNames == null)
|
||||
{
|
||||
stencilPropertyNames = defaultStencilPropertyNames;
|
||||
}
|
||||
|
||||
StencilValues stencilValues;
|
||||
if (stencilValuesConfig.ContainsKey(stencilConfigKey))
|
||||
{
|
||||
stencilValues = stencilValuesConfig[stencilConfigKey];
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencil))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencil, stencilValues.Ref);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilComp) )
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilComp, (float)stencilValues.Comp);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilOp))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilOp, (float)stencilValues.Pass);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilWriteMask))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilWriteMask, stencilValues.WriteMask);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilReadMask))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilReadMask, stencilValues.ReadMask);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilZFail))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilZFail, (float)stencilValues.ZFail);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilFail))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilFail, (float)stencilValues.Fail);
|
||||
}
|
||||
|
||||
defaultQueue = stencilValues.DefaultQueue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("无法设置材质模板参数,因为没有配置模板值", mat);
|
||||
defaultQueue = mat.renderQueue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7d6268a1ca7d824d8da2adf4cb8f74a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Packages/XuanXuanRenderUtility/Editor/StencilValuesConfig.cs
Normal file
60
Packages/XuanXuanRenderUtility/Editor/StencilValuesConfig.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace stencilTestHelper
|
||||
{
|
||||
|
||||
public class StencilValuesConfig : ScriptableObject
|
||||
{
|
||||
// public Dictionary<string, StencilValues> Config = new Dictionary<string, StencilValues>();
|
||||
// public StencilValuesConfigDictionary Config = new StencilValuesConfigDictionary();
|
||||
[Serializable]
|
||||
public class KeyStencilValues
|
||||
{
|
||||
public string key;
|
||||
public StencilValues Values;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
public List<KeyStencilValues> Config = new List<KeyStencilValues>();
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
if (GetStencilValues(key) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public StencilValues GetStencilValues(string key)
|
||||
{
|
||||
foreach (var item in Config)
|
||||
{
|
||||
if (item.key == key)
|
||||
{
|
||||
return item.Values;
|
||||
}
|
||||
}
|
||||
Debug.LogError("StencilValuesConfig: 不存在Key"+key);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public StencilValues this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetStencilValues(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9177edf81a5b2354490ec4d66c4c069d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
101
Packages/XuanXuanRenderUtility/Editor/StringListSerchProvider.cs
Normal file
101
Packages/XuanXuanRenderUtility/Editor/StringListSerchProvider.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class StringListSerchProvider : ScriptableObject , ISearchWindowProvider
|
||||
// public class StringListSerchProvider
|
||||
{
|
||||
|
||||
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
|
||||
{
|
||||
List<SearchTreeEntry> serchList = new List<SearchTreeEntry>();
|
||||
serchList.Add(new SearchTreeGroupEntry(new GUIContent("List"),0));
|
||||
List<string> listItemAfterSort = listItems.ToList();
|
||||
|
||||
sortListItems(ref listItemAfterSort);
|
||||
|
||||
List<string> groups = new List<string>();
|
||||
foreach (var item in listItemAfterSort)
|
||||
{
|
||||
string[] entryTitle = item.Split("/");
|
||||
string groupName = "";
|
||||
for (int i = 0; i < entryTitle.Length - 1; i++)
|
||||
{
|
||||
groupName += entryTitle[i];
|
||||
if (!groups.Contains(groupName))
|
||||
{
|
||||
serchList.Add(new SearchTreeGroupEntry(new GUIContent(entryTitle[i]),i+1));
|
||||
}
|
||||
groupName += "/";
|
||||
}
|
||||
|
||||
SearchTreeEntry entry = new SearchTreeEntry(new GUIContent(entryTitle.Last()));
|
||||
entry.level = entryTitle.Length;
|
||||
entry.userData = item;//这里是serch操作点击最后的返回值,是什么都可以的。
|
||||
// Debug.Log(entry.userData);
|
||||
serchList.Add(entry);
|
||||
}
|
||||
|
||||
|
||||
return serchList;
|
||||
|
||||
}
|
||||
|
||||
public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
|
||||
{
|
||||
string data = (string)searchTreeEntry.userData;
|
||||
onSetIndexCallback?.Invoke(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
private string[] listItems;
|
||||
private Action<string> onSetIndexCallback;
|
||||
public StringListSerchProvider(string[] items, Action<string> callBack)
|
||||
{
|
||||
listItems = items;
|
||||
onSetIndexCallback = callBack;
|
||||
}
|
||||
|
||||
public void Initialize(string[] items, Action<string> callBack)
|
||||
{
|
||||
listItems = items;
|
||||
onSetIndexCallback = callBack;
|
||||
}
|
||||
|
||||
// private List<string> sortListItems;
|
||||
|
||||
void sortListItems(ref List<string> list)
|
||||
{
|
||||
// sortListItems = listItems.ToList();
|
||||
list.Sort((a, b) =>
|
||||
{
|
||||
string[] splits1 = a.Split('/');
|
||||
string[] splits2 = b.Split('/');
|
||||
|
||||
for (int i = 0; i < splits1.Length; i++)
|
||||
{
|
||||
if (i >= splits2.Length)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int value = splits1[i].CompareTo(splits2[i]);
|
||||
if (value != 0)
|
||||
{
|
||||
if (splits1.Length != splits2.Length && (i == splits1.Length - 1 || i == splits2.Length - 1))
|
||||
{
|
||||
return splits1.Length < splits2.Length ? 1 : -1;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aec459410f5254c4bb4d42e7ec8b4b5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "com.xuanxuan.render.utility.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8495541fcd41b0c40b5b6e6e7a7639d1
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,187 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class RefreshMaterialInspectorWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("ArtTools/刷新选中材质球面板")]
|
||||
static void refershSelectMaterialInspector()
|
||||
{
|
||||
EditorWindow.GetWindow<RefreshMaterialInspectorWindow>("材质球刷新");
|
||||
}
|
||||
public static bool isRefreshing = false;
|
||||
List<Material> materials = new List<Material>();
|
||||
int i = 0;
|
||||
private void OnGUI()
|
||||
{
|
||||
if (GUILayout.Button("开始刷新材质面板"))
|
||||
{
|
||||
materials.Clear();
|
||||
foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(o);
|
||||
string fileExtension = Path.GetExtension(path);
|
||||
if (fileExtension == ".mat")
|
||||
{
|
||||
materials.Add((Material)o);
|
||||
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Debug.Log("刷新材质打开");
|
||||
|
||||
isRefreshing = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(materials.Count <= 0) return;
|
||||
if (i < materials.Count)
|
||||
{
|
||||
// isRefreshing = true;
|
||||
// SetNormalToUV1(materials[i]);
|
||||
Selection.activeObject = materials[i];
|
||||
Debug.Log(materials[i].name,materials[i]);
|
||||
EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Count}", (i + 1) / (float)materials.Count);
|
||||
i++;
|
||||
// isRefreshing = false;
|
||||
}
|
||||
if (i >= materials.Count)
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
materials.Clear();
|
||||
Debug.Log("材质刷新结束,isRefreshing布尔值 = "+isRefreshing);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
Debug.Log("刷新材质关闭");
|
||||
isRefreshing = false;
|
||||
|
||||
}
|
||||
|
||||
// void SetNormalToUV1(Material mat)
|
||||
// {
|
||||
// if (mat.HasProperty("_NormalFrom"))
|
||||
// {
|
||||
// mat.SetInteger("_NormalFrom",1);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // [MenuItem("Assets/测试刷新材质", priority = 1)]
|
||||
// public static void TestRefeshMaterial()
|
||||
// {
|
||||
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags();
|
||||
// int id = Shader.PropertyToID("_Mask2_Toggle");
|
||||
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
|
||||
// {
|
||||
// Material mat = o as Material;
|
||||
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
|
||||
// {
|
||||
// bool isToggle = mat.GetFloat(id) > 0.5f;
|
||||
// if (isToggle)
|
||||
// {
|
||||
// mat.DisableKeyword("_MASKMAP2");
|
||||
// flags.SetMaterial(mat);
|
||||
// flags.SetFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_MASK_MAP2,index:1);
|
||||
// }
|
||||
// // flags.SetMaterial(mat);
|
||||
// }
|
||||
// }
|
||||
// AssetDatabase.SaveAssets();
|
||||
// }
|
||||
//
|
||||
// [MenuItem("Assets/Effect Tool/刷新选中文件夹内材质Wrap模式", priority = 1)]
|
||||
// public static void SetSelectParticleMaterialWrapMode()
|
||||
// {
|
||||
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
|
||||
// {
|
||||
// Material mat = (Material)o;
|
||||
// // Debug.Log(mat.shader.name);
|
||||
// SetParticleMaterialWrapMode((Material)o);
|
||||
// }
|
||||
// AssetDatabase.SaveAssets();
|
||||
// }
|
||||
//
|
||||
// public static void SetParticleMaterialWrapMode(Material mat)
|
||||
// {
|
||||
//
|
||||
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
|
||||
// {
|
||||
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags(mat);
|
||||
// SetWrapModeFlag(flags,mat,"_BaseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_BASEMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_MaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_MaskMap2",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP2);
|
||||
// SetWrapModeFlag(flags,mat,"_NoiseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_NOISEMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_EmissionMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_EMISSIONMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_DissolveMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MAP);
|
||||
// SetWrapModeFlag(flags,mat,"_DissolveMaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_DissolveRampMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_ColorBlendMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_COLORBLENDMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_VertexOffset_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP);
|
||||
// SetWrapModeFlag(flags,mat,"_ParallaxMapping_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void SetParticleMaterialMaskStrenth(Material mat)
|
||||
// {
|
||||
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
|
||||
// {
|
||||
// Vector4 vec = mat.GetVector("_MaskMap3OffsetAnition");
|
||||
// if (vec.z < 1)
|
||||
// {
|
||||
// Vector4 newVec = new Vector4(vec.x, vec.y, 1, vec.w);
|
||||
// mat.SetVector("_MaskMap3OffsetAnition",newVec);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static void SetWrapModeFlag(W9ParticleShaderFlags flags, Material mat, string matTexPropertyName, int flagBit)
|
||||
// {
|
||||
// if (mat.GetTexture(matTexPropertyName) != null)
|
||||
// {
|
||||
// Texture tex = mat.GetTexture(matTexPropertyName);
|
||||
// Debug.Log(tex.name);
|
||||
// if (tex.wrapMode == TextureWrapMode.Clamp)
|
||||
// {
|
||||
// Debug.Log("This is Clamp");
|
||||
// flags.SetFlagBits(flagBit,index:2);
|
||||
// }
|
||||
// else if (tex.wrapMode == TextureWrapMode.Repeat)
|
||||
// {
|
||||
// Debug.Log("This is Repeat");
|
||||
// flags.ClearFlagBits(flagBit,index:2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// static IEnumerator refreshMaterialInspector(Material[] materials)
|
||||
// {
|
||||
// for (int i = 0; i < materials.Length; i++)
|
||||
// {
|
||||
// EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Length}", (i + 1) / (float)materials.Length);
|
||||
// Debug.Log(i);
|
||||
// // Selection.activeObject = materials[i];
|
||||
// yield return null;
|
||||
// }
|
||||
// EditorUtility.ClearProgressBar();
|
||||
// // yield break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 317bb692129be184ebd7249bba265210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/XuanXuanRenderUtility/Runtime.meta
Normal file
8
Packages/XuanXuanRenderUtility/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72e9a7523c1a5994c8fb317e7a9514e0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Packages/XuanXuanRenderUtility/Runtime/ButtonAttributes.cs
Normal file
57
Packages/XuanXuanRenderUtility/Runtime/ButtonAttributes.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public class InspectorButtonAttribute:PropertyAttribute
|
||||
{
|
||||
public string Label;
|
||||
public string MethodName;
|
||||
|
||||
public InspectorButtonAttribute(string label,string methodName)
|
||||
{
|
||||
this.Label = label;
|
||||
this.MethodName = methodName;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(InspectorButtonAttribute))]
|
||||
public class InspectorButtonPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
InspectorButtonAttribute buttonAttribute = (InspectorButtonAttribute)attribute;
|
||||
|
||||
|
||||
// 绘制按钮
|
||||
if (GUI.Button(position, buttonAttribute.Label))
|
||||
{
|
||||
// 获取包含该方法的对象
|
||||
var targetObject = property.serializedObject.targetObject;
|
||||
|
||||
// 获取方法信息
|
||||
var methodInfo = targetObject.GetType().GetMethod(buttonAttribute.MethodName,BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
if (methodInfo != null)
|
||||
{
|
||||
// 调用方法
|
||||
methodInfo.Invoke(targetObject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Method '{buttonAttribute.MethodName}' not found in {targetObject.name}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight; // 返回按钮的高度
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45f557806bb54c4dbeaec7a2ded5be83
|
||||
timeCreated: 1737792133
|
||||
562
Packages/XuanXuanRenderUtility/Runtime/MaterialPropertyAgent.cs
Normal file
562
Packages/XuanXuanRenderUtility/Runtime/MaterialPropertyAgent.cs
Normal file
@@ -0,0 +1,562 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
//TODO增加一键去重功能。测试排查BUG
|
||||
[ExecuteInEditMode]
|
||||
public class MaterialPropertyAgent : MonoBehaviour,IMaterialModifier
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct PropertyData
|
||||
{
|
||||
[HideInInspector] public int dataIndexInAgent;
|
||||
[HideInInspector] public MaterialPropertyAgent agent;
|
||||
[HideInInspector] public int id;
|
||||
|
||||
|
||||
public int index;
|
||||
[HideInInspector] public string propName;
|
||||
|
||||
public shaderPropertyType type;
|
||||
|
||||
|
||||
public string descripName;
|
||||
|
||||
|
||||
public Color colorValue;
|
||||
|
||||
public Vector4 vecValue;
|
||||
|
||||
public float floatValue;
|
||||
|
||||
[SerializeField] public IEnumerable propNameList;
|
||||
[HideInInspector] public bool isActive;
|
||||
[HideInInspector] public Shader shader;
|
||||
[HideInInspector] public Material mat;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public float rangMin { get; set; }
|
||||
public float rangMax { get; set; }
|
||||
|
||||
public void setValueByPropChange()
|
||||
{
|
||||
agent.refreshShderPropNameList();
|
||||
if (!agent.isCanUsedIndex(index))
|
||||
{
|
||||
index = agent.getCanUsedIndex();
|
||||
}
|
||||
|
||||
string propertyName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
|
||||
id = Shader.PropertyToID(propertyName);
|
||||
descripName = UnityEditor.ShaderUtil.GetPropertyDescription(shader, index);
|
||||
type = (shaderPropertyType) UnityEditor.ShaderUtil.GetPropertyType(shader, index);
|
||||
if (type == shaderPropertyType.TexEnv)
|
||||
{
|
||||
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case shaderPropertyType.Color:
|
||||
colorValue = mat.GetColor(id);
|
||||
break;
|
||||
case shaderPropertyType.Float:
|
||||
floatValue = mat.GetFloat(id);
|
||||
break;
|
||||
case shaderPropertyType.Range:
|
||||
rangMin = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 1);
|
||||
rangMax = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 2);
|
||||
floatValue = mat.GetFloat(id);
|
||||
break;
|
||||
case shaderPropertyType.Vector:
|
||||
vecValue = mat.GetVector(id);
|
||||
break;
|
||||
case shaderPropertyType.TexEnv:
|
||||
string stName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
|
||||
vecValue = mat.GetVector(stName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void inActivateThis()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//因为ShaderUtil只是用于Editor,所以复制一个枚举对属性类型进行识别。
|
||||
|
||||
public enum shaderPropertyType
|
||||
{
|
||||
//
|
||||
// 摘要:
|
||||
// Color Property.
|
||||
Color = 0,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Vector Property.
|
||||
Vector = 1,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Float Property.
|
||||
Float = 2,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Range Property.
|
||||
Range = 3,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Texture Property.
|
||||
TexEnv = 4
|
||||
}
|
||||
|
||||
|
||||
public PropertyData data0 = new PropertyData();
|
||||
|
||||
public PropertyData data1 = new PropertyData();
|
||||
|
||||
public PropertyData data2 = new PropertyData();
|
||||
|
||||
public PropertyData data3 = new PropertyData();
|
||||
|
||||
public PropertyData data4 = new PropertyData();
|
||||
|
||||
public PropertyData data5 = new PropertyData();
|
||||
|
||||
public Shader shader;
|
||||
public Material mat;
|
||||
|
||||
|
||||
public int materialIndex = 0;
|
||||
public Renderer customRenderer;
|
||||
|
||||
void initMatAndShader(bool initMat = false)
|
||||
{
|
||||
if (!initMat)
|
||||
{
|
||||
if (mat != null) return;
|
||||
}
|
||||
|
||||
if (customRenderer || GetComponent<Renderer>())
|
||||
{
|
||||
Material[] materials;
|
||||
Renderer r;
|
||||
if (customRenderer)
|
||||
{
|
||||
r = customRenderer;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = GetComponent<Renderer>();
|
||||
}
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
materials = r.materials;
|
||||
}
|
||||
else
|
||||
{
|
||||
materials = r.sharedMaterials;
|
||||
}
|
||||
|
||||
mat = materials[materialIndex];
|
||||
shader = mat.shader;
|
||||
}
|
||||
else if (this.GetComponent<Graphic>())
|
||||
{
|
||||
Graphic graphic = this.GetComponent<Graphic>();
|
||||
|
||||
//测试,要不要用IMaterialModifier来处理
|
||||
// if (Application.isPlaying)
|
||||
// {
|
||||
// graphic.material = Material.Instantiate(graphic.material);
|
||||
// }
|
||||
|
||||
mat = graphic.material;
|
||||
|
||||
|
||||
shader = mat.shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("MaterialPropertyAgent未找到材质", this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
initMatAndShader(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
initMatAndShader(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mat == null)
|
||||
{
|
||||
// initMatAndShader();
|
||||
return;
|
||||
}
|
||||
|
||||
updateData(data0);
|
||||
updateData(data1);
|
||||
updateData(data2);
|
||||
updateData(data3);
|
||||
updateData(data4);
|
||||
updateData(data5);
|
||||
}
|
||||
|
||||
void updateData(PropertyData data)
|
||||
{
|
||||
if (!data.isActive) return;
|
||||
if (mat == null) return;
|
||||
switch (data.type)
|
||||
{
|
||||
case shaderPropertyType.Color:
|
||||
mat.SetColor(data.propName, data.colorValue);
|
||||
break;
|
||||
case shaderPropertyType.Vector:
|
||||
case shaderPropertyType.TexEnv:
|
||||
mat.SetVector(data.propName, data.vecValue);
|
||||
break;
|
||||
case shaderPropertyType.Float:
|
||||
case shaderPropertyType.Range:
|
||||
mat.SetFloat(data.propName, data.floatValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//实际上是修改了graphic.materialForRendering
|
||||
public Material GetModifiedMaterial(Material baseMaterial)
|
||||
{
|
||||
if (mat)
|
||||
{
|
||||
return mat;
|
||||
}
|
||||
else
|
||||
{
|
||||
return baseMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void addProperteData()
|
||||
{
|
||||
refreshShderPropNameList();
|
||||
|
||||
if (!data0.isActive)
|
||||
{
|
||||
initData(ref data0, 0);
|
||||
}
|
||||
else if (!data1.isActive)
|
||||
{
|
||||
initData(ref data1, 1);
|
||||
}
|
||||
else if (!data2.isActive)
|
||||
{
|
||||
initData(ref data2, 2);
|
||||
}
|
||||
else if (!data3.isActive)
|
||||
{
|
||||
initData(ref data3, 3);
|
||||
}
|
||||
else if (!data4.isActive)
|
||||
{
|
||||
initData(ref data4, 4);
|
||||
}
|
||||
else if (!data5.isActive)
|
||||
{
|
||||
initData(ref data5, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("已用掉可用的6个属性");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllProperty()
|
||||
{
|
||||
data0.isActive = false;
|
||||
data1.isActive = false;
|
||||
data2.isActive = false;
|
||||
data3.isActive = false;
|
||||
data4.isActive = false;
|
||||
data5.isActive = false;
|
||||
}
|
||||
|
||||
public void initData(ref PropertyData data, int dataIndexInAgent)
|
||||
{
|
||||
data.dataIndexInAgent = dataIndexInAgent;
|
||||
data.agent = this;
|
||||
data.shader = shader;
|
||||
data.mat = mat;
|
||||
data.isActive = true;
|
||||
|
||||
data.index = getCanUsedIndex();
|
||||
data.setValueByPropChange();
|
||||
}
|
||||
|
||||
#region TODO自动排除已用Property
|
||||
|
||||
List<string> usedPropertyName = new List<string>();
|
||||
|
||||
void collectUsedPropName()
|
||||
{
|
||||
usedPropertyName.Clear();
|
||||
if (data0.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data0.propName);
|
||||
}
|
||||
|
||||
if (data1.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data1.propName);
|
||||
}
|
||||
|
||||
if (data2.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data2.propName);
|
||||
}
|
||||
|
||||
if (data3.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data3.propName);
|
||||
}
|
||||
|
||||
if (data4.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data4.propName);
|
||||
}
|
||||
|
||||
if (data5.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data5.propName);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCanUsedIndex()
|
||||
{
|
||||
int index = -1;
|
||||
collectUsedPropName();
|
||||
for (int i = 0; i < shaderPropNameArr.Length; i++)
|
||||
{
|
||||
string propertyName;
|
||||
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
|
||||
{
|
||||
propertyName = shaderPropNameArr[i] + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = shaderPropNameArr[i];
|
||||
}
|
||||
|
||||
if (usedPropertyName.Contains(propertyName)) continue;
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public bool isCanUsedIndex(int i)
|
||||
{
|
||||
string propertyName;
|
||||
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
|
||||
{
|
||||
propertyName = shaderPropNameArr[i] + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = shaderPropNameArr[i];
|
||||
}
|
||||
|
||||
collectUsedPropName();
|
||||
if (usedPropertyName.Contains(propertyName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string[] shaderPropNameArr;
|
||||
public string[] shaderPropDescripArr;
|
||||
public string[] shaderPropDescripsForSerch;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
// if (XLuaManager.Instance != null)
|
||||
// {
|
||||
// if (XLuaManager.Instance.HasGameStart)//判断是游戏运行状态才进行实例化
|
||||
// {
|
||||
// return;//游戏进行中不允许编辑
|
||||
// }
|
||||
// }
|
||||
// Debug.Log("MaterialPropertyAgent : " + "OnValidate");
|
||||
refreshShderPropNameList();
|
||||
if (TryGetComponent<Renderer>(out Renderer r)||customRenderer)
|
||||
{
|
||||
isRendererMode = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isRendererMode = false;
|
||||
}
|
||||
|
||||
if (TryGetComponent<Renderer>(out Renderer r2) || TryGetComponent<Graphic>(out Graphic g))
|
||||
{
|
||||
isGetByComponet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isGetByComponet = false;
|
||||
}
|
||||
}
|
||||
public bool isRendererMode = false;
|
||||
public bool isGetByComponet = false;
|
||||
public void initMatAndShaderByMaterialIndexChange()
|
||||
{
|
||||
initMatAndShader(true);
|
||||
refreshShderPropNameList();
|
||||
if (data0.isActive && data0.shader != mat.shader) {data0.shader = mat.shader;data0.mat = mat;}
|
||||
if (data1.isActive && data1.shader != mat.shader) {data1.shader = mat.shader;data1.mat = mat;}
|
||||
if (data2.isActive && data2.shader != mat.shader) {data2.shader = mat.shader;data2.mat = mat;}
|
||||
if (data3.isActive && data3.shader != mat.shader) {data3.shader = mat.shader;data3.mat = mat;}
|
||||
if (data4.isActive && data4.shader != mat.shader) {data4.shader = mat.shader;data4.mat = mat;}
|
||||
if (data5.isActive && data5.shader != mat.shader) {data5.shader = mat.shader;data5.mat = mat;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<string> shaderPropNameList = new List<string>();
|
||||
private List<string> shaderPropDescripList = new List<string>();
|
||||
private List<string> shaderPropDescripListForSerch = new List<string>();
|
||||
public void refreshShderPropNameList()
|
||||
{
|
||||
initMatAndShader();
|
||||
if (shader == null) return;
|
||||
|
||||
shaderPropNameList.Clear();
|
||||
shaderPropDescripList.Clear();
|
||||
shaderPropDescripListForSerch.Clear();
|
||||
for (int i = 0; i < UnityEditor.ShaderUtil.GetPropertyCount(shader); i++)
|
||||
{
|
||||
shaderPropNameList.Add(UnityEditor.ShaderUtil.GetPropertyName(shader, i));
|
||||
string descript = UnityEditor.ShaderUtil.GetPropertyDescription(shader, i);
|
||||
shaderPropDescripList.Add(descript);
|
||||
string lowerDesc = descript.ToLower();
|
||||
if (!(lowerDesc.Contains("ignore") || lowerDesc.Contains("mode") || lowerDesc.Contains("toggle") ||
|
||||
lowerDesc.Contains("enable") || lowerDesc.Contains("flag")))
|
||||
{
|
||||
shaderPropDescripListForSerch.Add(descript);
|
||||
}
|
||||
}
|
||||
|
||||
shaderPropNameArr = shaderPropNameList.ToArray();
|
||||
shaderPropDescripArr = shaderPropDescripList.ToArray();
|
||||
shaderPropDescripsForSerch = shaderPropDescripListForSerch.ToArray();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
[CustomPropertyDrawer(typeof(MaterialPropertyAgent.PropertyData))]
|
||||
public class PropertyAgentPropertyDataDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var isActive = property.FindPropertyRelative("isActive");
|
||||
if (isActive.boolValue)
|
||||
{
|
||||
EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var index = property.FindPropertyRelative("index");
|
||||
MaterialPropertyAgent agent = property.FindPropertyRelative("agent").objectReferenceValue as MaterialPropertyAgent;
|
||||
int preservedIndex = index.intValue;
|
||||
float originLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 80;
|
||||
index.intValue = EditorGUILayout.Popup("属性名:", index.intValue, agent.shaderPropNameArr);
|
||||
if (preservedIndex != index.intValue)//证明用户进行了更改
|
||||
{
|
||||
if (!agent.isCanUsedIndex(index.intValue))
|
||||
{
|
||||
//TODO给一个报错提示
|
||||
Debug.Log(ShaderUtil.GetPropertyDescription(agent.shader, index.intValue));
|
||||
index.intValue = agent.getCanUsedIndex();
|
||||
}
|
||||
//此处进行内容刷新
|
||||
data.setValueByPropChange();
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = originLabelWidth;
|
||||
switch (data.type)
|
||||
{
|
||||
case MaterialPropertyAgent.shaderPropertyType.Color:
|
||||
data.colorValue = EditorGUILayout.ColorField(data.descripName + " :", data.colorValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Vector:
|
||||
data.vecValue = EditorGUILayout.Vector4Field(data.descripName + " :", data.vecValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Float:
|
||||
data.floatValue = EditorGUILayout.FloatField(data.descripName + ":", data.floatValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Range:
|
||||
data.floatValue = EditorGUILayout.Slider(data.descripName + ":", data.floatValue, data.rangMin, data.rangMax);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
|
||||
data.vecValue = EditorGUILayout.Vector4Field(data.propName + "_ST:", data.vecValue);
|
||||
break;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
|
||||
{
|
||||
data.isActive = false;
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 781e80efab11a1d438f7c4d37603bdff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Packages/XuanXuanRenderUtility/Runtime/ShaderFlagsBase.cs
Normal file
105
Packages/XuanXuanRenderUtility/Runtime/ShaderFlagsBase.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class ShaderFlagsBase
|
||||
{
|
||||
|
||||
private Material _material;
|
||||
|
||||
public Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
return _material;
|
||||
}
|
||||
}
|
||||
|
||||
protected ShaderFlagsBase(Material material)
|
||||
{
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public void SetMaterial(Material material)
|
||||
{
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public Material GetMaterial()
|
||||
{
|
||||
return _material;
|
||||
}
|
||||
|
||||
protected abstract int GetShaderFlagsId(int index = 0);
|
||||
protected abstract string GetShaderFlagsName(int index = 0);
|
||||
|
||||
private void SetIntValue(Material material, int flagBits,int index = 0)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// SerializedObject serializedObject = new SerializedObject(_material);
|
||||
// SerializedProperty serializedProperty = serializedObject.FindProperty("m_SavedProperties");
|
||||
// serializedProperty = serializedProperty.FindPropertyRelative("m_Floats");
|
||||
// for (int index = serializedProperty.arraySize - 1; index >= 0; index--)
|
||||
// {
|
||||
// var property = serializedProperty.GetArrayElementAtIndex(index);
|
||||
// string propertyName = property.displayName;
|
||||
// if (propertyName == "_W9PBRStandardShaderFlags")
|
||||
// {
|
||||
// var propertyType = property.propertyType;
|
||||
// Debug.Log("xxx: "+propertyType);
|
||||
//
|
||||
//
|
||||
// property.floatValue = (float) (flags | flagBits);
|
||||
// }
|
||||
// }
|
||||
// material.SetInt(GetShaderFlagsName(), flagBits);
|
||||
material.SetInteger(GetShaderFlagsId(index), flagBits);
|
||||
#else
|
||||
material.SetInteger(GetShaderFlagsId(index), flagBits);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) return;
|
||||
int flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
SetIntValue(_material, flags | flagBits,index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int flags = propertyBlock.GetInt(GetShaderFlagsId(index));
|
||||
propertyBlock.SetInt(GetShaderFlagsId(index), flags|flagBits);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) return;
|
||||
int flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
SetIntValue(_material, flags&~flagBits,index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
|
||||
propertyBlock.SetInteger(GetShaderFlagsId(index), flags&~flagBits);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
int flags = 0;
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) throw new NullReferenceException("material");
|
||||
flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
}
|
||||
else
|
||||
{
|
||||
flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
|
||||
}
|
||||
return (flags & flagBits) != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bcf591e67bd470e9375d72c63838643
|
||||
timeCreated: 1655437380
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "com.xuanxuan.render.utility",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9e4d586616f13449cfeb86c5f704c2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/XuanXuanRenderUtility/Shader.meta
Normal file
8
Packages/XuanXuanRenderUtility/Shader.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97647516635f92f43a6cd4807c3899d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user