Esempio n. 1
0
        public static void InstallShaders(ShaderInstallation config)
        {
            string guid        = UniversalShaderPackageGUID;
            string packagePath = AssetDatabase.GUIDToAssetPath(guid);

            GetRootFolder();

            //TODO: Package up current shaders
            if (config == ShaderInstallation.BuiltIn)
            {
                //AssetDatabase.ExportPackage(PACKAGE_ROOT_FOLDER + "/Shaders/URP", packagePath, ExportPackageOptions.Default | ExportPackageOptions.Recurse);

                UpgradeMaterials(config);
            }
            else
            {
                if (packagePath == string.Empty)
                {
                    Debug.LogError("URP Shader/material package with the GUID: " + guid + ". Could not be found in the project, was it changed or not imported? It should be located in <i>" + PACKAGE_ROOT_FOLDER + "/Shaders/URP</i>");
                    return;
                }
                AssetDatabase.ImportPackage(packagePath, false);
                AssetDatabase.importPackageCompleted += new AssetDatabase.ImportPackageCallback(ImportURPCallback);
            }

#if UNITY_2019_3_OR_NEWER && FAE_DEV
            SwitchRenderPipeline.SetPipeline(config);
#endif
        }
Esempio n. 2
0
        public static void UpgradeMaterials(ShaderInstallation config)
        {
            string[] GUIDs = AssetDatabase.FindAssets("t: material", new string[] { PACKAGE_ROOT_FOLDER });

            int count = 0;

            if (GUIDs.Length > 0)
            {
                Material[] mats = new Material[GUIDs.Length];

                for (int i = 0; i < mats.Length; i++)
                {
                    EditorUtility.DisplayProgressBar("Material configuration", "Converting FAE materials for " + config, (float)i / mats.Length);
                    string path = AssetDatabase.GUIDToAssetPath(GUIDs[i]);

                    mats[i] = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));

                    string dest    = string.Empty;
                    string source  = mats[i].shader.name;
                    bool   matched = ShaderRelations.TryGetValue(source, out dest);

                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Get key by value (inverse lookup)
                        dest = ShaderRelations.FirstOrDefault(x => x.Value == source).Key;

                        matched = dest != null;
                    }

                    if (config == ShaderInstallation.UniversalRP)
                    {
                        //Set grass to foliage shader
                        if (source == "FAE/Grass")
                        {
                            dest    = urpName + "/FAE/FAE_Foliage";
                            matched = true;
                        }
                    }
                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Set foliage to grass shader
                        if (mats[i].name.Contains("Grass"))
                        {
                            dest    = "FAE/Grass";
                            matched = true;
                        }
                    }

                    if (source == null && dest == null)
                    {
                        continue;
                    }
                    if (string.Equals(dest, source))
                    {
                        continue;
                    }

                    if (matched)
                    {
                        if (config == ShaderInstallation.UniversalRP)
                        {
                            Texture mainTex = null;
                            if (mats[i].HasProperty("_MainTex"))
                            {
                                mainTex = mats[i].GetTexture("_MainTex");
                            }

                            if (mats[i].HasProperty("_Color"))
                            {
                                mats[i].SetColor("_BaseColor", mats[i].GetColor("_Color"));
                            }
                            if (mats[i].HasProperty("_TintColor"))
                            {
                                mats[i].SetColor("_BaseColor", mats[i].GetColor("_TintColor"));
                            }

                            //Grass to foliage switch
                            if (mats[i].HasProperty("_ColorTop"))
                            {
                                mats[i].SetColor("_Color", mats[i].GetColor("_ColorTop"));
                            }

                            if (mats[i].HasProperty("_MainTex"))
                            {
                                mats[i].SetTexture("_BaseMap", mainTex);
                            }


                            if (mats[i].name.Contains("Fogsheets") || mats[i].name.Contains("Wind Streak"))
                            {
                                //Set material to transparent
                                mats[i].SetOverrideTag("RenderType", "Transparent");
#if UNITY_2021_1_OR_NEWER
                                mats[i].SetInteger("_Surface", 1);
                                mats[i].SetInteger("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                                mats[i].SetInteger("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
#else
                                mats[i].SetInt("_Surface", 1);
                                mats[i].SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                                mats[i].SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
#endif
                                mats[i].DisableKeyword("_ALPHAPREMULTIPLY_ON");

                                //Additive blending
#if UNITY_2021_1_OR_NEWER
                                mats[i].SetInteger("_ColorMode", 1);
#else
                                mats[i].SetInt("_ColorMode", 1);
#endif
                                mats[i].DisableKeyword("_COLOROVERLAY_ON");
                                mats[i].DisableKeyword("_COLORCOLOR_ON");
                                mats[i].EnableKeyword("_COLORADDSUBDIFF_ON");
                                mats[i].SetVector("_BaseColorAddSubDiff", new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
                            }

                            if (mats[i].name.Contains("Grass"))
                            {
                                mats[i].SetFloat("_MaxWindStrength", 0.2f);
                                mats[i].SetFloat("_AmbientOcclusion", 0.15f);
                            }

                            mats[i].shader = Shader.Find(dest);

                            if (mainTex)
                            {
                                mats[i].SetTexture("_BaseMap", mainTex);
                            }
                        }

                        if (mats[i].HasProperty("_TransmissionAmount"))
                        {
                            mats[i].SetFloat("_TransmissionAmount", Mathf.Clamp(mats[i].GetFloat("_TransmissionAmount"), 0, 10));
                        }

                        //Debug.Log("src: " + source + " dst:" + dest);
                        mats[i].shader = Shader.Find(dest);

                        EditorUtility.SetDirty(mats[i]);
                        count++;
                    }
                    else
                    {
#if FAE_DEV
                        Debug.LogError("No matching " + config + " shader could be found for " + mats[i].shader.name);
#endif
                    }
                }
                EditorUtility.ClearProgressBar();

                Debug.Log(count + " materials were configured for the " + config + " render pipeline");

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                if (config == ShaderInstallation.UniversalRP)
                {
                    delayTime = (float)EditorApplication.timeSinceStartup + renameDelaySec;
                    EditorApplication.update += PostURPConversion;
                }
            }
        }
Esempio n. 3
0
        public static void UpgradeMaterials(ShaderInstallation config)
        {
            string[] GUIDs = AssetDatabase.FindAssets("t: material", new string[] { PACKAGE_ROOT_FOLDER });

            int count = 0;

            if (GUIDs.Length > 0)
            {
                Material[] mats = new Material[GUIDs.Length];

                for (int i = 0; i < mats.Length; i++)
                {
                    EditorUtility.DisplayProgressBar("Material configuration", "Converting FAE materials for " + config, (float)i / mats.Length);
                    string path = AssetDatabase.GUIDToAssetPath(GUIDs[i]);

                    mats[i] = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));

                    string dest    = string.Empty;
                    string source  = mats[i].shader.name;
                    bool   matched = ShaderRelations.TryGetValue(source, out dest);

                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Get key by value (inverse lookup)
                        dest = ShaderRelations.FirstOrDefault(x => x.Value == source).Key;

                        matched = dest != null;
                    }

                    if (config == ShaderInstallation.UniversalRP)
                    {
                        //Set grass to foliage shader
                        if (source == "FAE/Grass")
                        {
                            dest    = urpName + "/FAE/FAE_Foliage";
                            matched = true;
                        }
                    }
                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Set foliage to grass shader
                        if (mats[i].name.Contains("Grass"))
                        {
                            dest    = "FAE/Grass";
                            matched = true;
                        }
                    }

                    if (source == null && dest == null)
                    {
                        continue;
                    }
                    if (string.Equals(dest, source))
                    {
                        continue;
                    }

                    if (matched)
                    {
                        if (config == ShaderInstallation.UniversalRP)
                        {
                            Texture mainTex = null;
                            if (mats[i].HasProperty("_MainTex"))
                            {
                                mainTex = mats[i].GetTexture("_MainTex");
                            }

                            if ((source.Contains("WindStreak") || source.Contains("Fogsheets")))
                            {
                                //mats[i].EnableKeyword("_ALPHATEST_ON");
                                mats[i].EnableKeyword("_COLORADDSUBDIFF_ON");
                                mats[i].SetFloat("_ColorMode", 1);
                            }

                            if (source.Contains("Particle") && !source.Contains("Leaf"))
                            {
                                //Set material to transparent
                                mats[i].SetFloat("_Surface", 1);
                                mats[i].EnableKeyword("_COLORADDSUBDIFF_ON");
                                //Additive blending
                                mats[i].SetFloat("_ColorMode", 1);
                            }

                            if (mats[i].HasProperty("_Color"))
                            {
                                mats[i].SetColor("_BaseColor", mats[i].GetColor("_Color"));
                            }
                            if (mats[i].HasProperty("_TintColor"))
                            {
                                mats[i].SetColor("_BaseColor", mats[i].GetColor("_TintColor"));
                            }

                            //Grass to foliage switch
                            if (mats[i].HasProperty("_ColorTop"))
                            {
                                mats[i].SetColor("_Color", mats[i].GetColor("_ColorTop"));
                            }

                            if (mats[i].HasProperty("_MainTex"))
                            {
                                mats[i].SetTexture("_BaseMap", mats[i].GetTexture("_MainTex"));
                            }

                            if (mats[i].name.Contains("Grass"))
                            {
                                mats[i].SetFloat("_MaxWindStrength", 0.2f);
                                mats[i].SetFloat("_AmbientOcclusion", 0.15f);
                            }

                            mats[i].shader = Shader.Find(dest);
                            if (mainTex)
                            {
                                mats[i].SetTexture("_BaseMap", mainTex);
                            }
                        }

                        if (mats[i].HasProperty("_TransmissionAmount"))
                        {
                            mats[i].SetFloat("_TransmissionAmount", Mathf.Clamp(mats[i].GetFloat("_TransmissionAmount"), 0, 10));
                        }

                        //Debug.Log("src: " + source + " dst:" + dest);
                        mats[i].shader = Shader.Find(dest);

                        EditorUtility.SetDirty(mats[i]);
                        count++;
                    }
                    else
                    {
#if FAE_DEV
                        Debug.LogError("No matching " + config + " shader could be found for " + mats[i].shader.name);
#endif
                    }
                }
                EditorUtility.ClearProgressBar();


                Debug.Log(count + " materials were configured for the " + config + " render pipeline");

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                //If any controllers are present in the open scene, these need to be nudged to apply the correct shaders
                CliffAppearance[] cliffConstrollers = GameObject.FindObjectsOfType <CliffAppearance>();
                for (int i = 0; i < cliffConstrollers.Length; i++)
                {
                    cliffConstrollers[i].OnEnable();
                }

                if (config == ShaderInstallation.UniversalRP)
                {
                    if (EditorUtility.DisplayDialog("Fantasy Adventure Environment", "Ensure the Depth/Opaque Texture options are enabled in your pipeline settings, otherwise the water isn't visible in the game view", "Show me", "OK"))
                    {
                        Selection.activeObject = UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset;
                    }
                }
            }
        }
Esempio n. 4
0
        public static void UpgradeMaterials(ShaderInstallation config)
        {
            string[] GUIDs = AssetDatabase.FindAssets("t: material", new string[] { PACKAGE_ROOT_FOLDER });

            int count = 0;

            if (GUIDs.Length > 0)
            {
                Material[] mats = new Material[GUIDs.Length];

                for (int i = 0; i < mats.Length; i++)
                {
                    EditorUtility.DisplayProgressBar("Material configuration", "Converting FAE materials for " + config, (float)i / mats.Length);
                    string path = AssetDatabase.GUIDToAssetPath(GUIDs[i]);

                    mats[i] = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));

                    string dest    = string.Empty;
                    string source  = mats[i].shader.name;
                    bool   matched = ShaderRelations.TryGetValue(source, out dest);

                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Get key by value (inverse lookup)
                        dest = ShaderRelations.FirstOrDefault(x => x.Value == source).Key;

                        matched = dest != null;
                    }

                    if (config == ShaderInstallation.UniversalRP)
                    {
                        //Set grass to foliage shader
                        if (source == "FAE/Grass")
                        {
                            dest    = urpName + "/FAE/FAE_Foliage";
                            matched = true;
                        }
                    }
                    if (config == ShaderInstallation.BuiltIn)
                    {
                        //Set foliage to grass shader
                        if (mats[i].name.Contains("Grass"))
                        {
                            dest    = "FAE/Grass";
                            matched = true;
                        }
                    }

                    if (source == null && dest == null)
                    {
                        continue;
                    }
                    if (string.Equals(dest, source))
                    {
                        continue;
                    }

                    if (matched)
                    {
                        if (source.Contains("Particle") && !source.Contains("Leaf"))
                        {
                            //Set material to transparent
                            if (mats[i].HasProperty("_Surface"))
                            {
                                mats[i].SetFloat("_Surface", 1);
                            }
                            //Additive blending
                            if (mats[i].HasProperty("_ColorMode"))
                            {
                                mats[i].SetFloat("_ColorMode", 1);
                            }
                        }

                        if (config == ShaderInstallation.UniversalRP && mats[i].HasProperty("_MainTex"))
                        {
                            //Grass to foliage switch
                            if (mats[i].HasProperty("_ColorTop"))
                            {
                                mats[i].SetColor("_Color", mats[i].GetColor("_ColorTop"));
                            }

                            if (mats[i].HasProperty("_MainTex"))
                            {
                                mats[i].SetTexture("_BaseMap", mats[i].GetTexture("_MainTex"));
                            }
                        }

                        if (mats[i].HasProperty("_TransmissionAmount"))
                        {
                            mats[i].SetFloat("_TransmissionAmount", Mathf.Clamp(mats[i].GetFloat("_TransmissionAmount"), 0, 10));
                        }

                        //Debug.Log("src: " + source + " dst:" + dest);
                        mats[i].shader = Shader.Find(dest);

                        EditorUtility.SetDirty(mats[i]);
                        count++;
                    }
                    else
                    {
#if FAE_DEV
                        Debug.LogError("No matching " + config + " shader could be found for " + mats[i].shader.name);
#endif
                    }
                }
                EditorUtility.ClearProgressBar();

                //If any controllers are present in the open scene, these need to be nudged to apply the correct shaders
                CliffAppearance[] cliffConstrollers = GameObject.FindObjectsOfType <CliffAppearance>();
                for (int i = 0; i < cliffConstrollers.Length; i++)
                {
                    cliffConstrollers[i].OnEnable();
                }

                Debug.Log(count + " materials were configured for the " + config + " render pipeline");

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
            }
        }