新增unity的牛逼shader和熊猫超级shader

This commit is contained in:
Abin committed 2026-03-10 18:34:45 +08:00
1 parent 6001f6d87a
commit 1a4cd29e7c
216 files changed
+41947

No files matched your search

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="91023a6b-e90c-4b7e-ad29-2c758b62337b" name="更改" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 1
}]]></component>
<component name="ProjectId" id="2woZni0kkDvAva6vMvSRxXle59k" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="默认任务">
<changelist id="91023a6b-e90c-4b7e-ad29-2c758b62337b" name="更改" comment="" />
<created>1746710058620</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1746710058620</updated>
<workItem from="1746710064595" duration="3599000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>
@@ -0,0 +1,45 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEngine;
using NBShader;
namespace NBShaderEditor
{
public class NBShaderGUI:ShaderGUI
{
NBShaderRootItem NBRootItem = new NBShaderRootItem();
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
NBRootItem.OnGUI(materialEditor, properties);
}
}
public class NBShaderRootItem:ShaderGUIRootItem
{
public override void InitFlags(List<Material> mats)
{
ShaderFlags = new List<ShaderFlagsBase>();
foreach (Material mat in mats)
{
W9ParticleShaderFlags flag = new W9ParticleShaderFlags(mat);
ShaderFlags.Add(flag);
}
}
public ModeBigBlockItem modeBigBlock;
public BaseOptionBigBlockItem baseOptionBigBlock;
public override void OnChildOnGUI()
{
if (IsInit)
{
modeBigBlock = new ModeBigBlockItem(this,null);
baseOptionBigBlock = new BaseOptionBigBlockItem(this,null);
}
modeBigBlock.OnGUI();
baseOptionBigBlock.OnGUI();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1b18ce80080b45c7a5b2a0f8cc2492d7
timeCreated: 1758206263
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 50e1a495cb24f82429902d4d23679f43
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace NBShaderEditor
{
public class BaseOptionBigBlockItem:ShaderGUIBigBlockItem
{
public BaseOptionBigBlockItem(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) :
base(rootItem, parentItem: parentItem)
{
GuiContent = new GUIContent("基本全局功能", "全局控制功能");
FoldOutPropertyName = "_BaseOptionBigBlockItemFoldOut";
_baseColorIntensityItem = new BaseColorIntensityItem(rootItem, this);
_alphaAllItem = new AlphaAllItem(rootItem, this);
_zTestItem = new ZTestItem(rootItem, this);
base.InitTriggerByChild();
}
BaseColorIntensityItem _baseColorIntensityItem;
AlphaAllItem _alphaAllItem;
ZTestItem _zTestItem;
public override void DrawBlock()
{
_baseColorIntensityItem.OnGUI();
_alphaAllItem.OnGUI();
_zTestItem.OnGUI();
}
}
public class BaseColorIntensityItem:ShaderGUIFloatItem
{
public BaseColorIntensityItem(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem: parentItem)
{
PropertyName = "_BaseColorIntensityForTimeline";
GuiContent = new GUIContent("整体颜色强度", "");
base.InitTriggerByChild();
}
}
public class AlphaAllItem:ShaderGUISliderItem
{
public AlphaAllItem(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem: parentItem)
{
PropertyName = "_AlphaAll";
GuiContent = new GUIContent("整体透明度");
RangePropertyName = "AlphaAllRangeVec";
base.InitTriggerByChild();
}
}
public class ZTestItem : ShaderGUIPopUpItem
{
public ZTestItem(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem: parentItem)
{
PropertyName = "_ZTest";
GuiContent = new GUIContent("深度测试");
PopUpNames = Enum.GetNames(typeof(CompareFunction));
base.InitTriggerByChild();
}
public override void OnGUI()
{
MixedBool uiEffectEnabled = MeshModePopUp.MeshSourceModeDic[RootItem].UIEffectEnabled();
if (uiEffectEnabled == MixedBool.True)
{
if (!Mathf.Approximately(PropertyInfo.Property.floatValue,(float)CompareFunction.LessEqual))
{
PropertyInfo.Property.floatValue = (float)CompareFunction.LessEqual;
}
return; //UIEffeect不应比较深度
}
else if (uiEffectEnabled == MixedBool.Mixed)
{
return;
}
base.OnGUI();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 135aa1fd916c4155b15cada119fdf3fd
timeCreated: 1758549245
@@ -0,0 +1,385 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBShaderEditor
{
public class ModeBigBlockItem:ShaderGUIBigBlockItem
{
public ModeBigBlockItem(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem: parentItem)
{
GuiContent = new GUIContent("模式设置", "各种基础模式设置");
FoldOutPropertyName = "_BigBlockModeSettingFoldOut";
_meshModePopUp = new MeshModePopUp(rootItem, this);
_transparentMode = new TransparentModePopUp(rootItem, this);
base.InitTriggerByChild();
}
private MeshModePopUp _meshModePopUp;
private TransparentModePopUp _transparentMode;
public override void DrawBlock()
{
_meshModePopUp.OnGUI();
_transparentMode.OnGUI();
}
}
public enum MeshSourceMode
{
Particle,
Mesh,
UIEffectRawImage,
UIEffectSprite,
UIEffectBaseMap,
UIParticle,
UnKnowOrMixed = -1
}
public class MeshModePopUp : ShaderGUIPopUpItem,IDisposable
{
public MeshSourceMode MeshSourceMode;
public static Dictionary<ShaderGUIRootItem,MeshModePopUp> MeshSourceModeDic = new Dictionary<ShaderGUIRootItem,MeshModePopUp>();
public MeshModePopUp(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) :
base(rootItem, parentItem: parentItem)
{
PopUpNames = new[]
{
"粒子系统",
"模型(非粒子发射)",
"2D RawImage",
"2D 精灵",
"2D 材质贴图",
"2D UIParticle"
};
PropertyName = "_MeshSourceMode";
GuiContent = new GUIContent("Mesh来源模式", "Mesh来源模式和当前的对象类型一致");
MeshSourceModeDic.Add(rootItem,this);
InitTriggerByChild();
}
public MixedBool UIEffectEnabled()
{
if ((int)MeshSourceMode >= 2)
{
return MixedBool.True;
}
else if (MeshSourceMode == MeshSourceMode.UnKnowOrMixed)
{
return MixedBool.Mixed;
}
else
{
return MixedBool.False;
}
}
public override void OnGUI()
{
base.OnGUI();
if (PropertyInfo.Property.hasMixedValue)
{
MeshSourceMode = MeshSourceMode.UnKnowOrMixed;
}
else
{
MeshSourceMode = (MeshSourceMode)PropertyInfo.Property.floatValue;
}
}
public void Dispose()
{
MeshSourceModeDic.Remove(RootItem);
}
}
public enum TransparentMode
{
Opaque = 0,
Transparent = 1,
CutOff = 2,
UnKnowOrMixed = -1
}
public class TransparentModePopUp : ShaderGUIPopUpItem,IDisposable
{
public TransparentMode TransparentMode;
public static Dictionary<ShaderGUIRootItem,TransparentModePopUp> TransparentModeDic =
new Dictionary<ShaderGUIRootItem, TransparentModePopUp>();
public TransparentModePopUp(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) :
base(rootItem, parentItem: parentItem)
{
PopUpNames = new[]
{
"不透明Opaque",
"半透明Transparent",
"不透明裁剪CutOff"
};
PropertyName = "_TransparentMode";
GuiContent = new GUIContent("透明模式", "透明模式");
TransparentModeDic.Add(RootItem,this);
_cutOffSlider = new CutOffSlider(RootItem, this);
_blendPopUp = new BlendPopUp(RootItem, this);
PropertyInfo = RootItem.PropertyInfoDic[PropertyName];
TransparentMode = (TransparentMode)PropertyInfo.Property.floatValue;
InitTriggerByChild();
}
public override void OnGUI()
{
base.OnGUI();
if (PropertyInfo.Property.hasMixedValue)
{
TransparentMode = TransparentMode.UnKnowOrMixed;
}
else
{
TransparentMode = (TransparentMode)PropertyInfo.Property.floatValue;
}
}
private CutOffSlider _cutOffSlider;
private BlendPopUp _blendPopUp;
public override void DrawBlock()
{
if (TransparentMode== TransparentMode.CutOff)
{
_cutOffSlider.OnGUI();
}
if (TransparentMode == TransparentMode.Transparent)
{
_blendPopUp.OnGUI();
}
}
public override void OnEndChange()
{
TransparentMode = (TransparentMode)PropertyInfo.Property.floatValue;
ShaderPropertyInfo zWritePropInfo = RootItem.PropertyInfoDic["_ZWrite"];//TODO ModifyToZWriteToggleGUI
ShaderPropertyInfo queueBiasPropInfo = RootItem.PropertyInfoDic["_QueueBias"];//TODO ModifyToQueueBiasGUI
switch (TransparentMode)
{
case TransparentMode.Opaque:
zWritePropInfo.Property.floatValue = 1;
foreach (var mat in RootItem.Mats)
{
mat.renderQueue = 2100 + (int)queueBiasPropInfo.Property.floatValue; //3D粒子永远最前显示
}
_blendPopUp.PropertyInfo.Property.floatValue = (float)BlendMode.Opaque;
_blendPopUp.OnEndChange();
break;
case TransparentMode.Transparent:
zWritePropInfo.Property.floatValue = 0;
foreach (var mat in RootItem.Mats)
{
mat.renderQueue = 3000 + (int)queueBiasPropInfo.Property.floatValue;
}
if (_blendPopUp.BlendMode == BlendMode.Opaque)
{
_blendPopUp.PropertyInfo.Property.floatValue = (float)BlendMode.Alpha;//如果设置错误则强制设置。
_blendPopUp.OnEndChange();
}
break;
case TransparentMode.CutOff:
zWritePropInfo.Property.floatValue = 1;
foreach (var mat in RootItem.Mats)
{
mat.renderQueue = 2450 + (int)queueBiasPropInfo.Property.floatValue; //3D粒子永远最前显示
}
_blendPopUp.PropertyInfo.Property.floatValue = (float)BlendMode.Opaque;
_blendPopUp.OnEndChange();
break;
}
foreach (var mat in RootItem.Mats)
{
if (TransparentMode == TransparentMode.CutOff)
{
mat.EnableKeyword("_ALPHATEST_ON");
}
else
{
mat.DisableKeyword("_ALPHATEST_ON");
}
}
base.OnEndChange();
}
public void Dispose()
{
TransparentModeDic.Remove(RootItem);//回收时清掉相关引用。?会不会有时序问题
}
}
public class CutOffSlider:ShaderGUISliderItem
{
public CutOffSlider(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem)
{
PropertyName = "_Cutoff";
GuiContent = new GUIContent("裁剪位置", "0为完全不裁剪,1为完全裁剪");
base.InitTriggerByChild();
}
}
public enum BlendMode
{
Alpha, // Old school alpha-blending mode, fresnel does not affect amount of transparency
Premultiply, // Physically plausible transparency mode, implemented as alpha pre-multiply
Additive,
Multiply,
Opaque,
UnKnowOrMixed = -1
}
public class BlendPopUp : ShaderGUIPopUpItem,IDisposable
{
public BlendMode BlendMode;
public static Dictionary<ShaderGUIRootItem,BlendPopUp> BlendModeDic = new Dictionary<ShaderGUIRootItem,BlendPopUp>();
public BlendPopUp(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem)
{
PropertyName = "_Blend";
PopUpNames = new[]
{
"透明度混合AlphaBlend",
"预乘PreMultiply",
"叠加Additive",
"正片叠底Multiply"
};
GuiContent = new GUIContent("混合模式");
BlendModeDic.Add(rootItem,this);
_addToPreMultiplySlider = new AddToPreMultiplySlider(rootItem, this);
InitTriggerByChild();
}
public override void OnGUI()
{
base.OnGUI();
if (PropertyInfo.Property.hasMixedValue)
{
BlendMode = BlendMode.UnKnowOrMixed;
}
else
{
BlendMode = (BlendMode)PropertyInfo.Property.floatValue;
}
}
private AddToPreMultiplySlider _addToPreMultiplySlider;
public override void DrawBlock()
{
if (BlendMode == BlendMode.Additive || BlendMode == BlendMode.Premultiply)
{
_addToPreMultiplySlider.OnGUI();
}
}
public override void OnEndChange()
{
BlendMode = (BlendMode)PropertyInfo.Property.floatValue;
if (BlendMode == BlendMode.Additive)
{
_addToPreMultiplySlider.PropertyInfo.Property.floatValue = 0;
_addToPreMultiplySlider.OnEndChange();
}
if (BlendMode == BlendMode.Premultiply)
{
_addToPreMultiplySlider.PropertyInfo.Property.floatValue = 1;
_addToPreMultiplySlider.OnEndChange();
}
foreach (var mat in RootItem.Mats)
{
switch (BlendMode)
{
case BlendMode.Alpha:
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
mat.DisableKeyword("_ALPHAMODULATE_ON");
break;
case BlendMode.Premultiply:
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.EnableKeyword("_ALPHAPREMULTIPLY_ON");
mat.DisableKeyword("_ALPHAMODULATE_ON");
break;
case BlendMode.Additive:
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.EnableKeyword("_ALPHAPREMULTIPLY_ON");
mat.DisableKeyword("_ALPHAMODULATE_ON");
break;
case BlendMode.Multiply:
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
mat.EnableKeyword("_ALPHAMODULATE_ON");
break;
case BlendMode.Opaque:
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
break;
}
}
base.OnEndChange();
}
public void Dispose()
{
BlendModeDic.Remove(RootItem);
}
}
public class AddToPreMultiplySlider : ShaderGUISliderItem
{
public AddToPreMultiplySlider(ShaderGUIRootItem rootItem, ShaderGUIItem parentItem) : base(rootItem, parentItem)
{
PropertyName = "_AdditiveToPreMultiplyAlphaLerp";
GuiContent = new GUIContent("叠加到预乘混合", "0为叠加混合,1为预乘混合");
base.InitTriggerByChild();
}
public override void CheckIsPropertyModified(bool isCallByChild = false)
{
float defaultValue = 0;
BlendPopUp blendPopUp = BlendPopUp.BlendModeDic[RootItem];
if (blendPopUp.BlendMode == BlendMode.Premultiply)
{
defaultValue = 1;
}
HasModified = !Mathf.Approximately(defaultValue,PropertyInfo.Property.floatValue);
ParentItem?.CheckIsPropertyModified(true);
}
public override void ExecuteReset(bool isCallByParent = false)
{
float defaultValue = 0;
BlendPopUp blendPopUp = BlendPopUp.BlendModeDic[RootItem];
if (blendPopUp.BlendMode == BlendMode.Premultiply)
{
defaultValue = 1;
}
PropertyInfo.Property.floatValue = defaultValue;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ed09665b113c407dbfb8c818b74f48aa
timeCreated: 1758445745
@@ -0,0 +1,20 @@
{
"name": "com.xuanxuan.nb.shaders2.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: 6e0dde26488c0e44a9afcddc82a907e9
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: