diff --git a/UniGLTF/UniUnlit.meta b/UniUnlit.meta similarity index 100% rename from UniGLTF/UniUnlit.meta rename to UniUnlit.meta diff --git a/UniGLTF/UniUnlit/Editor.meta b/UniUnlit/Editor.meta similarity index 100% rename from UniGLTF/UniUnlit/Editor.meta rename to UniUnlit/Editor.meta diff --git a/UniGLTF/UniUnlit/Editor/UniUnlitEditor.cs b/UniUnlit/Editor/UniUnlitEditor.cs similarity index 97% rename from UniGLTF/UniUnlit/Editor/UniUnlitEditor.cs rename to UniUnlit/Editor/UniUnlitEditor.cs index afd11b718..5aadb6f47 100644 --- a/UniGLTF/UniUnlit/Editor/UniUnlitEditor.cs +++ b/UniUnlit/Editor/UniUnlitEditor.cs @@ -1,149 +1,149 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEditor; -using UnityEngine; -using UnityEngine.Rendering; - - -namespace UniGLTF.UniUnlit -{ - public class UniUnlitEditor : ShaderGUI - { - private MaterialProperty _mainTex; - private MaterialProperty _color; - private MaterialProperty _cutoff; - private MaterialProperty _blendMode; - private MaterialProperty _cullMode; - private MaterialProperty _vColBlendMode; -// private MaterialProperty _srcBlend; -// private MaterialProperty _dstBlend; -// private MaterialProperty _zWrite; - - public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) - { - _mainTex = FindProperty(Utils.PropNameMainTex, properties); - _color = FindProperty(Utils.PropNameColor, properties); - _cutoff = FindProperty(Utils.PropNameCutoff, properties); - _blendMode = FindProperty(Utils.PropNameBlendMode, properties); - _cullMode = FindProperty(Utils.PropNameCullMode, properties); - _vColBlendMode = FindProperty(Utils.PropeNameVColBlendMode, properties); -// _srcBlend = FindProperty(PropNameSrcBlend, properties); -// _dstBlend = FindProperty(PropNameDstBlend, properties); -// _zWrite = FindProperty(PropNameZWrite, properties); - - var materials = materialEditor.targets.Select(x => x as Material).ToArray(); - - EditorGUI.BeginChangeCheck(); - { - DrawRenderingBox(materialEditor, materials); - DrawColorBox(materialEditor, materials); - DrawOptionsBox(materialEditor, materials); - } - EditorGUI.EndChangeCheck(); - } - - public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) - { - var blendMode = UniUnlitRenderMode.Opaque; - if (material.HasProperty(Utils.PropNameStandardShadersRenderMode)) // from Standard shader - { - blendMode = (UniUnlitRenderMode) Math.Min(2f, material.GetFloat(Utils.PropNameStandardShadersRenderMode)); - } - - // assigns UniUnlit's properties... - base.AssignNewShaderToMaterial(material, oldShader, newShader); - - // take over old value - material.SetFloat(Utils.PropNameBlendMode, (float) blendMode); - - Utils.ValidateProperties(material, isRenderModeChangedByUser: true); - } - - private void DrawRenderingBox(MaterialEditor materialEditor, Material[] materials) - { - EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel); - EditorGUILayout.BeginVertical(GUI.skin.box); - { - if (PopupEnum("Rendering Type", _blendMode, materialEditor)) - { - ModeChanged(materials, isRenderModeChangedByUser: true); - } - if (PopupEnum("Cull Mode", _cullMode, materialEditor)) - { - ModeChanged(materials, isRenderModeChangedByUser: true); - } - EditorGUILayout.Space(); - - switch ((UniUnlitRenderMode) _blendMode.floatValue) - { - case UniUnlitRenderMode.Cutout: - materialEditor.ShaderProperty(_cutoff, "Cutoff"); - break; - case UniUnlitRenderMode.Opaque: - case UniUnlitRenderMode.Transparent: - break; - } - } - EditorGUILayout.EndVertical(); - EditorGUILayout.Space(); - } - - private void DrawColorBox(MaterialEditor materialEditor, Material[] materials) - { - EditorGUILayout.LabelField("Color", EditorStyles.boldLabel); - EditorGUILayout.BeginVertical(GUI.skin.box); - { - materialEditor.TexturePropertySingleLine(new GUIContent("Main Tex", "(RGBA)"), _mainTex, _color); - materialEditor.TextureScaleOffsetProperty(_mainTex); - EditorGUILayout.Space(); - - if (PopupEnum("Vertex Color Blend Mode", _vColBlendMode, materialEditor)) - { - ModeChanged(materials, isRenderModeChangedByUser: true); - } - } - EditorGUILayout.EndVertical(); - EditorGUILayout.Space(); - } - - private void DrawOptionsBox(MaterialEditor materialEditor, Material[] materials) - { - EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); - EditorGUILayout.BeginVertical(GUI.skin.box); - { - #if UNITY_5_6_OR_NEWER -// materialEditor.EnableInstancingField(); - materialEditor.DoubleSidedGIField(); - #endif - materialEditor.RenderQueueField(); - } - EditorGUILayout.EndVertical(); - EditorGUILayout.Space(); - } - - private static bool PopupEnum(string name, MaterialProperty property, MaterialEditor editor) where T : struct - { - EditorGUI.showMixedValue = property.hasMixedValue; - EditorGUI.BeginChangeCheck(); - var ret = EditorGUILayout.Popup(name, (int) property.floatValue, Enum.GetNames(typeof(T))); - var changed = EditorGUI.EndChangeCheck(); - if (changed) - { - editor.RegisterPropertyChangeUndo("EnumPopUp"); - property.floatValue = ret; - } - EditorGUI.showMixedValue = false; - return changed; - } - - - private static void ModeChanged(Material[] materials, bool isRenderModeChangedByUser = false) - { - foreach (var material in materials) - { - Utils.ValidateProperties(material, isRenderModeChangedByUser); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + + +namespace UniGLTF.UniUnlit +{ + public class UniUnlitEditor : ShaderGUI + { + private MaterialProperty _mainTex; + private MaterialProperty _color; + private MaterialProperty _cutoff; + private MaterialProperty _blendMode; + private MaterialProperty _cullMode; + private MaterialProperty _vColBlendMode; +// private MaterialProperty _srcBlend; +// private MaterialProperty _dstBlend; +// private MaterialProperty _zWrite; + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + _mainTex = FindProperty(Utils.PropNameMainTex, properties); + _color = FindProperty(Utils.PropNameColor, properties); + _cutoff = FindProperty(Utils.PropNameCutoff, properties); + _blendMode = FindProperty(Utils.PropNameBlendMode, properties); + _cullMode = FindProperty(Utils.PropNameCullMode, properties); + _vColBlendMode = FindProperty(Utils.PropeNameVColBlendMode, properties); +// _srcBlend = FindProperty(PropNameSrcBlend, properties); +// _dstBlend = FindProperty(PropNameDstBlend, properties); +// _zWrite = FindProperty(PropNameZWrite, properties); + + var materials = materialEditor.targets.Select(x => x as Material).ToArray(); + + EditorGUI.BeginChangeCheck(); + { + DrawRenderingBox(materialEditor, materials); + DrawColorBox(materialEditor, materials); + DrawOptionsBox(materialEditor, materials); + } + EditorGUI.EndChangeCheck(); + } + + public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) + { + var blendMode = UniUnlitRenderMode.Opaque; + if (material.HasProperty(Utils.PropNameStandardShadersRenderMode)) // from Standard shader + { + blendMode = (UniUnlitRenderMode) Math.Min(2f, material.GetFloat(Utils.PropNameStandardShadersRenderMode)); + } + + // assigns UniUnlit's properties... + base.AssignNewShaderToMaterial(material, oldShader, newShader); + + // take over old value + material.SetFloat(Utils.PropNameBlendMode, (float) blendMode); + + Utils.ValidateProperties(material, isRenderModeChangedByUser: true); + } + + private void DrawRenderingBox(MaterialEditor materialEditor, Material[] materials) + { + EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel); + EditorGUILayout.BeginVertical(GUI.skin.box); + { + if (PopupEnum("Rendering Type", _blendMode, materialEditor)) + { + ModeChanged(materials, isRenderModeChangedByUser: true); + } + if (PopupEnum("Cull Mode", _cullMode, materialEditor)) + { + ModeChanged(materials, isRenderModeChangedByUser: true); + } + EditorGUILayout.Space(); + + switch ((UniUnlitRenderMode) _blendMode.floatValue) + { + case UniUnlitRenderMode.Cutout: + materialEditor.ShaderProperty(_cutoff, "Cutoff"); + break; + case UniUnlitRenderMode.Opaque: + case UniUnlitRenderMode.Transparent: + break; + } + } + EditorGUILayout.EndVertical(); + EditorGUILayout.Space(); + } + + private void DrawColorBox(MaterialEditor materialEditor, Material[] materials) + { + EditorGUILayout.LabelField("Color", EditorStyles.boldLabel); + EditorGUILayout.BeginVertical(GUI.skin.box); + { + materialEditor.TexturePropertySingleLine(new GUIContent("Main Tex", "(RGBA)"), _mainTex, _color); + materialEditor.TextureScaleOffsetProperty(_mainTex); + EditorGUILayout.Space(); + + if (PopupEnum("Vertex Color Blend Mode", _vColBlendMode, materialEditor)) + { + ModeChanged(materials, isRenderModeChangedByUser: true); + } + } + EditorGUILayout.EndVertical(); + EditorGUILayout.Space(); + } + + private void DrawOptionsBox(MaterialEditor materialEditor, Material[] materials) + { + EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); + EditorGUILayout.BeginVertical(GUI.skin.box); + { + #if UNITY_5_6_OR_NEWER +// materialEditor.EnableInstancingField(); + materialEditor.DoubleSidedGIField(); + #endif + materialEditor.RenderQueueField(); + } + EditorGUILayout.EndVertical(); + EditorGUILayout.Space(); + } + + private static bool PopupEnum(string name, MaterialProperty property, MaterialEditor editor) where T : struct + { + EditorGUI.showMixedValue = property.hasMixedValue; + EditorGUI.BeginChangeCheck(); + var ret = EditorGUILayout.Popup(name, (int) property.floatValue, Enum.GetNames(typeof(T))); + var changed = EditorGUI.EndChangeCheck(); + if (changed) + { + editor.RegisterPropertyChangeUndo("EnumPopUp"); + property.floatValue = ret; + } + EditorGUI.showMixedValue = false; + return changed; + } + + + private static void ModeChanged(Material[] materials, bool isRenderModeChangedByUser = false) + { + foreach (var material in materials) + { + Utils.ValidateProperties(material, isRenderModeChangedByUser); + } + } + } +} diff --git a/UniGLTF/UniUnlit/Editor/UniUnlitEditor.cs.meta b/UniUnlit/Editor/UniUnlitEditor.cs.meta similarity index 100% rename from UniGLTF/UniUnlit/Editor/UniUnlitEditor.cs.meta rename to UniUnlit/Editor/UniUnlitEditor.cs.meta diff --git a/UniGLTF/UniUnlit/Resources.meta b/UniUnlit/Resources.meta similarity index 100% rename from UniGLTF/UniUnlit/Resources.meta rename to UniUnlit/Resources.meta diff --git a/UniGLTF/UniUnlit/Resources/UniUnlit.shader b/UniUnlit/Resources/UniUnlit.shader similarity index 100% rename from UniGLTF/UniUnlit/Resources/UniUnlit.shader rename to UniUnlit/Resources/UniUnlit.shader diff --git a/UniGLTF/UniUnlit/Resources/UniUnlit.shader.meta b/UniUnlit/Resources/UniUnlit.shader.meta similarity index 100% rename from UniGLTF/UniUnlit/Resources/UniUnlit.shader.meta rename to UniUnlit/Resources/UniUnlit.shader.meta diff --git a/UniGLTF/UniUnlit/Scripts.meta b/UniUnlit/Scripts.meta similarity index 100% rename from UniGLTF/UniUnlit/Scripts.meta rename to UniUnlit/Scripts.meta diff --git a/UniGLTF/UniUnlit/Scripts/Utils.cs b/UniUnlit/Scripts/Utils.cs similarity index 97% rename from UniGLTF/UniUnlit/Scripts/Utils.cs rename to UniUnlit/Scripts/Utils.cs index d32d4f490..3c5bc843a 100644 --- a/UniGLTF/UniUnlit/Scripts/Utils.cs +++ b/UniUnlit/Scripts/Utils.cs @@ -1,139 +1,139 @@ -using UnityEngine; -using UnityEngine.Rendering; - -namespace UniGLTF.UniUnlit -{ - public enum UniUnlitRenderMode - { - Opaque = 0, - Cutout = 1, - Transparent = 2, - } - - public enum UniUnlitCullMode - { - Off = 0, -// Front = 1, - Back = 2, - } - - public enum UniUnlitVertexColorBlendOp - { - None = 0, - Multiply = 1, - } - - public static class Utils - { - public const string PropNameMainTex = "_MainTex"; - public const string PropNameColor = "_Color"; - public const string PropNameCutoff = "_Cutoff"; - public const string PropNameBlendMode = "_BlendMode"; - public const string PropNameCullMode = "_CullMode"; - public const string PropeNameVColBlendMode = "_VColBlendMode"; - public const string PropNameSrcBlend = "_SrcBlend"; - public const string PropNameDstBlend = "_DstBlend"; - public const string PropNameZWrite = "_ZWrite"; - - public const string PropNameStandardShadersRenderMode = "_Mode"; - - public const string KeywordAlphaTestOn = "_ALPHATEST_ON"; - public const string KeywordAlphaBlendOn = "_ALPHABLEND_ON"; - public const string KeywordVertexColMul = "_VERTEXCOL_MUL"; - - public const string TagRenderTypeKey = "RenderType"; - public const string TagRenderTypeValueOpaque = "Opaque"; - public const string TagRenderTypeValueTransparentCutout = "TransparentCutout"; - public const string TagRenderTypeValueTransparent = "Transparent"; - - public static void SetRenderMode(Material material, UniUnlitRenderMode mode) - { - material.SetInt(PropNameBlendMode, (int)mode); - } - - public static void SetCullMode(Material material, UniUnlitCullMode mode) - { - material.SetInt(PropNameCullMode, (int) mode); - } - - public static UniUnlitRenderMode GetRenderMode(Material material) - { - return (UniUnlitRenderMode)material.GetInt(PropNameBlendMode); - } - - public static UniUnlitCullMode GetCullMode(Material material) - { - return (UniUnlitCullMode)material.GetInt(PropNameCullMode); - } - - /// - /// Validate target material's UniUnlitRenderMode, UniUnlitVertexColorBlendOp. - /// Set appropriate hidden properites & keywords. - /// This will change RenderQueue independent to UniUnlitRenderMode if isRenderModeChagedByUser is true. - /// - /// Target material - /// Is changed by user - public static void ValidateProperties(Material material, bool isRenderModeChangedByUser = false) - { - SetupBlendMode(material, (UniUnlitRenderMode)material.GetFloat(PropNameBlendMode), - isRenderModeChangedByUser); - SetupVertexColorBlendOp(material, (UniUnlitVertexColorBlendOp)material.GetFloat(PropeNameVColBlendMode)); - } - - private static void SetupBlendMode(Material material, UniUnlitRenderMode renderMode, - bool isRenderModeChangedByUser = false) - { - switch (renderMode) - { - case UniUnlitRenderMode.Opaque: - material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueOpaque); - material.SetInt(PropNameSrcBlend, (int)BlendMode.One); - material.SetInt(PropNameDstBlend, (int)BlendMode.Zero); - material.SetInt(PropNameZWrite, 1); - SetKeyword(material, KeywordAlphaTestOn, false); - SetKeyword(material, KeywordAlphaBlendOn, false); - if (isRenderModeChangedByUser) material.renderQueue = -1; - break; - case UniUnlitRenderMode.Cutout: - material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueTransparentCutout); - material.SetInt(PropNameSrcBlend, (int)BlendMode.One); - material.SetInt(PropNameDstBlend, (int)BlendMode.Zero); - material.SetInt(PropNameZWrite, 1); - SetKeyword(material, KeywordAlphaTestOn, true); - SetKeyword(material, KeywordAlphaBlendOn, false); - if (isRenderModeChangedByUser) material.renderQueue = (int)RenderQueue.AlphaTest; - break; - case UniUnlitRenderMode.Transparent: - material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueTransparent); - material.SetInt(PropNameSrcBlend, (int)BlendMode.SrcAlpha); - material.SetInt(PropNameDstBlend, (int)BlendMode.OneMinusSrcAlpha); - material.SetInt(PropNameZWrite, 0); - SetKeyword(material, KeywordAlphaTestOn, false); - SetKeyword(material, KeywordAlphaBlendOn, true); - if (isRenderModeChangedByUser) material.renderQueue = (int)RenderQueue.Transparent; - break; - } - } - - private static void SetupVertexColorBlendOp(Material material, UniUnlitVertexColorBlendOp vColBlendOp) - { - switch (vColBlendOp) - { - case UniUnlitVertexColorBlendOp.None: - SetKeyword(material, KeywordVertexColMul, false); - break; - case UniUnlitVertexColorBlendOp.Multiply: - SetKeyword(material, KeywordVertexColMul, true); - break; - } - } - - private static void SetKeyword(Material mat, string keyword, bool required) - { - if (required) - mat.EnableKeyword(keyword); - else - mat.DisableKeyword(keyword); - } - } +using UnityEngine; +using UnityEngine.Rendering; + +namespace UniGLTF.UniUnlit +{ + public enum UniUnlitRenderMode + { + Opaque = 0, + Cutout = 1, + Transparent = 2, + } + + public enum UniUnlitCullMode + { + Off = 0, +// Front = 1, + Back = 2, + } + + public enum UniUnlitVertexColorBlendOp + { + None = 0, + Multiply = 1, + } + + public static class Utils + { + public const string PropNameMainTex = "_MainTex"; + public const string PropNameColor = "_Color"; + public const string PropNameCutoff = "_Cutoff"; + public const string PropNameBlendMode = "_BlendMode"; + public const string PropNameCullMode = "_CullMode"; + public const string PropeNameVColBlendMode = "_VColBlendMode"; + public const string PropNameSrcBlend = "_SrcBlend"; + public const string PropNameDstBlend = "_DstBlend"; + public const string PropNameZWrite = "_ZWrite"; + + public const string PropNameStandardShadersRenderMode = "_Mode"; + + public const string KeywordAlphaTestOn = "_ALPHATEST_ON"; + public const string KeywordAlphaBlendOn = "_ALPHABLEND_ON"; + public const string KeywordVertexColMul = "_VERTEXCOL_MUL"; + + public const string TagRenderTypeKey = "RenderType"; + public const string TagRenderTypeValueOpaque = "Opaque"; + public const string TagRenderTypeValueTransparentCutout = "TransparentCutout"; + public const string TagRenderTypeValueTransparent = "Transparent"; + + public static void SetRenderMode(Material material, UniUnlitRenderMode mode) + { + material.SetInt(PropNameBlendMode, (int)mode); + } + + public static void SetCullMode(Material material, UniUnlitCullMode mode) + { + material.SetInt(PropNameCullMode, (int) mode); + } + + public static UniUnlitRenderMode GetRenderMode(Material material) + { + return (UniUnlitRenderMode)material.GetInt(PropNameBlendMode); + } + + public static UniUnlitCullMode GetCullMode(Material material) + { + return (UniUnlitCullMode)material.GetInt(PropNameCullMode); + } + + /// + /// Validate target material's UniUnlitRenderMode, UniUnlitVertexColorBlendOp. + /// Set appropriate hidden properites & keywords. + /// This will change RenderQueue independent to UniUnlitRenderMode if isRenderModeChagedByUser is true. + /// + /// Target material + /// Is changed by user + public static void ValidateProperties(Material material, bool isRenderModeChangedByUser = false) + { + SetupBlendMode(material, (UniUnlitRenderMode)material.GetFloat(PropNameBlendMode), + isRenderModeChangedByUser); + SetupVertexColorBlendOp(material, (UniUnlitVertexColorBlendOp)material.GetFloat(PropeNameVColBlendMode)); + } + + private static void SetupBlendMode(Material material, UniUnlitRenderMode renderMode, + bool isRenderModeChangedByUser = false) + { + switch (renderMode) + { + case UniUnlitRenderMode.Opaque: + material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueOpaque); + material.SetInt(PropNameSrcBlend, (int)BlendMode.One); + material.SetInt(PropNameDstBlend, (int)BlendMode.Zero); + material.SetInt(PropNameZWrite, 1); + SetKeyword(material, KeywordAlphaTestOn, false); + SetKeyword(material, KeywordAlphaBlendOn, false); + if (isRenderModeChangedByUser) material.renderQueue = -1; + break; + case UniUnlitRenderMode.Cutout: + material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueTransparentCutout); + material.SetInt(PropNameSrcBlend, (int)BlendMode.One); + material.SetInt(PropNameDstBlend, (int)BlendMode.Zero); + material.SetInt(PropNameZWrite, 1); + SetKeyword(material, KeywordAlphaTestOn, true); + SetKeyword(material, KeywordAlphaBlendOn, false); + if (isRenderModeChangedByUser) material.renderQueue = (int)RenderQueue.AlphaTest; + break; + case UniUnlitRenderMode.Transparent: + material.SetOverrideTag(TagRenderTypeKey, TagRenderTypeValueTransparent); + material.SetInt(PropNameSrcBlend, (int)BlendMode.SrcAlpha); + material.SetInt(PropNameDstBlend, (int)BlendMode.OneMinusSrcAlpha); + material.SetInt(PropNameZWrite, 0); + SetKeyword(material, KeywordAlphaTestOn, false); + SetKeyword(material, KeywordAlphaBlendOn, true); + if (isRenderModeChangedByUser) material.renderQueue = (int)RenderQueue.Transparent; + break; + } + } + + private static void SetupVertexColorBlendOp(Material material, UniUnlitVertexColorBlendOp vColBlendOp) + { + switch (vColBlendOp) + { + case UniUnlitVertexColorBlendOp.None: + SetKeyword(material, KeywordVertexColMul, false); + break; + case UniUnlitVertexColorBlendOp.Multiply: + SetKeyword(material, KeywordVertexColMul, true); + break; + } + } + + private static void SetKeyword(Material mat, string keyword, bool required) + { + if (required) + mat.EnableKeyword(keyword); + else + mat.DisableKeyword(keyword); + } + } } \ No newline at end of file diff --git a/UniGLTF/UniUnlit/Scripts/Utils.cs.meta b/UniUnlit/Scripts/Utils.cs.meta similarity index 71% rename from UniGLTF/UniUnlit/Scripts/Utils.cs.meta rename to UniUnlit/Scripts/Utils.cs.meta index 0b5c8bc7b..7824f085e 100644 --- a/UniGLTF/UniUnlit/Scripts/Utils.cs.meta +++ b/UniUnlit/Scripts/Utils.cs.meta @@ -1,3 +1,3 @@ -fileFormatVersion: 2 -guid: e96cbbd810384352a6799dd731533178 +fileFormatVersion: 2 +guid: e96cbbd810384352a6799dd731533178 timeCreated: 1537534399 \ No newline at end of file