This commit is contained in:
SoulliesOfficial
2025-12-17 04:19:38 -05:00
parent 7c1cb7e8e1
commit d15957c719
4315 changed files with 8260710 additions and 2940 deletions

View File

@@ -0,0 +1,137 @@
#if UNITY_EDITOR
using GraphicsCat.MarkupShaderGUIInternal;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace GraphicsCat
{
public class MarkupShaderGUI : ShaderGUI
{
public class Context
{
public Shader shader;
public MaterialEditor materialEditor;
public Material[] materials;
public MaterialProperty[] materialProperties;
public MaterialProperty materialProperty;
public string[] attributes;
public string attribute;
}
private Context m_Context = new();
private MarkupShaderGUIInternal.RenderSettings m_RenderSettingsTag = new();
private Foldout m_FoldoutTag = new();
private ShowIf m_ShowIfTag = new();
private EnableIf m_EnableIfTag = new();
private Separator m_SeparatorTag = new();
private Label m_LabelTag = new();
private MiniTextureWithColor m_MiniTextureWithColorTag = new();
private LightmapEmissionFlags m_LightmapEmissionFlags = new();
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] materialProperties)
{
Material material = materialEditor.target as Material;
if (material == null)
return;
Shader shader = material.shader;
if (shader == null)
return;
m_Context.shader = shader;
m_Context.materialEditor = materialEditor;
m_Context.materials = materialEditor.targets.Cast<Material>().ToArray();
m_Context.materialProperties = materialProperties;
GUILayout.Space(2f);
bool hasRenderSettings = false;
for (int propIndex = 0; propIndex < materialProperties.Length; propIndex++)
{
m_Context.materialProperty = materialProperties[propIndex];
m_Context.attributes = shader.GetPropertyAttributes(propIndex);
foreach (var attribute in m_Context.attributes)
{
m_Context.attribute = attribute;
if (attribute.IndexOf("RenderSettings") != -1)
{
hasRenderSettings = true;
m_RenderSettingsTag.InitNewMaterials(m_Context);
}
m_FoldoutTag.Process(m_Context);
m_ShowIfTag.Process(m_Context);
m_EnableIfTag.Process(m_Context);
m_MiniTextureWithColorTag.Process(m_Context);
var hideInFoldout = m_FoldoutTag.inScope && !m_FoldoutTag.state;
var hideInShowIf = m_ShowIfTag.inScope && !m_ShowIfTag.state;
if (hideInFoldout || hideInShowIf)
continue;
if (m_EnableIfTag.inScope)
GUI.enabled = m_EnableIfTag.state;
m_RenderSettingsTag.Process(m_Context);
m_SeparatorTag.Process(m_Context);
m_LabelTag.Process(m_Context);
m_LightmapEmissionFlags.Process(m_Context);
GUI.enabled = true;
}
if (m_RenderSettingsTag.inScope)
continue;
if (m_FoldoutTag.inScope && !m_FoldoutTag.state)
continue;
if (m_ShowIfTag.inScope && !m_ShowIfTag.state)
continue;
ShaderPropertyFlags propFlags = shader.GetPropertyFlags(propIndex);
if ((propFlags & ShaderPropertyFlags.HideInInspector) != 0)
continue;
if (m_EnableIfTag.inScope)
GUI.enabled = m_EnableIfTag.state;
if (m_MiniTextureWithColorTag.inScope && m_MiniTextureWithColorTag.state)
{
var isTextureType = (m_Context.materialProperty.propertyType == ShaderPropertyType.Texture);
if (isTextureType)
{
if (propIndex < materialProperties.Length - 1)
{
var nextPropIndex = propIndex + 1;
var nextProp = materialProperties[nextPropIndex];
var nextPropIsColorType = (nextProp.propertyType == ShaderPropertyType.Color);
if (nextPropIsColorType)
m_MiniTextureWithColorTag.Draw(m_Context.materialProperty, materialEditor);
}
}
}
else
{
var guiContent = GUIUtils.TempContent(m_Context.materialProperty.displayName);
materialEditor.ShaderProperty(m_Context.materialProperty, guiContent);
}
}
if (hasRenderSettings == false)
{
materialEditor.RenderQueueField();
materialEditor.DoubleSidedGIField();
}
GUI.enabled = true;
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 71217df46f6890e4e9d9bacc9db95f61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/MarkupShaderGUI.cs
uploadId: 820558

View File

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

View File

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

View File

@@ -0,0 +1,33 @@
#if UNITY_EDITOR
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class Tag
{
public bool inScope = false;
public bool state = false;
protected virtual string m_beginTag => "BeginTag";
protected virtual string m_EndTag => "EndTag";
public void Process(MarkupShaderGUI.Context context)
{
if (context.attribute.StartsWith(m_beginTag))
{
inScope = true;
OnBegin(context);
}
if (context.attribute.StartsWith(m_EndTag))
{
OnEnd();
inScope = false;
}
}
public virtual void OnBegin(MarkupShaderGUI.Context context) { }
public virtual void OnEnd() { }
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 10c2a44e2e696714aac0ae41c83b30fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Common/Tag.cs
uploadId: 820558

View File

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

View File

@@ -0,0 +1,63 @@
#if UNITY_EDITOR
using System;
using System.Linq;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class ConditionalTag : Tag
{
override public void OnBegin(MarkupShaderGUI.Context context)
{
var args = AttributeUtils.ExtractArgs(context.attribute);
if (args.Count < 3)
return;
var comparePropName = args[0];
var compareMode = args[1];
var compareValue = Convert.ToSingle(args[2]);
var compareProp = context.materialProperties.FirstOrDefault(p => p.name == comparePropName);
if (compareProp.hasMixedValue)
{
state = false;
return;
}
switch (compareMode)
{
case "Less":
if (compareProp.floatValue >= compareValue)
state = false;
break;
case "Equal":
if (compareProp.floatValue != compareValue)
state = false;
break;
case "LessEqual":
if (compareProp.floatValue > compareValue)
state = false;
break;
case "Greater":
if (compareProp.floatValue <= compareValue)
state = false;
break;
case "NotEqual":
if (compareProp.floatValue == compareValue)
state = false;
break;
case "GreaterEqual":
if (compareProp.floatValue < compareValue)
state = false;
break;
}
}
override public void OnEnd()
{
state = true;
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9ea8285fb70ac2b4fa2c9ee791e39aa9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/ConditionalTag.cs
uploadId: 820558

View File

@@ -0,0 +1,12 @@
#if UNITY_EDITOR
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class EnableIf : ConditionalTag
{
protected override string m_beginTag => "BeginEnableIf";
protected override string m_EndTag => "EndEnableIf";
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9c871a475490c264fb301ca8d1d318bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/EnableIf.cs
uploadId: 820558

View File

@@ -0,0 +1,12 @@
#if UNITY_EDITOR
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class ShowIf : ConditionalTag
{
protected override string m_beginTag => "BeginShowIf";
protected override string m_EndTag => "EndShowIf";
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b6443c4cdd419d446a2f9559b8786799
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/ShowIf.cs
uploadId: 820558

View File

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

View File

@@ -0,0 +1,19 @@
#if UNITY_EDITOR
using UnityEditor;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class LightmapEmissionFlags : Tag
{
protected override string m_beginTag => "LightmapEmissionFlags";
public override void OnBegin(MarkupShaderGUI.Context context)
{
// Change the GI emission flag and fix it up with emissive as black if necessary.
context.materialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel - 2, true);
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 628dc929ce4f0b24fb7626af865a7520
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Experimental/LightmapEmissionFlags.cs
uploadId: 820558

View File

@@ -0,0 +1,531 @@
#if UNITY_EDITOR
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class RenderSettings : Tag
{
protected override string m_beginTag => "BeginRenderSettings";
protected override string m_EndTag => "EndRenderSettings";
enum SurfaceType { Opaque, Transparent }
readonly string _SURFACE_TYPE_OPAQUE = "_SURFACE_TYPE_OPAQUE";
readonly string _SURFACE_TYPE_TRANSPARENT = "_SURFACE_TYPE_TRANSPARENT";
readonly string k_SurfaceTypeName = "_SURFACE_TYPE";
readonly string[] k_SurfaceTypeOptions = System.Enum.GetNames(typeof(SurfaceType));
readonly int[] k_SurfaceTypeValues = (int[])System.Enum.GetValues(typeof(SurfaceType));
SurfaceType? m_SurfaceType;
bool m_SurfaceTypeChanged;
readonly string _ALPHATEST_ON = "_ALPHATEST_ON";
readonly string k_AlphaClippingName = "_AlphaClipping";
bool? m_AlphaClipping;
readonly string k_CutoffName = "_Cutoff";
float? m_Cutoff;
readonly string k_PreserveSpecular = "_PreserveSpecular";
bool? m_PreserveSpecular;
readonly string k_CullModeName = "_Cull";
readonly string[] k_CullModeOptions = System.Enum.GetNames(typeof(CullMode));
readonly int[] k_CullModeValues = (int[])System.Enum.GetValues(typeof(CullMode));
CullMode? m_CullMode;
readonly string k_ZTestName = "_ZTest";
readonly string[] k_ZTestOptions = System.Enum.GetNames(typeof(CompareFunction));
int[] k_ZTestValues = (int[])System.Enum.GetValues(typeof(CompareFunction));
CompareFunction? m_ZTest;
enum ZWriteControl { Auto, Off, On }
readonly string k_ZWriteControlName = "_ZWriteControl";
readonly string[] k_ZWriteControlOptions = System.Enum.GetNames(typeof(ZWriteControl));
readonly int[] k_ZWriteControlValues = (int[])System.Enum.GetValues(typeof(ZWriteControl));
readonly string k_ZWriteName = "_ZWrite";
ZWriteControl? m_ZWriteControl;
enum BlendControl { Auto, Custom, Alpha, Premultiply, Additive, Multiply }
readonly string k_BlendControlName = "_BlendControl";
readonly string[] k_BlendControlOptions = System.Enum.GetNames(typeof(BlendControl));
readonly int[] k_BlendControlValues = (int[])System.Enum.GetValues(typeof(BlendControl));
BlendControl? m_BlendControl;
readonly string k_SrcBlendName = "_SrcBlend";
readonly string k_DstBlendName = "_DstBlend";
readonly string k_AlphaSrcBlendName = "_AlphaSrcBlend";
readonly string k_AlphaDstBlendName = "_AlphaDstBlend";
readonly string[] k_BlendFactorOptions = System.Enum.GetNames(typeof(BlendMode));
readonly int[] k_BlendFactorValues = (int[])System.Enum.GetValues(typeof(BlendMode));
BlendMode? m_SrcBlend, m_DstBlend, m_AlphaSrcBlend, m_AlphaDstBlend;
readonly string _RECEIVE_SHADOWS_OFF = "_RECEIVE_SHADOWS_OFF";
readonly string k_CastShadowsName = "_CastShadows";
readonly string k_ReceiveShadowsName = "_ReceiveShadows";
bool? m_CastShadows;
bool? m_ReceiveShadows;
enum QueueControl { Auto, Custom }
readonly string k_QueueControlName = "_QueueControl";
QueueControl? m_QueueControl;
readonly string k_QueueOffsetName = "_QueueOffset";
int? m_QueueOffset;
MarkupShaderGUI.Context m_Context;
UnityEngine.Object[] m_Targets;
bool m_PropChanged = false;
public void InitNewMaterials(MarkupShaderGUI.Context context)
{
m_Context = context;
if (m_Context.materialEditor.targets != m_Targets)
{
m_Targets = m_Context.materialEditor.targets;
CollectPropertyValues();
UpdateMaterials();
}
}
public override void OnBegin(MarkupShaderGUI.Context context)
{
m_PropChanged = false;
DrawSurfaceType();
DrawAlphaClipping();
DrawPreserveSpecular();
DrawHelper.DrawSeparator();
DrawCullMode();
DrawZTest();
DrawZWrite();
DrawBlendMode();
DrawHelper.DrawSeparator();
DrawShadows();
DrawHelper.DrawSeparator();
DrawRenderQueue();
if (m_PropChanged)
UpdateMaterials();
DrawHelper.DrawSeparator();
context.materialEditor.EnableInstancingField();
context.materialEditor.DoubleSidedGIField();
}
void CollectPropertyValues()
{
m_SurfaceType = GetMixedEnum<SurfaceType>(k_SurfaceTypeName);
m_AlphaClipping = GetMixedBool(k_AlphaClippingName);
m_PreserveSpecular = GetMixedBool(k_PreserveSpecular);
m_Cutoff = GetMixedFloat(k_CutoffName);
m_CullMode = GetMixedEnum<CullMode>(k_CullModeName);
m_ZTest = GetMixedEnum<CompareFunction>(k_ZTestName);
m_ZWriteControl = GetMixedEnum<ZWriteControl>(k_ZWriteControlName);
m_BlendControl = GetMixedEnum<BlendControl>(k_BlendControlName);
m_SrcBlend = GetMixedEnum<BlendMode>(k_SrcBlendName);
m_DstBlend = GetMixedEnum<BlendMode>(k_DstBlendName);
m_AlphaSrcBlend = GetMixedEnum<BlendMode>(k_AlphaSrcBlendName);
m_AlphaDstBlend = GetMixedEnum<BlendMode>(k_AlphaDstBlendName);
m_CastShadows = GetMixedBool(k_CastShadowsName);
m_ReceiveShadows = GetMixedBool(k_ReceiveShadowsName);
m_QueueControl = GetMixedEnum<QueueControl>(k_QueueControlName);
m_QueueOffset = GetMixedInt(k_QueueOffsetName);
}
void DrawSurfaceType()
{
DrawEnum("Surface Type", k_SurfaceTypeName, ref m_SurfaceType, SurfaceType.Opaque);
}
void DrawAlphaClipping()
{
DrawToggle("Alpha Clipping", k_AlphaClippingName, ref m_AlphaClipping, false);
if (m_AlphaClipping.HasValue && m_AlphaClipping.Value)
{
EditorGUI.indentLevel += 1;
DrawFloatRange("Threshold", k_CutoffName, ref m_Cutoff, 0.5f, 0.0f, 1.0f);
EditorGUI.indentLevel -= 1;
}
}
void DrawPreserveSpecular()
{
DrawToggle("Preserve Specular", k_PreserveSpecular, ref m_PreserveSpecular, true);
}
void DrawCullMode()
{
DrawEnum("Cull Mode", k_CullModeName, ref m_CullMode, CullMode.Back);
}
void DrawZTest()
{
DrawEnum("Depth Test", k_ZTestName, ref m_ZTest, CompareFunction.LessEqual);
}
void DrawZWrite()
{
DrawEnum("Depth Write", k_ZWriteControlName, ref m_ZWriteControl, ZWriteControl.Auto);
}
void DrawBlendMode()
{
DrawEnum("Blend Control", k_BlendControlName, ref m_BlendControl, BlendControl.Auto);
EditorGUI.indentLevel += 1;
if (m_BlendControl.HasValue)
{
GUI.enabled = (m_BlendControl == BlendControl.Custom);
DrawEnum("Src Blend", k_SrcBlendName, ref m_SrcBlend, BlendMode.One);
DrawEnum("Dst Blend", k_DstBlendName, ref m_DstBlend, BlendMode.Zero);
DrawEnum("Alpha Src Blend", k_AlphaSrcBlendName, ref m_AlphaSrcBlend, BlendMode.One);
DrawEnum("Alpha Dst Blend", k_AlphaDstBlendName, ref m_AlphaDstBlend, BlendMode.Zero);
GUI.enabled = true;
}
EditorGUI.indentLevel -= 1;
}
void DrawShadows()
{
DrawToggle("Cast Shadows", k_CastShadowsName, ref m_CastShadows, true);
DrawToggle("Receive Shadows", k_ReceiveShadowsName, ref m_ReceiveShadows, true);
}
void DrawRenderQueue()
{
DrawEnum("Queue Control", k_QueueControlName, ref m_QueueControl, QueueControl.Auto);
if (m_QueueControl.HasValue)
{
GUI.enabled = (m_QueueControl.Value == QueueControl.Auto);
DrawIntRange("Offset", k_QueueOffsetName, ref m_QueueOffset, 0, -50, 50);
GUI.enabled = (m_QueueControl.Value == QueueControl.Custom);
m_Context.materialEditor.RenderQueueField();
GUI.enabled = true;
}
}
void DrawIntRange(string displayName, string propName, ref int? propValue, int defaultValue, int min, int max)
{
EditorGUI.showMixedValue = !propValue.HasValue;
try
{
using (var _ = new EditorGUILayout.HorizontalScope())
{
EditorGUI.BeginChangeCheck();
// EditorGUILayout.LabelField(displayName, GUILayout.ExpandWidth(false));
// var newValue = EditorGUILayout.IntSlider(propValue ?? defaultValue, min, max, GUILayout.ExpandWidth(true));
GUILayout.Label(displayName, GUILayout.ExpandWidth(false));
var newValue = (int)GUILayout.HorizontalSlider(propValue ?? defaultValue, min, max, GUILayout.ExpandWidth(true));
newValue = IMGUIUtils.IntField(newValue);
if (EditorGUI.EndChangeCheck())
{
m_PropChanged = true;
propValue = newValue;
foreach (var material in m_Context.materials)
material.SetInt(propName, propValue.Value);
}
}
}
catch
{
EditorGUI.showMixedValue = false;
}
}
void DrawFloatRange(string displayName, string propName, ref float? propValue, float defaultValue, float min, float max)
{
EditorGUI.showMixedValue = !propValue.HasValue;
try
{
EditorGUI.BeginChangeCheck();
var newValue = EditorGUILayout.Slider(displayName, propValue ?? defaultValue, min, max);
if (EditorGUI.EndChangeCheck())
{
m_PropChanged = true;
propValue = newValue;
foreach (var material in m_Context.materials)
material.SetFloat(propName, propValue.Value);
}
}
catch
{
EditorGUI.showMixedValue = false;
}
}
void DrawEnum<T>(string displayName, string propName, ref T? propValue, T defaultValue) where T : struct, System.Enum
{
EditorGUI.showMixedValue = !propValue.HasValue;
try
{
EditorGUI.BeginChangeCheck();
var newValue = (T)EditorGUILayout.EnumPopup(displayName, propValue ?? defaultValue);
if (EditorGUI.EndChangeCheck())
{
m_PropChanged = true;
propValue = newValue;
var intValue = Convert.ToInt32(propValue.Value);
foreach (var material in m_Context.materials)
material.SetInt(propName, intValue);
}
}
catch
{
EditorGUI.showMixedValue = false;
}
}
void DrawToggle(string displayName, string propName, ref bool? propValue, bool defaultValue)
{
EditorGUI.showMixedValue = !propValue.HasValue;
try
{
EditorGUI.BeginChangeCheck();
var newValue = EditorGUILayout.Toggle(displayName, propValue ?? defaultValue);
if (EditorGUI.EndChangeCheck())
{
m_PropChanged = true;
propValue = newValue;
var intValue = propValue.Value ? 1 : 0;
foreach (var material in m_Context.materials)
material.SetInt(propName, intValue);
}
}
catch
{
EditorGUI.showMixedValue = false;
}
}
void UpdateMaterials()
{
UpdateRenderType();
UpdateZWrite();
UpdateBlendFactors();
UpdateRenderQueue();
UpdateShadows();
}
void UpdateRenderType()
{
foreach (var material in m_Context.materials)
{
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
var isOpaque = (surfaceType == SurfaceType.Opaque);
var isTransparent = (surfaceType == SurfaceType.Transparent);
var isAlphaClipping = (material.GetInt(k_AlphaClippingName) == 1);
material.SetKeyword(_SURFACE_TYPE_OPAQUE, isOpaque);
material.SetKeyword(_SURFACE_TYPE_TRANSPARENT, isTransparent);
material.SetKeyword(_ALPHATEST_ON, isAlphaClipping);
if (isAlphaClipping) // alpha clipping first
material.SetOverrideTag("RenderType", "TransparentCutout");
else if (isTransparent)
material.SetOverrideTag("RenderType", "Transparent");
else
material.SetOverrideTag("RenderType", ""); // Empty string resets the value
}
}
void UpdateZWrite()
{
foreach (var material in m_Context.materials)
{
var zWriteMode = (ZWriteControl)material.GetInt(k_ZWriteControlName);
var oldZWrite = material.GetInt(k_ZWriteName);
var newZWrite = 0;
switch (zWriteMode)
{
case ZWriteControl.Auto:
var srufaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
newZWrite = (srufaceType == SurfaceType.Transparent) ? 0 : 1;
break;
case ZWriteControl.Off: newZWrite = 0; break;
case ZWriteControl.On: newZWrite = 1; break;
}
if (oldZWrite != newZWrite)
material.SetInt(k_ZWriteName, newZWrite);
}
}
void UpdateBlendFactors()
{
foreach (var material in m_Context.materials)
{
var blendingMode = (BlendControl)material.GetInt(k_BlendControlName);
var srcBlend = (BlendMode)material.GetInt(k_SrcBlendName);
var dstBlend = (BlendMode)material.GetInt(k_DstBlendName);
var alphaSrcBlend = (BlendMode)material.GetInt(k_AlphaSrcBlendName);
var alphaDstBlend = (BlendMode)material.GetInt(k_AlphaDstBlendName);
var isAuto = (blendingMode == BlendControl.Auto);
if (isAuto)
{
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
if (surfaceType == SurfaceType.Opaque)
{
srcBlend = BlendMode.One;
dstBlend = BlendMode.Zero;
alphaSrcBlend = BlendMode.One;
alphaDstBlend = BlendMode.Zero;
}
else if (surfaceType == SurfaceType.Transparent)
{
srcBlend = BlendMode.SrcAlpha;
dstBlend = BlendMode.OneMinusSrcAlpha;
alphaSrcBlend = BlendMode.One;
alphaDstBlend = dstBlend;
}
}
var isAlpha = (blendingMode == BlendControl.Alpha);
if (isAlpha)
{
srcBlend = BlendMode.SrcAlpha;
dstBlend = BlendMode.OneMinusSrcAlpha;
alphaSrcBlend = BlendMode.One;
alphaDstBlend = dstBlend;
}
var isPremultiply = (blendingMode == BlendControl.Premultiply);
if (isPremultiply)
{
srcBlend = BlendMode.One;
dstBlend = BlendMode.OneMinusSrcAlpha;
alphaSrcBlend = srcBlend;
alphaDstBlend = dstBlend;
}
var isAdditive = (blendingMode == BlendControl.Additive);
if (isAdditive)
{
srcBlend = BlendMode.SrcAlpha;
dstBlend = BlendMode.One;
alphaSrcBlend = BlendMode.One;
alphaDstBlend = dstBlend;
}
var isMultiply = (blendingMode == BlendControl.Multiply);
if (isMultiply)
{
srcBlend = BlendMode.DstColor;
dstBlend = BlendMode.Zero;
alphaSrcBlend = BlendMode.Zero;
alphaDstBlend = BlendMode.One;
}
SetBlendingFactors(material, srcBlend, dstBlend, alphaSrcBlend, alphaDstBlend);
}
}
void UpdateShadows()
{
foreach (var material in m_Context.materials)
{
var castShadows = material.GetInt(k_CastShadowsName);
material.SetShaderPassEnabled("ShadowCaster", (castShadows == 1));
var receiveShadows = material.GetInt(k_ReceiveShadowsName);
material.SetKeyword(_RECEIVE_SHADOWS_OFF, (receiveShadows != 1));
}
}
void UpdateRenderQueue()
{
foreach (var material in m_Context.materials)
{
var queueControl = (QueueControl)material.GetInt(k_QueueControlName);
if (queueControl == QueueControl.Auto)
{
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
if (surfaceType == SurfaceType.Transparent)
material.renderQueue = (int)RenderQueue.Transparent;
else
{
var isAlphaClipping = (material.GetInt(k_AlphaClippingName) == 1);
if (isAlphaClipping)
material.renderQueue = (int)RenderQueue.AlphaTest;
else
material.renderQueue = (int)RenderQueue.Geometry;
}
var queueOffset = material.GetInt(k_QueueOffsetName);
material.renderQueue += queueOffset;
}
}
}
void SetBlendingFactors(Material material, BlendMode colorSrc, BlendMode colorDst, BlendMode alphaSrc, BlendMode alphaDst)
{
material.SetInt("_SrcBlend", (int)colorSrc);
material.SetInt("_DstBlend", (int)colorDst);
material.SetInt("_AlphaSrcBlend", (int)alphaSrc);
material.SetInt("_AlphaDstBlend", (int)alphaDst);
}
T? GetMixedEnum<T>(string prop) where T : struct
{
var first = m_Context.materials[0].GetInt(prop);
if (m_Context.materials.All(m => m.GetInt(prop) == first))
return (T)(object)first;
return null;
}
bool? GetMixedBool(string prop)
{
var first = m_Context.materials[0].GetInt(prop);
if (m_Context.materials.All(m => m.GetInt(prop) == first))
return first == 1;
return null;
}
int? GetMixedInt(string prop)
{
var first = m_Context.materials[0].GetInt(prop);
if (m_Context.materials.All(m => m.GetInt(prop) == first))
return first;
return null;
}
float? GetMixedFloat(string prop)
{
var first = m_Context.materials[0].GetFloat(prop);
if (m_Context.materials.All(m => m.GetFloat(prop) == first))
return first;
return null;
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2764b74759e7c81419d5a1913fad1ffd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Experimental/RenderSettings.cs
uploadId: 820558

View File

@@ -0,0 +1,112 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class Foldout : Tag
{
protected override string m_beginTag => "BeginFoldout";
protected override string m_EndTag => "EndFoldout";
string m_FoldoutName = "";
string m_FoldoutKey = "";
public override void OnBegin(MarkupShaderGUI.Context context)
{
m_FoldoutName = ExtractFoldoutName(context.attribute);
m_FoldoutKey = context.shader.name + m_FoldoutName;
state = GetFoldoutState(m_FoldoutKey);
DrawFoldout(m_FoldoutKey, context);
if (state == true) // begin foldout space
GUILayout.Space(4);
}
public override void OnEnd()
{
if (state == true) // end foldout space
GUILayout.Space(6);
else
GUILayout.Space(2);
m_FoldoutName = "";
m_FoldoutKey = "";
state = true;
}
void DrawFoldout(string foldoutKey, MarkupShaderGUI.Context context)
{
const float height = 21f;
Rect foldoutRect = GUILayoutUtility.GetRect(0, height, GUILayout.ExpandWidth(true));
foldoutRect.xMin -= 29;
var style = new GUIStyle("ShurikenModuleTitle")
{
border = new RectOffset(15, 7, 4, 4),
fixedHeight = height,
contentOffset = new Vector2(19, -1), // text offset
fontSize = 12 // Default is 10
};
var foldoutTitle = m_FoldoutName;
var prop = context.materialProperty;
var enumName = AttributeUtils.GetKeywordEnumName(context.attributes, prop);
if (string.IsNullOrEmpty(enumName) == false)
{
if (prop.hasMixedValue)
foldoutTitle += " - *";
else
foldoutTitle += " - " + enumName;
}
// Draw title
GUI.Label(foldoutRect, foldoutTitle, style);
// Draw arrow
var arrowRect = new Rect(foldoutRect.x + 4, foldoutRect.y + foldoutRect.height / 2 - 7, 14f, 14f);
Event e = Event.current;
if (e.type == EventType.Repaint)
EditorStyles.foldout.Draw(arrowRect, false, false, GetFoldoutState(foldoutKey), false);
// Handle click to toggle foldout
if (Event.current.type == EventType.MouseDown && foldoutRect.Contains(Event.current.mousePosition))
{
var previousState = GetFoldoutState(foldoutKey);
SetFoldoutState(foldoutKey, !previousState);
Event.current.Use();
}
}
string ExtractFoldoutName(string attribute)
{
var args = AttributeUtils.ExtractArgs(attribute);
if (args.Count > 0)
return args[0];
return "";
}
void SetFoldoutState(string foldoutKey, bool state)
{
var prefKey = GetPrefKey(foldoutKey);
EditorPrefs.SetBool(prefKey, state);
}
bool GetFoldoutState(string foldoutKey)
{
var prefKey = GetPrefKey(foldoutKey);
return EditorPrefs.GetBool(prefKey, false);
}
string GetPrefKey(string foldoutKey)
{
return $"{nameof(MarkupShaderGUIInternal)}.{foldoutKey}";
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: afcebc20e9235a0418735b9896aa1981
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Foldout.cs
uploadId: 820558

View File

@@ -0,0 +1,69 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class Label : Tag
{
protected override string m_beginTag => "Label";
GUIStyle m_LabelStyle;
GUIStyle labelStyle => m_LabelStyle ??= new GUIStyle(EditorStyles.label);
public override void OnBegin(MarkupShaderGUI.Context context)
{
var args = AttributeUtils.ExtractArgs(context.attribute);
var argsCount = args.Count;
var label = "";
if (argsCount >= 1)
label = args[0];
var size = 10;
if (args.Count >= 2)
size = (int)AttributeUtils.ParseNumber(args[1]);
if (argsCount == 1)
DrawLabel(label);
else if (argsCount == 2)
DrawLabel(label, size);
else if (argsCount == 3)
{
var fontStyle = args[2];
DrawLabel(label, size, fontStyle);
}
}
void DrawLabel(string label)
{
if (string.IsNullOrEmpty(label))
return;
GUILayout.Label(label);
}
void DrawLabel(string label, int size)
{
if (string.IsNullOrEmpty(label))
return;
labelStyle.fontSize = size;
labelStyle.fontStyle = FontStyle.Normal;
GUILayout.Label(label, labelStyle);
}
void DrawLabel(string label, int size, string fontStyleStr)
{
if (string.IsNullOrEmpty(label))
return;
labelStyle.fontSize = size;
labelStyle.fontStyle = (FontStyle)System.Enum.Parse(typeof(FontStyle), fontStyleStr);
GUILayout.Label(label, labelStyle);
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 06a9c3b0f10cace4c815d6476783f718
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Label.cs
uploadId: 820558

View File

@@ -0,0 +1,73 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class MiniTextureWithColor : Tag
{
protected override string m_beginTag => "BeginMiniTextureWithColor";
protected override string m_EndTag => "EndMiniTextureWithColor";
public override void OnBegin(MarkupShaderGUI.Context context)
{
state = true;
}
public override void OnEnd()
{
state = false;
}
public void Draw(MaterialProperty prop, MaterialEditor editor)
{
var material = editor.target as Material;
var shader = material.shader;
var texPropIndex = shader.FindPropertyIndex(prop.name);
var texPropDisplayName = prop.displayName;
// single line texture and color
EditorGUILayout.BeginHorizontal();
{
var controlRect = EditorGUILayout.GetControlRect(true, 20f, EditorStyles.layerMaskField);
editor.TexturePropertyMiniThumbnail(controlRect, prop, "", texPropDisplayName);
var displayNameRect = controlRect;
displayNameRect.x += 31;
var labelGUIConent = GUIUtils.TempContent(prop.displayName);
EditorGUI.LabelField(displayNameRect, labelGUIConent);
var colorPropIndex = texPropIndex + 1;
if (colorPropIndex < shader.GetPropertyCount())
{
if (shader.GetPropertyType(colorPropIndex) == ShaderPropertyType.Color)
{
var offset = Mathf.Max(controlRect.width * 0.425f, 122f);
var colorRect = controlRect;
colorRect.x += offset;
colorRect.width -= offset;
string colorPropName = shader.GetPropertyName(colorPropIndex);
var colorProp = MaterialEditor.GetMaterialProperty(editor.targets, colorPropName);
editor.ColorProperty(colorRect, colorProp, GUIContent.none.text);
}
}
}
EditorGUILayout.EndHorizontal();
// texture uv scale offset
ShaderPropertyFlags shaderPropFlags = shader.GetPropertyFlags(texPropIndex);
if ((shaderPropFlags & ShaderPropertyFlags.NoScaleOffset) == 0)
{
// GUI.enabled = prop.textureValue != null;
editor.TextureScaleOffsetProperty(prop);
// GUI.enabled = true;
}
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 88a627b463d99794d8b0124021edaeab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/MiniTextureWithColor.cs
uploadId: 820558

View File

@@ -0,0 +1,16 @@
#if UNITY_EDITOR
namespace GraphicsCat.MarkupShaderGUIInternal
{
public class Separator : Tag
{
protected override string m_beginTag => "Separator";
public override void OnBegin(MarkupShaderGUI.Context context)
{
DrawHelper.DrawSeparator();
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6c1206d37c95cfe47afd03bff13e345d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 328765
packageName: LitPlus - URP Enhanced Lit Shader
packageVersion: 1.0.1
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Separator.cs
uploadId: 820558