Beispiel #1
0
        void ConvertMaterials()
        {
            const string legacyShaderPrefix = "UnityChanToonShader/";


            var guids = AssetDatabase.FindAssets("t:Material", null);

            foreach (var guid in guids)
            {
                string   path       = AssetDatabase.GUIDToAssetPath(guid);
                Material material   = AssetDatabase.LoadAssetAtPath <Material>(path);
                var      shaderName = material.shader.ToString();
                if (!shaderName.StartsWith(legacyShaderPrefix))
                {
                    continue;
                }
                Debug.Log(shaderName);
                material.shader      = Shader.Find("HDRP/Toon");
                _Transparent_Setting = (_UTS_Transparent)material.GetInt(ShaderPropTransparentEnabled);
                _StencilNo_Setting   = material.GetInt(ShaderPropStencilNo);
                _autoRenderQueue     = material.GetInt(ShaderPropAutoRenderQueue);
                _renderQueue         = material.renderQueue;
                _UTS_Technique technique = (_UTS_Technique)material.GetInt(ShaderPropUtsTechniqe);

                switch (technique)
                {
                case _UTS_Technique.DoubleShadeWithFeather:
                    material.DisableKeyword(ShaderDefineSHADINGGRADEMAP);
                    break;

                case _UTS_Technique.ShadingGradeMap:
                    material.EnableKeyword(ShaderDefineSHADINGGRADEMAP);
                    break;
                }
                BasicLookdevs(material);
                SetGameRecommendation(material);
                ApplyClippingMode(material);
                ApplyStencilMode(material);
                ApplyAngelRing(material);
                ApplyMatCapMode(material);
                ApplyQueueAndRenderType(technique, material);
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Beispiel #2
0
        void ApplyQueueAndRenderType(_UTS_Technique technique, Material material)
        {
            var stencilMode = (_UTS_StencilMode)material.GetInt(ShaderPropStencilMode);

            if (_autoRenderQueue == 1)
            {
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
            }

            const string OPAQUE                = "Opaque";
            const string TRANSPARENTCUTOUT     = "TransparentCutOut";
            const string TRANSPARENT           = "Transparent";
            const string RENDERTYPE            = "RenderType";
            const string IGNOREPROJECTION      = "IgnoreProjection";
            const string DO_IGNOREPROJECTION   = "True";
            const string DONT_IGNOREPROJECTION = "False";
            var          renderType            = OPAQUE;
            var          ignoreProjection      = DONT_IGNOREPROJECTION;

            if (_Transparent_Setting == _UTS_Transparent.On)
            {
                renderType       = TRANSPARENT;
                ignoreProjection = DO_IGNOREPROJECTION;
            }
            else
            {
                switch (technique)
                {
                case _UTS_Technique.DoubleShadeWithFeather:
                {
                    _UTS_ClippingMode clippingMode = (_UTS_ClippingMode)material.GetInt(ShaderPropClippingMode);
                    if (clippingMode == _UTS_ClippingMode.Off)
                    {
                    }
                    else
                    {
                        renderType = TRANSPARENTCUTOUT;
                    }

                    break;
                }

                case _UTS_Technique.ShadingGradeMap:
                {
                    _UTS_TransClippingMode transClippingMode = (_UTS_TransClippingMode)material.GetInt(ShaderPropClippingMode);
                    if (transClippingMode == _UTS_TransClippingMode.Off)
                    {
                    }
                    else
                    {
                        renderType = TRANSPARENTCUTOUT;
                    }

                    break;
                }
                }
            }
            if (_autoRenderQueue == 1)
            {
                if (_Transparent_Setting == _UTS_Transparent.On)
                {
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                }
                else if (stencilMode == _UTS_StencilMode.StencilMask)
                {
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest - 1;
                }
                else if (stencilMode == _UTS_StencilMode.StencilOut)
                {
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                }
            }
            else
            {
                material.renderQueue = _renderQueue;
            }

            material.SetOverrideTag(RENDERTYPE, renderType);
            material.SetOverrideTag(IGNOREPROJECTION, ignoreProjection);
        }