/// <summary>
        /// Add CTS to a specific terrain
        /// </summary>
        /// <param name="terrain">Terrain to be added to</param>
        public void AddCTSToTerrain(Terrain terrain)
        {
            if (terrain == null)
            {
                return;
            }
            CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();

            if (shader == null)
            {
                shader = terrain.gameObject.AddComponent <CompleteTerrainShader>();
                CompleteTerrainShader.SetDirty(shader, false, false);
                CompleteTerrainShader.SetDirty(terrain, false, false);
                m_shaderList.Add(shader);
            }
            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (Terrain.activeTerrain != null)
                {
                    EditorGUIUtility.PingObject(Terrain.activeTerrain);
                }
            }
            #endif
        }
 public void BroadcastShaderSetup(CTSProfile profile)
 {
     if (Object.op_Inequality((Object)Terrain.get_activeTerrain(), (Object)null))
     {
         CompleteTerrainShader component = (CompleteTerrainShader)((Component)Terrain.get_activeTerrain()).GetComponent <CompleteTerrainShader>();
         if (Object.op_Inequality((Object)component, (Object)null) && Object.op_Inequality((Object)component.Profile, (Object)null) && ((Object)component.Profile).get_name() == ((Object)profile).get_name())
         {
             component.UpdateProfileFromTerrainForced();
             this.BroadcastProfileUpdate(profile);
             return;
         }
     }
     foreach (CompleteTerrainShader shader in this.m_shaderSet)
     {
         if (Object.op_Inequality((Object)shader.Profile, (Object)null))
         {
             if (Object.op_Equality((Object)profile, (Object)null))
             {
                 shader.UpdateProfileFromTerrainForced();
             }
             else if (((Object)shader.Profile).get_name() == ((Object)profile).get_name())
             {
                 shader.UpdateProfileFromTerrainForced();
                 this.BroadcastProfileUpdate(profile);
                 break;
             }
         }
     }
 }
        /// <summary>
        /// Broadcast a normal texture switch
        /// </summary>
        /// <param name="profile">Selected profile - null means all CTS terrains</param>
        /// <param name="texture">New texture</param>
        /// <param name="textureIdx">Index</param>
        /// <param name="tiling">Tiling</param>
        public void BroadcastNormalTextureSwitch(CTSProfile profile, Texture2D texture, int textureIdx, float tiling)
        {
            //Make sure shaders are registered
            RegisterAllShaders(true);

            //Do the texture switch
            CompleteTerrainShader shader = null;

            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                shader = m_shaderList[idx];
                if (shader != null && shader.Profile != null)
                {
                    if (profile == null)
                    {
                        shader.ReplaceNormalInTerrain(texture, textureIdx, tiling);
                    }
                    else
                    {
                        if (shader.Profile.GetInstanceID() == profile.GetInstanceID())
                        {
                            shader.ReplaceNormalInTerrain(texture, textureIdx, tiling);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Broadcast a profile update to all the shaders using it in the scene
        /// </summary>
        /// <param name="profile">Profile being updated</param>
        public void BroadcastProfileUpdate(CTSProfile profile)
        {
            //Make sure shaders are registered
            RegisterAllShaders();

            //Also make sure weather is registered
            RegisterAllControllers();

            //Can not do this on a null profile
            if (profile == null)
            {
                Debug.LogWarning("Cannot update shader on null profile.");
                return;
            }

            //Broadcast the update
            CompleteTerrainShader shader = null;

            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                shader = m_shaderList[idx];
                if (shader != null && shader.Profile != null)
                {
                    if (shader.Profile.GetInstanceID() == profile.GetInstanceID())
                    {
                        shader.UpdateMaterialAndShader();
                    }
                }
            }
        }
        /// <summary>
        /// Broadcast bake terrains
        /// </summary>
        public void BroadcastBakeTerrains()
        {
            //Make sure shaders are registered
            RegisterAllShaders(true);

            //Broadcast the setup
            CompleteTerrainShader shader = null;

            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                shader = m_shaderList[idx];
                if (shader != null)
                {
                    if (shader.AutoBakeNormalMap)
                    {
                        shader.BakeTerrainNormals();
                    }
                    if (shader.AutoBakeColorMap)
                    {
                        if (!shader.AutoBakeGrassIntoColorMap)
                        {
                            shader.BakeTerrainBaseMap();
                        }
                        else
                        {
                            shader.BakeTerrainBaseMapWithGrass();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Return true if the profile is actively assigned to a terrain
        /// </summary>
        /// <param name="profile">The profile being checked</param>
        /// <returns>True if its been assiged to a terrain</returns>
        public bool ProfileIsActive(CTSProfile profile)
        {
            //Return rubbish if we have no usage
            if (profile == null)
            {
                return(false);
            }

            //Make sure shaders are registered
            RegisterAllShaders();

            CompleteTerrainShader shader = null;

            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                shader = m_shaderList[idx];
                if (shader != null && shader.Profile != null)
                {
                    if (shader.Profile.GetInstanceID() == profile.GetInstanceID())
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 7
0
        public static void AddCTSRuntimeWeatherToScene(MenuCommand menuCommand)
        {
            //Add a weather manager
            GameObject ctsWeatherManager = GameObject.Find("CTS Weather Manager");

            if (ctsWeatherManager == null)
            {
                ctsWeatherManager      = new GameObject();
                ctsWeatherManager.name = "CTS Weather Manager";
                ctsWeatherManager.AddComponent <CTSWeatherManager>();
                CompleteTerrainShader.SetDirty(ctsWeatherManager, false, false);
            }
            EditorGUIUtility.PingObject(ctsWeatherManager);

            //And now add weather controllers
            foreach (var terrain in Terrain.activeTerrains)
            {
                CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
                if (shader != null)
                {
                    CTSWeatherController controller = terrain.gameObject.GetComponent <CTSWeatherController>();
                    if (controller == null)
                    {
                        controller = terrain.gameObject.AddComponent <CTSWeatherController>();
                        CompleteTerrainShader.SetDirty(terrain, false, false);
                        CompleteTerrainShader.SetDirty(controller, false, false);
                    }
                }
            }
        }
 /// <summary>
 /// Add CTS to all terrains
 /// </summary>
 public void AddCTSToAllTerrains()
 {
     m_shaderList.Clear();
     foreach (var terrain in Terrain.activeTerrains)
     {
         CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
         if (shader == null)
         {
             shader = terrain.gameObject.AddComponent <CompleteTerrainShader>();
             CompleteTerrainShader.SetDirty(shader, false, false);
             CompleteTerrainShader.SetDirty(terrain, false, false);
         }
         m_shaderList.Add(shader);
         m_lastShaderListUpdate = DateTime.Now;
     }
     #if UNITY_EDITOR
     //AssetDatabase.SaveAssets();
     if (!Application.isPlaying)
     {
         if (Terrain.activeTerrain != null)
         {
             EditorGUIUtility.PingObject(Terrain.activeTerrain);
         }
     }
     #endif
 }
Esempio n. 9
0
        /// <summary>
        /// Bakes the normal map on a terrain with a CTS component
        /// </summary>
        /// <param name="t"></param>
        private static void BakeCTSNormalsForTerrain(Terrain t)
        {
            CompleteTerrainShader cts = t.GetComponent <CompleteTerrainShader>();

            if (cts != null)
            {
                cts.BakeTerrainNormals();
            }
        }
 public void AddCTSToTerrain(Terrain terrain)
 {
     if (Object.op_Equality((Object)terrain, (Object)null) || !Object.op_Equality((Object)((Component)terrain).get_gameObject().GetComponent <CompleteTerrainShader>(), (Object)null))
     {
         return;
     }
     ((Component)terrain).get_gameObject().AddComponent <CompleteTerrainShader>();
     CompleteTerrainShader.SetDirty((Object)terrain, false, false);
 }
 public void AddCTSToAllTerrains()
 {
     foreach (Terrain activeTerrain in Terrain.get_activeTerrains())
     {
         if (Object.op_Equality((Object)((Component)activeTerrain).get_gameObject().GetComponent <CompleteTerrainShader>(), (Object)null))
         {
             ((Component)activeTerrain).get_gameObject().AddComponent <CompleteTerrainShader>();
             CompleteTerrainShader.SetDirty((Object)activeTerrain, false, false);
         }
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Called when we select this in the scene
        /// </summary>
        void OnEnable()
        {
            //Check for target
            if (target == null)
            {
                return;
            }

            //Force a shader update
            CTSTerrainManager.Instance.RegisterAllShaders();

            //Setup target
            m_shader = (CompleteTerrainShader)target;
        }
Esempio n. 13
0
        public static void AddWorldAPIToScene(MenuCommand menuCommand)
        {
            //First - are we even here present
            Type worldAPIType = CompleteTerrainShader.GetType("WAPI.WorldManager");

            if (worldAPIType == null)
            {
                EditorUtility.DisplayDialog("World Manager API", "World Manager is not present in your project. Please go to http://www.procedural-worlds.com/blog/wapi/ to learn about it.", "OK");
                Application.OpenURL("http://www.procedural-worlds.com/blog/wapi/");
                Application.OpenURL("https://github.com/adamgoodrich/WorldManager");
                return;
            }

            //First add a weather manager
            GameObject ctsWeatherManager = GameObject.Find("CTS Weather Manager");

            if (ctsWeatherManager == null)
            {
                ctsWeatherManager      = new GameObject();
                ctsWeatherManager.name = "CTS Weather Manager";
                ctsWeatherManager.AddComponent <CTSWeatherManager>();
                CompleteTerrainShader.SetDirty(ctsWeatherManager, false, false);
            }
            EditorGUIUtility.PingObject(ctsWeatherManager);

            //And now add weather controllers
            foreach (var terrain in Terrain.activeTerrains)
            {
                CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
                if (shader != null)
                {
                    CTSWeatherController controller = terrain.gameObject.GetComponent <CTSWeatherController>();
                    if (controller == null)
                    {
                        controller = terrain.gameObject.AddComponent <CTSWeatherController>();
                        CompleteTerrainShader.SetDirty(terrain, false, false);
                        CompleteTerrainShader.SetDirty(controller, false, false);
                    }
                }
            }

            //And now add world API integration component to weather manager
            #if WORLDAPI_PRESENT
            var worldAPIIntegration = ctsWeatherManager.GetComponent <CTSWorldAPIIntegration>();
            if (worldAPIIntegration == null)
            {
                worldAPIIntegration = ctsWeatherManager.AddComponent <CTSWorldAPIIntegration>();
            }
            #endif
        }
        /// <summary>
        /// Broadcast a message to select this profile on all the specific terrain provided
        /// </summary>
        /// <param name="profile">Profile being selected</param>
        /// <param name="terrain">Terrain being selected</param>
        public void BroadcastProfileSelect(CTSProfile profile, Terrain terrain)
        {
            if (profile == null || terrain == null)
            {
                return;
            }
            CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();

            if (shader != null)
            {
                shader.Profile = profile;
                shader.UpdateMaterialAndShader();
            }
        }
        public void BroadcastProfileSelect(CTSProfile profile, Terrain terrain)
        {
            if (Object.op_Equality((Object)profile, (Object)null) || Object.op_Equality((Object)terrain, (Object)null))
            {
                return;
            }
            CompleteTerrainShader completeTerrainShader = (CompleteTerrainShader)((Component)terrain).get_gameObject().GetComponent <CompleteTerrainShader>();

            if (Object.op_Equality((Object)completeTerrainShader, (Object)null))
            {
                completeTerrainShader = (CompleteTerrainShader)((Component)terrain).get_gameObject().AddComponent <CompleteTerrainShader>();
            }
            completeTerrainShader.Profile = profile;
        }
Esempio n. 16
0
        private static void ApplyCTSProfile(Terrain terrain, CTSProfile ctsProfile, bool bakeTerrainNormals)
        {
            CompleteTerrainShader cts = terrain.gameObject.GetComponent <CompleteTerrainShader>();

            if (cts == null)
            {
                cts = terrain.gameObject.AddComponent <CompleteTerrainShader>();
            }
            cts.Profile = ctsProfile;
            if (bakeTerrainNormals)
            {
                cts.BakeTerrainNormals();
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Removes the CTS components from the terrain
        /// </summary>
        /// <param name="terrain">The terrain to remove the CTS components from</param>
        private static void RemoveCTSFromTerrain(Terrain terrain)
        {
            CompleteTerrainShader cts = terrain.GetComponent <CompleteTerrainShader>();

            if (cts != null)
            {
                cts.Profile = null;
                cts.ApplyMaterialAndUpdateShader();
                UnityEngine.Object.DestroyImmediate(cts);
            }
            CTSWeatherController wc = terrain.GetComponent <CTSWeatherController>();

            if (wc != null)
            {
                UnityEngine.Object.DestroyImmediate(wc);
            }
        }
        /// <summary>
        /// Broadcast a shader setup on the selected profile in the scene, otherwise all
        /// </summary>
        /// <param name="profile">Profile being updated, otherwise all</param>
        public void BroadcastShaderSetup(CTSProfile profile)
        {
            //Make sure shaders are registered
            RegisterAllShaders(true);

            //First - check to see if we have one on the currently selected terrain - this will usually be where texture changes have been made
            CompleteTerrainShader shader = null;

            if (Terrain.activeTerrain != null)
            {
                shader = Terrain.activeTerrain.GetComponent <CompleteTerrainShader>();
                if (shader != null && shader.Profile != null)
                {
                    if (shader.Profile.GetInstanceID() == profile.GetInstanceID())
                    {
                        shader.UpdateProfileFromTerrainForced();
                        BroadcastProfileUpdate(profile);
                        return;
                    }
                }
            }

            //Otherwise broadcast the setup
            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                shader = m_shaderList[idx];
                if (shader != null && shader.Profile != null)
                {
                    if (profile == null)
                    {
                        shader.UpdateProfileFromTerrainForced();
                    }
                    else
                    {
                        //Find the first match and update it
                        if (shader.Profile.GetInstanceID() == profile.GetInstanceID())
                        {
                            shader.UpdateProfileFromTerrainForced();
                            BroadcastProfileUpdate(profile);
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Bakes the color map on a terrain with a CTS component
        /// </summary>
        /// <param name="t"></param>
        private static void BakeCTSColorMapForTerrain(Terrain t, bool bakeGrass)
        {
            CompleteTerrainShader cts = t.GetComponent <CompleteTerrainShader>();

            if (cts != null)
            {
                if (bakeGrass)
                {
                    cts.AutoBakeGrassIntoColorMap = true;
                    cts.BakeTerrainBaseMapWithGrass();
                }
                else
                {
                    cts.AutoBakeGrassIntoColorMap = false;
                    cts.BakeTerrainBaseMap();
                }
            }
        }
Esempio n. 20
0
        public static void CreateCTSProfile1(MenuCommand menuCommand)
        {
            CTSProfile profile = ScriptableObject.CreateInstance <CTS.CTSProfile>();

            profile.GlobalDetailNormalMap = GetAsset("T_Detail_Normal_3.png", typeof(Texture2D)) as Texture2D;
            profile.GeoAlbedo             = GetAsset("T_Geo_00.png", typeof(Texture2D)) as Texture2D;
            profile.SnowAlbedo            = GetAsset("T_Ground_Snow_1_A_Sm.tga", typeof(Texture2D)) as Texture2D;
            profile.SnowNormal            = GetAsset("T_Ground_Snow_1_N.tga", typeof(Texture2D)) as Texture2D;
            profile.SnowHeight            = GetAsset("T_Ground_Snow_1_H.png", typeof(Texture2D)) as Texture2D;
            profile.SnowAmbientOcclusion  = GetAsset("T_Ground_Snow_1_AO.tga", typeof(Texture2D)) as Texture2D;
            profile.SnowNoise             = GetAsset("T_Ground_Snow_Noise_1.tga", typeof(Texture2D)) as Texture2D;
            profile.m_ctsDirectory        = CompleteTerrainShader.GetCTSDirectory();
            Directory.CreateDirectory(profile.m_ctsDirectory + "Profiles/");
            AssetDatabase.CreateAsset(profile, string.Format("{0}Profiles/CTS_Profile_{1:yyMMdd-HHmm}.asset", profile.m_ctsDirectory, DateTime.Now));
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            CTSTerrainManager.Instance.BroadcastProfileSelect(profile);
            EditorGUIUtility.PingObject(profile);
        }
Esempio n. 21
0
        public void ConstructTerrainReplacementNormals()
        {
            if (Application.get_isPlaying())
            {
                return;
            }
            while (this.m_replacementTerrainNormals.Count > this.m_terrainTextures.Count)
            {
                this.m_replacementTerrainNormals.RemoveAt(this.m_replacementTerrainNormals.Count - 1);
            }
            while (this.m_replacementTerrainNormals.Count < this.m_terrainTextures.Count)
            {
                this.m_replacementTerrainNormals.Add((Texture2D)null);
            }
            string path1 = this.m_ctsDirectory + "Terrains/ReplacementTextures/";

            Directory.CreateDirectory(path1);
            for (int index = 0; index < this.m_terrainTextures.Count; ++index)
            {
                CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index];
                if (Object.op_Inequality((Object)terrainTexture.Normal, (Object)null))
                {
                    string path2 = path1 + ((Object)terrainTexture.Normal).get_name() + "_nrm_cts.png";
                    if (!File.Exists(path2))
                    {
                        Texture2D texture2D = CTSProfile.ResizeTexture(terrainTexture.Normal, this.m_normalFormat, this.m_normalAniso, 64, 64, false, true, false);
                        ((Object)texture2D).set_name(((Object)terrainTexture.Normal).get_name() + "_nrm_cts");
                        this.m_replacementTerrainNormals[index] = texture2D;
                        byte[] png = ImageConversion.EncodeToPNG(this.m_replacementTerrainNormals[index]);
                        File.WriteAllBytes(path2, png);
                    }
                }
                else
                {
                    this.m_replacementTerrainNormals[index] = (Texture2D)null;
                }
            }
            CompleteTerrainShader.SetDirty((Object)this, false, true);
        }
Esempio n. 22
0
        /// <summary>
        /// Editor UX
        /// </summary>
        public override void OnInspectorGUI()
        {
            #region Setup and introduction

            //Get the target
            m_manager = (CTSWeatherManager)target;

            //Set up the styles
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            if (m_wrapHelpStyle == null)
            {
                m_wrapHelpStyle          = new GUIStyle(GUI.skin.label);
                m_wrapHelpStyle.richText = true;
                m_wrapHelpStyle.wordWrap = true;
            }

            //Text intro
            GUILayout.BeginVertical(string.Format("CTS ({0}.{1})", CTSConstants.MajorVersion, CTSConstants.MinorVersion), m_boxStyle);
            if (m_globalHelp)
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?-"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?+"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }

            GUILayout.Space(20);

            EditorGUILayout.LabelField("Welcome to CTS Weather Manager. Click ? for help.", m_wrapStyle);
            DrawHelpSectionLabel("Overview");

            if (m_globalHelp)
            {
                if (GUILayout.Button(GetLabel("View Online Tutorials & Docs")))
                {
                    Application.OpenURL("http://www.procedural-worlds.com/cts/");
                }
            }

            GUILayout.EndVertical();

            #endregion

            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            GUILayout.BeginVertical("Control", m_boxStyle);
            GUILayout.Space(20f);
            DrawHelpSectionLabel("Control");


            GUILayout.BeginVertical(m_boxStyle);
            float rainPower = EditorGUILayout.Slider(GetLabel("Rain Power"), m_manager.RainPower, 0f, 1f);
            DrawHelpLabel("Rain Power");

            float snowPower = EditorGUILayout.Slider(GetLabel("Snow Power"), m_manager.SnowPower, 0f, 1f);
            DrawHelpLabel("Snow Power");

            float season = EditorGUILayout.Slider(GetLabel("Season"), m_manager.Season, 0f, 3.9999f);
            DrawHelpLabel("Season");

            EditorGUI.indentLevel++;
            if (season < 1f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Winter {1:0}% Spring", (1f - season) * 100f, season * 100f));
            }
            else if (season < 2f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Spring {1:0}% Summer", (2f - season) * 100f, (season - 1f) * 100f));
            }
            else if (season < 3f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Summer {1:0}% Autumn", (3f - season) * 100f, (season - 2f) * 100f));
            }
            else
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Autumn {1:0}% Winter", (4f - season) * 100f, (season - 3f) * 100f));
            }
            EditorGUI.indentLevel--;
            GUILayout.EndVertical();

            GUILayout.EndVertical();


            GUILayout.BeginVertical("Settings", m_boxStyle);
            GUILayout.Space(20f);
            DrawHelpSectionLabel("Settings");

            GUILayout.BeginVertical(m_boxStyle);
            float minSnowHeight = EditorGUILayout.FloatField(GetLabel("Min Snow Height"), m_manager.SnowMinHeight);
            DrawHelpLabel("Min Snow Height");

            float maxSmoothness = EditorGUILayout.Slider(GetLabel("Max Smoothness"), m_manager.MaxRainSmoothness, 0f, 30f);
            DrawHelpLabel("Max Smoothness");

            Color winterTint = EditorGUILayout.ColorField(GetLabel("Winter Tint"), m_manager.WinterTint, true, false, false, null);
            DrawHelpLabel("Winter Tint");

            Color springTint = EditorGUILayout.ColorField(GetLabel("Spring Tint"), m_manager.SpringTint, true, false, false, null);
            DrawHelpLabel("Spring Tint");

            Color summerTint = EditorGUILayout.ColorField(GetLabel("Summer Tint"), m_manager.SummerTint, true, false, false, null);
            DrawHelpLabel("Summer Tint");

            Color autumnTint = EditorGUILayout.ColorField(GetLabel("Autumn Tint"), m_manager.AutumnTint, true, false, false, null);
            DrawHelpLabel("Autumn Tint");

            GUILayout.EndVertical();

            GUILayout.EndVertical();

            //Handle changes
            if (EditorGUI.EndChangeCheck())
            {
                CompleteTerrainShader.SetDirty(m_manager, false, false);

                //UX Settings
                m_manager.SnowPower         = snowPower;
                m_manager.SnowMinHeight     = minSnowHeight;
                m_manager.RainPower         = rainPower;
                m_manager.Season            = season;
                m_manager.MaxRainSmoothness = maxSmoothness;
                m_manager.WinterTint        = winterTint;
                m_manager.SpringTint        = springTint;
                m_manager.SummerTint        = summerTint;
                m_manager.AutumnTint        = autumnTint;
            }
        }
 public void UnregisterShader(CompleteTerrainShader shader)
 {
     this.m_shaderSet.Remove(shader);
 }
 public void RegisterShader(CompleteTerrainShader shader)
 {
     this.m_shaderSet.Add(shader);
 }
Esempio n. 25
0
            public void Apply(Terrain terrain)
            {
                //saving enable state (since CTS switch to default on enabled when no profile assigned)
                bool activeState = terrain.gameObject.activeSelf;

                terrain.gameObject.SetActive(false);

                CompleteTerrainShader cts = terrain.GetComponent <CompleteTerrainShader>();

                if (cts == null)
                {
                    cts = terrain.gameObject.AddComponent <CompleteTerrainShader>();
                }

                //firstly add splat textures (otherwise CTS will log error on profile assign in playmode)
                int           resolution = (int)Mathf.Sqrt(textureColors[0].Length);
                TextureFormat texFormat  = TextureFormat.RGBA32;

                for (int i = 0; i < textureColors.Length; i++)
                {
                    if (textureColors[i] == null)
                    {
                        continue;
                    }

                    Texture2D tex =
                        i == 0 ? cts.Splat1 :
                        i == 1 ? cts.Splat2 :
                        i == 2 ? cts.Splat3 :
                        cts.Splat4;

                    if (tex == null || tex.width != resolution || tex.height != resolution || tex.format != texFormat)
                    {
                        if (tex != null)
                        {
                                                        #if UNITY_EDITOR
                            if (!UnityEditor.AssetDatabase.Contains(tex))
                                                        #endif
                            GameObject.DestroyImmediate(tex);
                        }

                        tex          = new Texture2D(resolution, resolution, texFormat, false, true);
                        tex.wrapMode = TextureWrapMode.Mirror;                         //to avoid border seams
                        //tex.hideFlags = HideFlags.DontSave;
                        //tex.filterMode = FilterMode.Point;

                        if (i == 0)
                        {
                            cts.Splat1 = tex;
                        }
                        else if (i == 1)
                        {
                            cts.Splat2 = tex;
                        }
                        else if (i == 2)
                        {
                            cts.Splat3 = tex;
                        }
                        else
                        {
                            cts.Splat4 = tex;
                        }
                    }

                    tex.SetPixels(0, 0, tex.width, tex.height, textureColors[i]);
                    tex.Apply();
                }

                //then asssign profile
                if (cts.Profile != profile)
                {
                    cts.Profile = profile;
                }

                //enable
                terrain.gameObject.SetActive(activeState);
            }
Esempio n. 26
0
        /// <summary>
        /// Editor UX
        /// </summary>
        public override void OnInspectorGUI()
        {
            //Set the target
            m_shader = (CompleteTerrainShader)target;

            if (m_shader == null)
            {
                return;
            }

            #region Setup and introduction

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            if (m_wrapHelpStyle == null)
            {
                m_wrapHelpStyle          = new GUIStyle(GUI.skin.label);
                m_wrapHelpStyle.richText = true;
                m_wrapHelpStyle.wordWrap = true;
            }

            //Text intro
            GUILayout.BeginVertical(string.Format("CTS ({0}.{1})", CTSConstants.MajorVersion, CTSConstants.MinorVersion), m_boxStyle);
            if (m_globalHelp)
            {
                Rect rect = EditorGUILayout.BeginVertical();
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?-"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?+"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Welcome to CTS. Click ? for help.", m_wrapStyle);
            DrawHelpSectionLabel("Overview");

            if (m_globalHelp)
            {
                if (GUILayout.Button(GetLabel("View Online Tutorials & Docs")))
                {
                    Application.OpenURL("http://www.procedural-worlds.com/cts/");
                }
            }

            GUILayout.EndVertical();
            #endregion

            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            GUILayout.Space(5);

            GUILayout.BeginVertical(m_boxStyle);

            CTSProfile profile = (CTSProfile)EditorGUILayout.ObjectField(GetLabel("Profile"), m_shader.Profile, typeof(CTSProfile), false);
            DrawHelpLabel("Profile");

            EditorGUILayout.LabelField(GetLabel("Global NormalMap"));
            DrawHelpLabel("Global NormalMap");
            EditorGUI.indentLevel++;

            bool autobakeNormalMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeNormalMap);
            DrawHelpLabel("AutoBake");

            Texture2D globalNormal = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Normal Map"), m_shader.NormalMap, typeof(Texture2D), false, GUILayout.Height(16f));
            DrawHelpLabel("NormalMap");

            EditorGUI.indentLevel--;

            EditorGUILayout.LabelField(GetLabel("Global ColorMap"));
            DrawHelpLabel("Global ColorMap");
            EditorGUI.indentLevel++;

            bool autobakeColorMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeColorMap);
            DrawHelpLabel("AutoBake");
            bool  autoBakeGrassIntoColorMap = m_shader.AutoBakeGrassIntoColorMap;
            float autoBakeGrassMixStrength  = m_shader.AutoBakeGrassMixStrength;
            float autoBakeGrassDarkenAmount = m_shader.AutoBakeGrassDarkenAmount;
            autoBakeGrassIntoColorMap = EditorGUILayout.Toggle(GetLabel("Bake Grass"), autoBakeGrassIntoColorMap);
            DrawHelpLabel("Bake Grass");
            if (autoBakeGrassIntoColorMap)
            {
                EditorGUI.indentLevel++;
                autoBakeGrassMixStrength = EditorGUILayout.Slider(GetLabel("Grass Strength"), autoBakeGrassMixStrength, 0f, 1f);
                DrawHelpLabel("Grass Strength");
                autoBakeGrassDarkenAmount = EditorGUILayout.Slider(GetLabel("Darken Strength"), autoBakeGrassDarkenAmount, 0f, 1f);
                DrawHelpLabel("Darken Strength");
                EditorGUI.indentLevel--;
            }

            Texture2D globalColorMap = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Color Map"), m_shader.ColorMap, typeof(Texture2D), false, GUILayout.Height(16f));
            DrawHelpLabel("ColorMap");

            EditorGUI.indentLevel--;

            bool useCutout = EditorGUILayout.Toggle(GetLabel("Use Cutout"), m_shader.UseCutout);
            DrawHelpLabel("Use Cutout");
            float     heightCutout     = m_shader.CutoutHeight;
            Texture2D globalCutoutMask = m_shader.CutoutMask;
            if (useCutout)
            {
                EditorGUI.indentLevel++;
                heightCutout = EditorGUILayout.FloatField(GetLabel("Cutout Below"), heightCutout);
                DrawHelpLabel("Cutout Below");
                globalCutoutMask = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Cutout Mask"), globalCutoutMask, typeof(Texture2D), false, GUILayout.Height(16f));
                DrawHelpLabel("Cutout Mask");
                EditorGUI.indentLevel--;
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(GetLabel("Bake NormalMap")))
            {
                m_shader.BakeTerrainNormals();
                globalNormal = m_shader.NormalMap;
            }
            if (GUILayout.Button(GetLabel("Bake ColorMap")))
            {
                if (!autoBakeGrassIntoColorMap)
                {
                    m_shader.BakeTerrainBaseMap();
                }
                else
                {
                    m_shader.BakeTerrainBaseMapWithGrass();
                }
                globalColorMap = m_shader.ColorMap;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.Space(5);

            #region Handle changes

            //Check for changes, make undo record, make changes and let editor know we are dirty
            if (EditorGUI.EndChangeCheck())
            {
                CompleteTerrainShader.SetDirty(m_shader, false, false);
                m_shader.Profile                   = profile;
                m_shader.NormalMap                 = globalNormal;
                m_shader.AutoBakeNormalMap         = autobakeNormalMap;
                m_shader.ColorMap                  = globalColorMap;
                m_shader.AutoBakeColorMap          = autobakeColorMap;
                m_shader.AutoBakeGrassIntoColorMap = autoBakeGrassIntoColorMap;
                m_shader.AutoBakeGrassMixStrength  = autoBakeGrassMixStrength;
                m_shader.AutoBakeGrassDarkenAmount = autoBakeGrassDarkenAmount;
                m_shader.UseCutout                 = useCutout;
                m_shader.CutoutMask                = globalCutoutMask;
                m_shader.CutoutHeight              = heightCutout;
                m_shader.UpdateMaterialAndShader();
            }
            #endregion
        }
Esempio n. 27
0
        private void GetTexturesAndSettingsAtCurrentLocation()
        {
            this.m_textureList.Clear();
            CTSProfile ctsProfile = (CTSProfile)null;

            SplatPrototype[] splatPrototypeArray = new SplatPrototype[0];
            Vector3          position            = ((Component)this).get_transform().get_position();
            Vector3          localScale          = ((Component)this).get_transform().get_localScale();
            Vector3          eulerAngles         = ((Component)this).get_transform().get_eulerAngles();

            for (int index1 = this.m_filters.Length - 1; index1 >= 0; --index1)
            {
                Mesh sharedMesh = this.m_filters[index1].get_sharedMesh();
                if (Object.op_Inequality((Object)sharedMesh, (Object)null))
                {
                    Vector3[] vertices = sharedMesh.get_vertices();
                    for (int index2 = vertices.Length - 1; index2 >= 0; --index2)
                    {
                        Vector3 locationWU = Vector3.op_Addition(position, Quaternion.op_Multiply(Quaternion.Euler(eulerAngles), Vector3.Scale(vertices[index2], localScale)));
                        Terrain terrain    = this.GetTerrain(locationWU);
                        if (Object.op_Inequality((Object)terrain, (Object)null))
                        {
                            if (Object.op_Equality((Object)ctsProfile, (Object)null))
                            {
                                CompleteTerrainShader component = (CompleteTerrainShader)((Component)terrain).get_gameObject().GetComponent <CompleteTerrainShader>();
                                if (Object.op_Inequality((Object)component, (Object)null))
                                {
                                    ctsProfile = component.Profile;
                                }
                            }
                            if (splatPrototypeArray.Length == 0)
                            {
                                splatPrototypeArray = terrain.get_terrainData().get_splatPrototypes();
                            }
                            Vector3 localPosition = this.GetLocalPosition(terrain, locationWU);
                            float[,,] texturesAtLocation = this.GetTexturesAtLocation(terrain, localPosition);
                            for (int index3 = 0; index3 < texturesAtLocation.GetLength(2); ++index3)
                            {
                                if (index3 == this.m_textureList.Count)
                                {
                                    this.m_textureList.Add(new CTSMeshBlender.TextureData()
                                    {
                                        m_terrainIdx             = index3,
                                        m_terrainTextureStrength = texturesAtLocation[0, 0, index3]
                                    });
                                }
                                else
                                {
                                    this.m_textureList[index3].m_terrainTextureStrength += texturesAtLocation[0, 0, index3];
                                }
                            }
                        }
                    }
                }
            }
            List <CTSMeshBlender.TextureData> list = this.m_textureList.OrderByDescending <CTSMeshBlender.TextureData, float>((Func <CTSMeshBlender.TextureData, float>)(x => x.m_terrainTextureStrength)).ToList <CTSMeshBlender.TextureData>();

            while (list.Count > 3)
            {
                list.RemoveAt(list.Count - 1);
            }
            this.m_textureList = list.OrderBy <CTSMeshBlender.TextureData, int>((Func <CTSMeshBlender.TextureData, int>)(x => x.m_terrainIdx)).ToList <CTSMeshBlender.TextureData>();
            if (Object.op_Inequality((Object)ctsProfile, (Object)null))
            {
                this.m_geoMap            = ctsProfile.GeoAlbedo;
                this.m_geoMapClosePower  = ctsProfile.m_geoMapClosePower;
                this.m_geoMapOffsetClose = ctsProfile.m_geoMapCloseOffset;
                this.m_geoTilingClose    = ctsProfile.m_geoMapTilingClose;
                this.m_smoothness        = ctsProfile.m_globalTerrainSmoothness;
                this.m_specular          = ctsProfile.m_globalTerrainSpecular;
                switch (ctsProfile.m_globalAOType)
                {
                case CTSConstants.AOType.None:
                    this.m_useAO        = false;
                    this.m_useAOTexture = false;
                    break;

                case CTSConstants.AOType.NormalMapBased:
                    this.m_useAO        = true;
                    this.m_useAOTexture = false;
                    break;

                case CTSConstants.AOType.TextureBased:
                    this.m_useAO        = true;
                    this.m_useAOTexture = true;
                    break;
                }
            }
            else
            {
                this.m_geoMap            = (Texture2D)null;
                this.m_geoMapClosePower  = 0.0f;
                this.m_geoMapOffsetClose = 0.0f;
                this.m_geoTilingClose    = 0.0f;
                this.m_smoothness        = 1f;
                this.m_specular          = 1f;
                this.m_useAO             = true;
                this.m_useAOTexture      = false;
            }
            byte minHeight = 0;
            byte maxHeight = 0;

            for (int index = 0; index < this.m_textureList.Count; ++index)
            {
                CTSMeshBlender.TextureData texture = this.m_textureList[index];
                if (Object.op_Inequality((Object)ctsProfile, (Object)null) && texture.m_terrainIdx < ctsProfile.TerrainTextures.Count)
                {
                    CTSTerrainTextureDetails terrainTexture = ctsProfile.TerrainTextures[texture.m_terrainIdx];
                    texture.m_albedo           = terrainTexture.Albedo;
                    texture.m_normal           = terrainTexture.Normal;
                    texture.m_hao_in_GA        = ctsProfile.BakeHAOTexture(((Object)terrainTexture.Albedo).get_name(), terrainTexture.Height, terrainTexture.AmbientOcclusion, out minHeight, out maxHeight);
                    texture.m_aoPower          = terrainTexture.m_aoPower;
                    texture.m_color            = new Vector4((float)terrainTexture.m_tint.r * terrainTexture.m_tintBrightness, (float)terrainTexture.m_tint.g * terrainTexture.m_tintBrightness, (float)terrainTexture.m_tint.b * terrainTexture.m_tintBrightness, terrainTexture.m_smoothness);
                    texture.m_geoPower         = terrainTexture.m_geologicalPower;
                    texture.m_normalPower      = terrainTexture.m_normalStrength;
                    texture.m_tiling           = terrainTexture.m_albedoTilingClose;
                    texture.m_heightContrast   = terrainTexture.m_heightContrast;
                    texture.m_heightDepth      = terrainTexture.m_heightDepth;
                    texture.m_heightBlendClose = terrainTexture.m_heightBlendClose;
                }
                else if (texture.m_terrainIdx < splatPrototypeArray.Length)
                {
                    SplatPrototype splatPrototype = splatPrototypeArray[texture.m_terrainIdx];
                    texture.m_albedo           = splatPrototype.get_texture();
                    texture.m_normal           = splatPrototype.get_normalMap();
                    texture.m_hao_in_GA        = (Texture2D)null;
                    texture.m_aoPower          = 0.0f;
                    texture.m_color            = Vector4.get_one();
                    texture.m_geoPower         = 0.0f;
                    texture.m_normalPower      = 1f;
                    texture.m_tiling           = (float)splatPrototype.get_tileSize().x;
                    texture.m_heightContrast   = 1f;
                    texture.m_heightDepth      = 1f;
                    texture.m_heightBlendClose = 1f;
                }
            }
        }