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);
                        }
                    }
                }
            }
        }
예제 #3
0
        public static Material GetMaterial(string shaderType, CTSProfile profile)
        {
            Material material1;

            if (profile.m_useMaterialControlBlock && CTSMaterials.m_materialLookup.TryGetValue(shaderType + ":" + ((Object)profile).get_name(), out material1))
            {
                return(material1);
            }
            Shader shader = CTSShaders.GetShader(shaderType);

            if (Object.op_Equality((Object)shader, (Object)null))
            {
                Debug.LogErrorFormat("Could not create CTS material for shader : {0}. Make sure you add your CTS shader is pre-loaded!", new object[1]
                {
                    (object)shaderType
                });
                return((Material)null);
            }
            Stopwatch stopwatch = Stopwatch.StartNew();
            Material  material2 = new Material(shader);

            ((Object)material2).set_name(shaderType + ":" + ((Object)profile).get_name());
            if (profile.m_useMaterialControlBlock)
            {
                ((Object)material2).set_hideFlags((HideFlags)52);
                CTSMaterials.m_materialLookup.Add(((Object)material2).get_name(), material2);
            }
            if (stopwatch.ElapsedMilliseconds <= 5L)
            {
                ;
            }
            return(material2);
        }
 public void BroadcastProfileSelect(CTSProfile profile)
 {
     foreach (CompleteTerrainShader shader in this.m_shaderSet)
     {
         shader.Profile = profile;
     }
 }
        /// <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>
        /// 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);
        }
        /// <summary>
        /// Broadcast a message to select this profile on all the CTS terrains in the scene
        /// </summary>
        /// <param name="profile">Profile being selected</param>
        public void BroadcastProfileSelect(CTSProfile profile)
        {
            //Make sure shaders are registered
            RegisterAllShaders(true);

            //Broadcast the select
            for (int idx = 0; idx < m_shaderList.Count; idx++)
            {
                m_shaderList[idx].Profile = profile;
            }
            System.GC.Collect();
        }
        /// <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;
        }
 public bool ProfileIsActive(CTSProfile profile)
 {
     if (Object.op_Equality((Object)profile, (Object)null))
     {
         return(false);
     }
     foreach (CompleteTerrainShader shader in this.m_shaderSet)
     {
         if (Object.op_Inequality((Object)shader.Profile, (Object)null) && ((Object)shader.Profile).GetInstanceID() == ((Object)profile).GetInstanceID())
         {
             return(true);
         }
     }
     return(false);
 }
 public void BroadcastProfileUpdate(CTSProfile profile)
 {
     if (Object.op_Equality((Object)profile, (Object)null))
     {
         Debug.LogWarning((object)"Cannot update shader on null profile.");
     }
     else
     {
         foreach (CompleteTerrainShader shader in this.m_shaderSet)
         {
             if (Object.op_Inequality((Object)shader.Profile, (Object)null) && ((Object)shader.Profile).get_name() == ((Object)profile).get_name())
             {
                 shader.UpdateShader();
             }
         }
     }
 }
        /// <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;
                        }
                    }
                }
            }
        }
예제 #13
0
        private Color32[] GetTextureColors(
            Texture2D source,
            TextureFormat format,
            int dimensions)
        {
            Texture2D texture2D = CTSProfile.ResizeTexture(source, format, this.m_albedoAniso, dimensions, dimensions, false, false, false);

            Color32[] pixels32 = texture2D.GetPixels32();
            if (!Application.get_isPlaying())
            {
                Object.DestroyImmediate((Object)texture2D);
            }
            else
            {
                Object.Destroy((Object)texture2D);
            }
            return(pixels32);
        }
예제 #14
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);
        }
예제 #15
0
        private Texture2D BakeNormal(Texture2D normalTexture)
        {
            int num = this.m_normalTextureSizePx * this.m_normalTextureSizePx;

            if (num == 0 || Object.op_Equality((Object)normalTexture, (Object)null))
            {
                return((Texture2D)null);
            }
            Texture2D texture2D1 = new Texture2D(this.m_normalTextureSizePx, this.m_normalTextureSizePx, this.m_normalFormat, true, true);

            ((Object)texture2D1).set_name("CTS_" + ((Object)this).get_name() + "_Normal");
            ((Texture)texture2D1).set_anisoLevel(this.m_normalAniso);
            ((Texture)texture2D1).set_filterMode(this.m_normalFilterMode);
            Color32[] pixels32_1 = texture2D1.GetPixels32();
            Texture2D texture2D2 = CTSProfile.ResizeTexture(normalTexture, this.m_normalFormat, this.m_normalAniso, this.m_normalTextureSizePx, this.m_normalTextureSizePx, false, true, false);

            Color32[] pixels32_2 = texture2D2.GetPixels32();
            for (int index = 0; index < num; ++index)
            {
                pixels32_1[index].r = (__Null)128;
                pixels32_1[index].g = pixels32_2[index].g;
                pixels32_1[index].b = (__Null)128;
                pixels32_1[index].a = pixels32_2[index].a;
            }
            if (Application.get_isPlaying())
            {
                Object.Destroy((Object)texture2D2);
            }
            else
            {
                Object.DestroyImmediate((Object)texture2D2);
            }
            texture2D1.SetPixels32(pixels32_1);
            texture2D1.Apply(true);
            if (this.m_normalCompress)
            {
                texture2D1.Compress(true);
                texture2D1.Apply(true);
            }
            return(texture2D1);
        }
 public void BroadcastNormalTextureSwitch(
     CTSProfile profile,
     Texture2D texture,
     int textureIdx,
     float tiling)
 {
     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.ReplaceNormalInTerrain(texture, textureIdx, tiling);
             }
             else if (((Object)shader.Profile).get_name() == ((Object)profile).get_name())
             {
                 shader.ReplaceNormalInTerrain(texture, textureIdx, tiling);
             }
         }
     }
 }
예제 #17
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);
        }
예제 #18
0
        private void ConstructAlbedosTextureArray()
        {
            this.m_needsAlbedosArrayUpdate = false;
            List <Texture2D> sourceTextures = new List <Texture2D>();
            int  num1 = 0;
            byte minHeight;
            byte maxHeight;

            for (int index = 0; index < this.m_terrainTextures.Count; ++index)
            {
                CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index];
                if (Object.op_Inequality((Object)terrainTexture.Albedo, (Object)null))
                {
                    Texture2D texture2D = !Object.op_Equality((Object)terrainTexture.Smoothness, (Object)null) || !Object.op_Equality((Object)terrainTexture.Roughness, (Object)null) ? this.BakeAlbedo(terrainTexture.Albedo, terrainTexture.Smoothness, terrainTexture.Roughness) : (!this.m_albedoCompress ? CTSProfile.ResizeTexture(terrainTexture.Albedo, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, false) : CTSProfile.ResizeTexture(terrainTexture.Albedo, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, true));
                    sourceTextures.Add(texture2D);
                    Color linear = ((Color) ref texture2D.GetPixels(texture2D.get_mipmapCount() - 1)[0]).get_linear();
                    terrainTexture.m_albedoAverage = new Vector4((float)linear.r, (float)linear.g, (float)linear.b, (float)linear.a);
                    terrainTexture.m_albedoIdx     = num1++;
                    if ((this.m_shaderType == CTSConstants.ShaderType.Advanced || this.m_shaderType == CTSConstants.ShaderType.Tesselation) && (Object.op_Inequality((Object)terrainTexture.Height, (Object)null) || Object.op_Inequality((Object)terrainTexture.AmbientOcclusion, (Object)null)))
                    {
                        sourceTextures.Add(this.BakeHAOTexture(terrainTexture.m_name, terrainTexture.Height, terrainTexture.AmbientOcclusion, out minHeight, out maxHeight));
                        if (Object.op_Inequality((Object)terrainTexture.Height, (Object)null))
                        {
                            terrainTexture.m_heightIdx = num1;
                            terrainTexture.m_heightMin = (float)minHeight / (float)byte.MaxValue;
                            terrainTexture.m_heightMax = (float)maxHeight / (float)byte.MaxValue;
                        }
                        else
                        {
                            terrainTexture.m_heightIdx = -1;
                        }
                        terrainTexture.m_aoIdx = !Object.op_Inequality((Object)terrainTexture.AmbientOcclusion, (Object)null) ? -1 : num1;
                        ++num1;
                    }
                    else
                    {
                        terrainTexture.m_aoIdx     = -1;
                        terrainTexture.m_heightIdx = -1;
                    }
                }
                else
                {
                    terrainTexture.m_albedoIdx = -1;
                }
                terrainTexture.m_albedoWasChanged = false;
            }
            if (Object.op_Inequality((Object)this.m_snowAlbedoTexture, (Object)null))
            {
                Texture2D texture2D = !this.m_albedoCompress ? CTSProfile.ResizeTexture(this.m_snowAlbedoTexture, this.m_albedoFormat, this.m_normalAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, false) : CTSProfile.ResizeTexture(this.m_snowAlbedoTexture, this.m_albedoFormat, this.m_normalAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, true);
                Color     linear    = ((Color) ref texture2D.GetPixels(texture2D.get_mipmapCount() - 1)[0]).get_linear();
                this.m_snowAverage = new Vector4((float)linear.r, (float)linear.g, (float)linear.b, (float)linear.a);
                sourceTextures.Add(texture2D);
                this.m_snowAlbedoTextureIdx = num1++;
            }
            else
            {
                this.m_snowAlbedoTextureIdx = -1;
            }
            if (Object.op_Inequality((Object)this.m_snowHeightTexture, (Object)null) || Object.op_Inequality((Object)this.m_snowAOTexture, (Object)null))
            {
                sourceTextures.Add(this.BakeHAOTexture("CTS_SnowHAO", this.m_snowHeightTexture, this.m_snowAOTexture, out minHeight, out maxHeight));
                if (Object.op_Inequality((Object)this.m_snowHeightTexture, (Object)null))
                {
                    this.m_snowHeightTextureIdx  = num1;
                    this.m_snowHeightmapMinValue = (float)minHeight / (float)byte.MaxValue;
                    this.m_snowHeightmapMaxValue = (float)maxHeight / (float)byte.MaxValue;
                }
                else
                {
                    this.m_snowHeightTextureIdx  = -1;
                    this.m_snowHeightmapMinValue = 0.0f;
                    this.m_snowHeightmapMaxValue = 1f;
                }
                this.m_snowAOTextureIdx = !Object.op_Inequality((Object)this.m_snowAOTexture, (Object)null) ? -1 : num1;
                int num2 = num1 + 1;
            }
            else
            {
                this.m_snowAOTextureIdx     = -1;
                this.m_snowHeightTextureIdx = -1;
            }
            this.AlbedosTextureArray = this.GetTextureArray(sourceTextures, CTSConstants.TextureType.Albedo, this.m_albedoAniso);
        }
예제 #19
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
        }
예제 #20
0
        private Texture2D BakeAlbedo(
            Texture2D albedoTexture,
            Texture2D smoothnessTexture,
            Texture2D roughnessTexture)
        {
            int num = this.m_normalTextureSizePx * this.m_normalTextureSizePx;

            if (num == 0)
            {
                return((Texture2D)null);
            }
            Texture2D texture2D1 = new Texture2D(this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, this.m_albedoFormat, true, false);

            ((Object)texture2D1).set_name("CTS_" + ((Object)this).get_name() + "_ASm");
            ((Texture)texture2D1).set_anisoLevel(this.m_albedoAniso);
            ((Texture)texture2D1).set_filterMode(this.m_albedoFilterMode);
            Color32[] pixels32_1 = texture2D1.GetPixels32();
            if (Object.op_Inequality((Object)albedoTexture, (Object)null))
            {
                Texture2D texture2D2 = CTSProfile.ResizeTexture(albedoTexture, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, false, false, false);
                Color32[] pixels32_2 = texture2D2.GetPixels32();
                for (int index = 0; index < num; ++index)
                {
                    pixels32_1[index].r = pixels32_2[index].r;
                    pixels32_1[index].g = pixels32_2[index].g;
                    pixels32_1[index].b = pixels32_2[index].b;
                }
                if (Application.get_isPlaying())
                {
                    Object.Destroy((Object)texture2D2);
                }
                else
                {
                    Object.DestroyImmediate((Object)texture2D2);
                }
            }
            if (Object.op_Inequality((Object)roughnessTexture, (Object)null) && Object.op_Equality((Object)smoothnessTexture, (Object)null))
            {
                Texture2D texture2D2 = CTSProfile.ResizeTexture(roughnessTexture, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, false, false, false);
                Color32[] pixels32_2 = texture2D2.GetPixels32();
                for (int index = 0; index < num; ++index)
                {
                    pixels32_1[index].a = (__Null)(int)(byte)((int)byte.MaxValue - pixels32_2[index].g);
                }
                if (Application.get_isPlaying())
                {
                    Object.Destroy((Object)texture2D2);
                }
                else
                {
                    Object.DestroyImmediate((Object)texture2D2);
                }
            }
            if (Object.op_Inequality((Object)smoothnessTexture, (Object)null))
            {
                Texture2D texture2D2 = CTSProfile.ResizeTexture(smoothnessTexture, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, false, false, false);
                Color32[] pixels32_2 = texture2D2.GetPixels32();
                for (int index = 0; index < num; ++index)
                {
                    pixels32_1[index].a = pixels32_2[index].g;
                }
                if (Application.get_isPlaying())
                {
                    Object.Destroy((Object)texture2D2);
                }
                else
                {
                    Object.DestroyImmediate((Object)texture2D2);
                }
            }
            texture2D1.SetPixels32(pixels32_1);
            texture2D1.Apply(true);
            if (this.m_albedoCompress)
            {
                texture2D1.Compress(true);
                texture2D1.Apply(true);
            }
            return(texture2D1);
        }
예제 #21
0
        public Texture2D BakeHAOTexture(
            string name,
            Texture2D hTexture,
            Texture2D aoTexture,
            out byte minHeight,
            out byte maxHeight)
        {
            minHeight = (byte)0;
            maxHeight = byte.MaxValue;
            int num = this.m_albedoTextureSizePx * this.m_albedoTextureSizePx;

            if (num == 0)
            {
                return((Texture2D)null);
            }
            Texture2D texture2D1 = new Texture2D(this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, this.m_albedoFormat, true, false);

            ((Object)texture2D1).set_name("CTS_" + name + "_HAO");
            ((Texture)texture2D1).set_anisoLevel(this.m_albedoAniso);
            ((Texture)texture2D1).set_filterMode(this.m_albedoFilterMode);
            Color32[] pixels32_1 = texture2D1.GetPixels32();
            if (Object.op_Inequality((Object)hTexture, (Object)null))
            {
                minHeight = byte.MaxValue;
                maxHeight = (byte)0;
                Texture2D texture2D2 = CTSProfile.ResizeTexture(hTexture, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, false, false, false);
                Color32[] pixels32_2 = texture2D2.GetPixels32();
                for (int index = 0; index < num; ++index)
                {
                    byte g = (byte)pixels32_2[index].g;
                    if ((int)g < (int)minHeight)
                    {
                        minHeight = g;
                    }
                    if ((int)g > (int)maxHeight)
                    {
                        maxHeight = g;
                    }
                    pixels32_1[index].r = (__Null)(int)(pixels32_1[index].g = pixels32_1[index].b = (__Null)g);
                }
                if (Application.get_isPlaying())
                {
                    Object.Destroy((Object)texture2D2);
                }
                else
                {
                    Object.DestroyImmediate((Object)texture2D2);
                }
            }
            if (Object.op_Inequality((Object)aoTexture, (Object)null))
            {
                Texture2D texture2D2 = CTSProfile.ResizeTexture(aoTexture, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, false, false, false);
                Color32[] pixels32_2 = texture2D2.GetPixels32();
                for (int index = 0; index < num; ++index)
                {
                    pixels32_1[index].a = pixels32_2[index].g;
                }
                if (Application.get_isPlaying())
                {
                    Object.Destroy((Object)texture2D2);
                }
                else
                {
                    Object.DestroyImmediate((Object)texture2D2);
                }
            }
            else
            {
                for (int index = 0; index < num; ++index)
                {
                    pixels32_1[index].a = (__Null)(int)byte.MaxValue;
                }
            }
            texture2D1.SetPixels32(pixels32_1);
            texture2D1.Apply(true);
            if (this.m_albedoCompress)
            {
                texture2D1.Compress(true);
                texture2D1.Apply(true);
            }
            return(texture2D1);
        }
예제 #22
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;
                }
            }
        }