private void DoBulkExport()
        {
            GCommon.ForEachTerrain(
                BulkExportGroupId,
                (t) =>
            {
                if (t == null || t.TerrainData == null)
                {
                    return;
                }

                GUnityTerrainDataExporter exporter = new GUnityTerrainDataExporter();
                exporter.SrcData              = t.TerrainData;
                exporter.DesData              = null;
                exporter.CreateNewAsset       = true;
                exporter.ExportGeometry       = ExportGeometry;
                exporter.ExportTerrainSize    = ExportTerrainSize;
                exporter.ExportSplats         = ExportSplats;
                exporter.OverwriteSplatLayers = false;
                exporter.ExportTrees          = ExportTrees;
                exporter.ExportGrasses        = ExportGrasses;
                exporter.DataDirectory        = DataDirectory;

                exporter.Export();
            });
        }
        private static void CenterToLevel(PWater water)
        {
            PWaterQuickSetupConfig config = PWaterQuickSetupConfig.Instance;
            Bounds levelBounds            = GCommon.GetLevelBounds();

            water.transform.position = new Vector3(levelBounds.center.x, config.WaterLevel, levelBounds.center.z);
        }
        private void InitModifierClasses()
        {
            List <Type> loadedTypes = GCommon.GetAllLoadedTypes();

            ModifierTypes = loadedTypes.FindAll(
                t => t.IsSubclassOf(typeof(GSplineModifier)));
        }
示例#4
0
 public void Import()
 {
     try
     {
         if (ImportGeometry)
         {
             GCommon.Editor_CancelableProgressBar("Working...", "Importing Geometry...", 1f);
             DoImportGeometry();
         }
         if (ImportColors)
         {
             GCommon.Editor_CancelableProgressBar("Working...", "Importing Colors...", 1f);
             DoImportColors();
         }
         if (ImportSplats)
         {
             GCommon.Editor_CancelableProgressBar("Working...", "Importing Splats...", 1f);
             DoImportSplats();
         }
     }
     catch (GProgressCancelledException)
     {
         Debug.Log("Importing process canceled!");
     }
     catch (System.Exception e)
     {
         Debug.LogError(e.ToString());
     }
     finally
     {
         GCommon.Editor_ClearProgressBar();
     }
 }
示例#5
0
        public void Internal_Apply(GStylizedTerrain t, RenderTexture rt, List <Vector4> vertices)
        {
            GCommon.CopyToRT(t.TerrainData.Geometry.HeightMap, rt);
            Material mat = GInternalMaterials.RampMakerMaterial;

            mat.SetTexture("_HeightMap", t.TerrainData.Geometry.HeightMap);
            mat.SetTexture("_Falloff", falloffTexture);
            mat.SetInt("_LowerHeight", LowerHeight ? 1 : 0);
            mat.SetInt("_RaiseHeight", RaiseHeight ? 1 : 0);
            mat.SetFloat("_AdditionalMeshResolution", GCommon.SUB_DIV_STEP * AdditionalMeshResolution);
            mat.SetTexture("_FalloffNoise", FalloffNoise);
            mat.SetTextureScale("_FalloffNoise", new Vector2(
                                    FalloffNoiseSize.x != 0 ? 1f / FalloffNoiseSize.x : 0,
                                    FalloffNoiseSize.y != 0 ? 1f / FalloffNoiseSize.y : 0));
            mat.SetTextureOffset("_FalloffNoise", Vector2.zero);
            if (SplineCreator.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", t.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            mat.SetInt("_StepCount", StepCount);
            int pass = 0;

            DrawOnTexture(rt, mat, pass, vertices, t);
        }
        public void Generate(RenderTexture targetRt)
        {
            GHeightMapFromMeshGeneratorParams param = GTextureToolParams.Instance.HeightMapFromMesh;

            if (param.SrcMesh == null)
            {
                GCommon.FillTexture(targetRt, Color.black);
            }
            else
            {
                try
                {
                    SetUp(param, targetRt);
                    Render(param, targetRt);
                }
                catch (System.Exception e)
                {
                    Debug.Log(e);
                }
                finally
                {
                    CleanUp();
                }
            }
        }
示例#7
0
        public void Generate(RenderTexture targetRt)
        {
            GNormalMapGeneratorParams param = GTextureToolParams.Instance.NormalMap;
            Color defaultColor = param.Space == GNormalMapSpace.Local ? new Color(0.5f, 1, 0.5f, 1) : new Color(0.5f, 0.5f, 1, 1);

            if (param.Terrain == null || param.Terrain.TerrainData == null)
            {
                GCommon.FillTexture(targetRt, defaultColor);
            }
            else
            {
                if (param.Mode == GNormalMapMode.Sharp)
                {
                    RenderSharpNormalMap(param, targetRt);
                }
                else if (param.Mode == GNormalMapMode.Interpolated)
                {
                    RenderInterpolatedNormalMap(param, targetRt);
                }
                else if (param.Mode == GNormalMapMode.PerPixel)
                {
                    RenderPerPixelNormalMap(param, targetRt);
                }
                else
                {
                    GCommon.FillTexture(targetRt, defaultColor);
                }
            }
        }
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            if (PrototypeIndices.Count == 0)
            {
                return;
            }
            if (Prototypes.Count == 0)
            {
                return;
            }
            RenderTexture  rt       = new RenderTexture(MaskResolution, MaskResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            List <Vector4> vertices = SplineCreator.GenerateVerticesWithFalloff();

            Internal_Apply(t, rt, vertices);
            Texture2D mask = GCommon.CreateTexture(MaskResolution, Color.clear);

            GCommon.CopyFromRT(mask, rt);
            mask.wrapMode = TextureWrapMode.Clamp;

            Color[] maskColors = mask.GetPixels();
            RemoveObjectFromTerrain(t, maskColors);

            rt.Release();
            GUtilities.DestroyObject(rt);
            GUtilities.DestroyObject(mask);
        }
        public void Internal_ApplySplat(GStylizedTerrain t, List <Vector4> worldPoints, RenderTexture[] rtControls)
        {
            Material mat = GInternalMaterials.PathPainterMaterial;

            mat.SetTexture("_Falloff", falloffTexture);
            mat.SetTexture("_FalloffNoise", FalloffNoise);
            mat.SetTextureScale("_FalloffNoise", new Vector2(
                                    FalloffNoiseSize.x != 0 ? 1f / FalloffNoiseSize.x : 0,
                                    FalloffNoiseSize.y != 0 ? 1f / FalloffNoiseSize.y : 0));
            mat.SetTextureOffset("_FalloffNoise", Vector2.zero);
            int pass = 2;

            for (int i = 0; i < rtControls.Length; ++i)
            {
                Texture2D splatControl = t.TerrainData.Shading.GetSplatControl(i);
                GCommon.CopyToRT(splatControl, rtControls[i]);
                mat.SetTexture("_MainTex", splatControl);
                if (SplatIndex / 4 == i)
                {
                    mat.SetInt("_ChannelIndex", SplatIndex % 4);
                }
                else
                {
                    mat.SetInt("_ChannelIndex", -1);
                }
                DrawOnTexture(rtControls[i], mat, pass, worldPoints, t);
            }

            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
        }
        public void Editor_DrawLivePreview(GStylizedTerrain terrain, GTexturePainterArgs args, Camera cam)
        {
#if UNITY_EDITOR
            Vector2[] uvCorners = new Vector2[args.WorldPointCorners.Length];
            for (int i = 0; i < uvCorners.Length; ++i)
            {
                uvCorners[i] = terrain.WorldPointToUV(args.WorldPointCorners[i]);
            }

            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners);
            if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1)))
            {
                return;
            }

            Texture2D     bg = terrain.TerrainData.Shading.AlbedoMap;
            int           albedoResolution = terrain.TerrainData.Shading.AlbedoMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, albedoResolution);
            GCommon.CopyToRT(bg, rt);

            Material mat = GInternalMaterials.AlbedoPainterMaterial;
            mat.SetColor("_Color", args.Color);
            mat.SetTexture("_MainTex", bg);
            SetupTextureGrid(terrain, mat);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 :
                args.ActionType == GPainterActionType.Alternative ? 2 : 0;
            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            GLivePreviewDrawer.DrawAlbedoLivePreview(terrain, cam, rt, dirtyRect);
#endif
        }
        public void FillArgs(ref GTexturePainterArgs args, bool useBrushDynamic = true)
        {
            args.Radius              = BrushRadius;
            args.Rotation            = BrushRotation;
            args.Opacity             = BrushOpacity;
            args.Color               = BrushColor;
            args.SplatIndex          = SelectedSplatIndex;
            args.SamplePoint         = SamplePoint;
            args.CustomArgs          = CustomPainterArgs;
            args.ForceUpdateGeometry = ForceUpdateGeometry;
            if (SelectedBrushMaskIndex >= 0 && SelectedBrushMaskIndex < BrushMasks.Count)
            {
                args.Mask = BrushMasks[SelectedBrushMaskIndex];
            }

            if (args.ActionType == GPainterActionType.Alternative &&
                args.MouseEventType == GPainterMouseEventType.Down)
            {
                SamplePoint      = args.HitPoint;
                args.SamplePoint = args.HitPoint;
            }

            if (useBrushDynamic)
            {
                ProcessBrushDynamic(ref args);
            }

            Vector3[] corners = GCommon.GetBrushQuadCorners(args.HitPoint, args.Radius, args.Rotation);
            args.WorldPointCorners = corners;
        }
示例#12
0
        private void InitFilterClasses()
        {
            List <Type> loadedTypes = GCommon.GetAllLoadedTypes();

            FilterTypes = loadedTypes.FindAll(
                t => t.IsSubclassOf(typeof(GSpawnFilter)));
        }
示例#13
0
        public void Generate(RenderTexture targetRt)
        {
            GFoliageDistributionMapGeneratorParams param = GTextureToolParams.Instance.TreeDistribution;

            GCommon.FillTexture(targetRt, Color.clear);

            List <Vector2> pos = new List <Vector2>();

            if (param.Terrain != null &&
                param.Terrain.TerrainData != null &&
                param.Terrain.TerrainData.Foliage.Trees != null &&
                param.Terrain.TerrainData.Foliage.Trees.Prototypes.Count != 0)
            {
                GetTreePosition(param, pos);
                Draw(targetRt, param, pos);
            }
            if (param.Terrain != null &&
                param.Terrain.TerrainData != null &&
                param.Terrain.TerrainData.Foliage.Grasses != null &&
                param.Terrain.TerrainData.Foliage.Grasses.Prototypes.Count != 0)
            {
                GGrassPatch[] patches = param.Terrain.TerrainData.Foliage.GrassPatches;
                for (int i = 0; i < patches.Length; ++i)
                {
                    GetGrassPosition(param, patches[i], pos);
                    Draw(targetRt, param, pos);
                }
            }
        }
示例#14
0
        public void Editor_DrawLivePreview(GStylizedTerrain terrain, GTexturePainterArgs args, Camera cam)
        {
#if UNITY_EDITOR
            Vector2[] uvCorners = new Vector2[args.WorldPointCorners.Length];
            for (int i = 0; i < uvCorners.Length; ++i)
            {
                uvCorners[i] = terrain.WorldPointToUV(args.WorldPointCorners[i]);
            }

            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners);
            if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1)))
            {
                return;
            }

            Texture2D     bg = terrain.TerrainData.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, heightMapResolution);
            GCommon.CopyToRT(bg, rt);

            Texture2D remapTex = GCommon.CreateTextureFromCurve(GTexturePainterCustomParams.Instance.Remap.Curve, 512, 1);
            Material  mat      = GInternalMaterials.RemapPainterMaterial;
            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            mat.SetTexture("_RemapTex", remapTex);
            int pass = 0;
            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            GLivePreviewDrawer.DrawGeometryLivePreview(terrain, cam, rt, dirtyRect);

            GUtilities.DestroyObject(remapTex);
#endif
        }
        public static void InitFilters()
        {
            List <Type> loadedTypes = GCommon.GetAllLoadedTypes();

            GSpawnFilter.AllFilters = loadedTypes.FindAll(
                t => t.IsSubclassOf(typeof(GSpawnFilter)));
        }
        private void DoExportRaw8()
        {
            int rawResolution = SrcData.Geometry.HeightMapResolution + 1;

            byte[] data = new byte[rawResolution * rawResolution];

            Vector2 uv  = Vector2.zero;
            Color   c   = Color.white;
            Vector2 enc = Vector2.zero;
            byte    h   = 0;

            for (int z = 0; z < rawResolution; ++z)
            {
                for (int x = 0; x < rawResolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, rawResolution - 1, x),
                        1 - Mathf.InverseLerp(0, rawResolution - 1, z));
                    c = SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    enc.Set(c.r, c.g);
                    h = (byte)(GCommon.DecodeFloatRG(enc) * byte.MaxValue);
                    data[GUtilities.To1DIndex(x, z, rawResolution)] = h;
                }
            }

            GUtilities.EnsureDirectoryExists(DataDirectory);
            string fileName = string.Format("RAW8_{0}x{0}_{1}.raw", rawResolution, SrcData.Id);
            string path     = Path.Combine(DataDirectory, fileName);

            File.WriteAllBytes(path, data);
#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
示例#17
0
        private void SetupSplatPreview(GStylizedTerrain t)
        {
            Material mat = t.TerrainData.Shading.MaterialToRender;

            if (mat == null)
            {
                return;
            }
            int controlMapResolution = t.TerrainData.Shading.SplatControlResolution;
            int controlMapCount      = t.TerrainData.Shading.SplatControlMapCount;

            if (controlMapCount == 0)
            {
                return;
            }
            RenderTexture[] rtControls = new RenderTexture[controlMapCount];
            for (int i = 0; i < controlMapCount; ++i)
            {
                Texture2D splatControl = t.TerrainData.Shading.GetSplatControl(i);
                rtControls[i] = GetPreviewTexture(t, "splatControl" + i, controlMapResolution, splatControl.filterMode);
                GCommon.ClearRT(rtControls[i]);
            }
            instance.Internal_ApplySplat(t, rtControls);
            previewPropertyBlock.Clear();
            //for (int i = 0; i < controlMapCount; ++i)
            //{
            //    if (!string.IsNullOrEmpty(t.TerrainData.Shading.SplatControlMapPropertyName))
            //    {
            //        previewPropertyBlock.SetTexture(t.TerrainData.Shading.SplatControlMapPropertyName + i, rtControls[i]);
            //    }
            //}
        }
示例#18
0
        private void SetupAlbedoMetallicSmoothnessPreview(GStylizedTerrain t)
        {
            Material mat = t.TerrainData.Shading.MaterialToRender;

            if (mat == null)
            {
                return;
            }
            int           albedoResolution = t.TerrainData.Shading.AlbedoMapResolution;
            RenderTexture previewAlbedo    = GetPreviewTexture(t, "albedo", albedoResolution, t.TerrainData.Shading.AlbedoMap.filterMode);

            GCommon.ClearRT(previewAlbedo);

            int           metallicResolution = t.TerrainData.Shading.MetallicMapResolution;
            RenderTexture previewMetallic    = GetPreviewTexture(t, "metallic", metallicResolution, t.TerrainData.Shading.MetallicMap.filterMode);

            GCommon.ClearRT(previewMetallic);
            instance.Internal_ApplyAlbedoMetallicSmoothness(t, previewAlbedo, previewMetallic);

            //previewPropertyBlock.Clear();
            //if (!string.IsNullOrEmpty(t.TerrainData.Shading.AlbedoMapPropertyName))
            //{
            //    previewPropertyBlock.SetTexture(t.TerrainData.Shading.AlbedoMapPropertyName, previewAlbedo);
            //}
            //if (!string.IsNullOrEmpty(t.TerrainData.Shading.MetallicMapPropertyName))
            //{
            //    previewPropertyBlock.SetTexture(t.TerrainData.Shading.MetallicMapPropertyName, previewMetallic);
            //}
        }
 private void DrawMask(Camera cam)
 {
     GCommon.ForEachTerrain(instance.GroupId, (t) =>
     {
         GLivePreviewDrawer.DrawTerrainMask(t, cam);
     });
 }
示例#20
0
        public static void Main(string[] args)
        {
            var tmpRet = UtilsHelper.GetMainParams(args);

            if (tmpRet != null && tmpRet.Count > 0)
            {
                foreach (var tmp in tmpRet)
                {
                    if (tmp.Key.ToUpper().Equals("-C"))
                    {
                        GCommon.OutConfigPath = tmp.Value;
                    }
                    if (tmp.Key.ToUpper().Equals("-L"))
                    {
                        GCommon.OutLogPath = tmp.Value;
                    }
                }
            }

            if (!string.IsNullOrEmpty(GCommon.OutLogPath))
            {
                if (!GCommon.OutLogPath.Trim().EndsWith('/'))
                {
                    GCommon.OutLogPath += "/";
                }
            }

            GCommon.InitLogger();
            Common.Init();
            CreateHostBuilder(args).Build().Run();
        }
示例#21
0
        private void StampLayer(GStylizedTerrain t, RenderTexture brush, int layerIndex)
        {
            GFoliageStampLayer layer = Layers[layerIndex];

            if (layer.Ignore)
            {
                return;
            }
            if (layer.TreeInstanceCount == 0)
            {
                return;
            }
            Texture2D tex = new Texture2D(brush.width, brush.height, TextureFormat.ARGB32, false, true);

            GCommon.CopyFromRT(tex, brush);
            Color[] maskData = tex.GetPixels();

            if (layer.StampTrees &&
                layer.TreeIndices.Count >= 0 &&
                t.TerrainData.Foliage.Trees != null)
            {
                SpawnTreeOnTerrain(t, maskData, layerIndex);
            }

            if (layer.StampGrasses &&
                layer.GrassIndices.Count >= 0 &&
                t.TerrainData.Foliage.Grasses != null)
            {
                SpawnGrassOnTerrain(t, maskData, layerIndex);
            }
        }
示例#22
0
        public void Editor_DrawLivePreview(GStylizedTerrain terrain, GTexturePainterArgs args, Camera cam)
        {
#if UNITY_EDITOR
            Vector2[] uvCorners = new Vector2[args.WorldPointCorners.Length];
            for (int i = 0; i < uvCorners.Length; ++i)
            {
                uvCorners[i] = terrain.WorldPointToUV(args.WorldPointCorners[i]);
            }

            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners);
            if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1)))
            {
                return;
            }

            Texture2D     bg = terrain.TerrainData.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, heightMapResolution);
            GCommon.CopyToRT(bg, rt);

            Vector3  localSamplePoint = terrain.transform.InverseTransformPoint(args.SamplePoint);
            Material mat = GInternalMaterials.HeightSamplingPainterMaterial;
            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            mat.SetFloat("_TargetGray", Mathf.InverseLerp(0, terrain.TerrainData.Geometry.Height, localSamplePoint.y));
            int pass = 0;
            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            GLivePreviewDrawer.DrawGeometryLivePreview(terrain, cam, rt, dirtyRect);
#endif
        }
示例#23
0
        private void RenderGeometryHeightMap(GStylizedTerrain terrain, RenderTexture targetRt)
        {
            GGeneralParams param = GTextureToolParams.Instance.General;
            RenderTexture  rt    = terrain.GetHeightMap(param.Resolution);

            GCommon.CopyToRT(rt, targetRt);
        }
        private void DoExportGeometry()
        {
            DesData.heightmapResolution = SrcData.Geometry.HeightMapResolution + 1;
            int resolution = DesData.heightmapResolution;

            float[,] heightSample = new float[resolution, resolution];
            Vector2 uv  = Vector2.zero;
            Vector2 enc = Vector2.zero;
            float   h   = 0;

            for (int z = 0; z < resolution; ++z)
            {
                for (int x = 0; x < resolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, resolution - 1, x),
                        Mathf.InverseLerp(0, resolution - 1, z));
                    enc = (Vector4)SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    h   = GCommon.DecodeFloatRG(enc);
                    heightSample[z, x] = h;
                }
            }

            DesData.SetHeights(0, 0, heightSample);

            if (ExportTerrainSize)
            {
                DesData.size = new Vector3(SrcData.Geometry.Width, SrcData.Geometry.Height, SrcData.Geometry.Length);
            }
        }
示例#25
0
        public void Internal_ApplyMetallic(GStylizedTerrain t, List <Vector4> worldPoints, RenderTexture rtMetallic)
        {
            GCommon.CopyToRT(t.TerrainData.Shading.MetallicMap, rtMetallic);
            Material mat = GInternalMaterials.PathPainterMaterial;

            mat.SetTexture("_MainTex", t.TerrainData.Shading.MetallicMap);
            mat.SetFloat("_Metallic", Metallic);
            mat.SetFloat("_Smoothness", Smoothness);
            mat.SetTexture("_FalloffNoise", FalloffNoise);
            mat.SetTextureScale("_FalloffNoise", new Vector2(
                                    FalloffNoiseSize.x != 0 ? 1f / FalloffNoiseSize.x : 0,
                                    FalloffNoiseSize.y != 0 ? 1f / FalloffNoiseSize.y : 0));
            mat.SetTextureOffset("_FalloffNoise", Vector2.zero);
            int pass = 1;

            DrawOnTexture(rtMetallic, mat, pass, worldPoints, t);
            if (SplineCreator.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", t.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
        }
示例#26
0
        public void Generate(RenderTexture targetRt)
        {
            GBlendMapGeneratorParams param = GTextureToolParams.Instance.Blend;

            RenderTexture bg = new RenderTexture(targetRt);

            GCommon.CopyToRT(targetRt, bg);

            GCommon.FillTexture(targetRt, Color.black);
            for (int i = 0; i < param.Layers.Count; ++i)
            {
                GBlendLayer l = param.Layers[i];
                Mat.SetTexture("_Background", bg);
                Mat.SetTexture("_Foreground", l.Texture);
                Mat.SetFloat("_Number", l.Number);
                Mat.SetVector("_Vector", l.Vector);
                Mat.SetInt("_Ops", (int)l.BlendOps);
                Mat.SetFloat("_LerpFactor", l.LerpFactor);
                Mat.SetTexture("_LerpMask", l.LerpMask);
                Mat.SetInt("_Saturate", l.Saturate ? 1 : 0);

                GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, (int)l.DataSource);
                GCommon.CopyToRT(targetRt, bg);
            }

            bg.Release();
            GUtilities.DestroyObject(bg);
        }
示例#27
0
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            RenderTexture  rt       = new RenderTexture(MaskResolution, MaskResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            List <Vector4> vertices = SplineCreator.GenerateVerticesWithFalloff();

            Internal_Apply(t, rt, vertices);
            Texture2D mask = GCommon.CreateTexture(MaskResolution, Color.clear);

            GCommon.CopyFromRT(mask, rt);
            mask.wrapMode = TextureWrapMode.Clamp;

            Color[] maskColors = mask.GetPixels();
            if (RemoveTrees)
            {
                RemoveTreeOnTerrain(t, maskColors);
            }
            if (RemoveGrasses)
            {
                RemoveGrassOnTerrain(t, maskColors);
                t.UpdateGrassPatches();
            }

            t.TerrainData.Foliage.ClearGrassDirtyRegions();
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Foliage);

            rt.Release();
            GUtilities.DestroyObject(rt);
            GUtilities.DestroyObject(mask);
        }
        public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Up)
            {
                return;
            }

            Vector2[] uvCorners = new Vector2[args.WorldPointCorners.Length];
            for (int i = 0; i < uvCorners.Length; ++i)
            {
                uvCorners[i] = terrain.WorldPointToUV(args.WorldPointCorners[i]);
            }

            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners);

            if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1)))
            {
                return;
            }

            Texture2D     bg = terrain.TerrainData.Shading.AlbedoMap;
            int           albedoResolution = terrain.TerrainData.Shading.AlbedoMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(albedoResolution);

            GCommon.CopyToRT(bg, rt);

            Material mat = GInternalMaterials.AlbedoPainterMaterial;

            mat.SetColor("_Color", args.Color);
            mat.SetTexture("_MainTex", bg);
            SetupTextureGrid(terrain, mat);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 :
                args.ActionType == GPainterActionType.Alternative ? 2 : 0;

            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            RenderTexture.active = rt;
            terrain.TerrainData.Shading.AlbedoMap.ReadPixels(
                new Rect(0, 0, albedoResolution, albedoResolution), 0, 0);
            terrain.TerrainData.Shading.AlbedoMap.Apply();
            RenderTexture.active = null;

            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);

            if (!args.ForceUpdateGeometry)
            {
                return;
            }
            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
示例#29
0
        private void DoImportGrasses()
        {
            if (!ImportGrassInstancesOnly)
            {
                GGrassPrototypeGroup grassesGroup = DesData.Foliage.Grasses;
                if (grassesGroup == null ||
                    grassesGroup == GRuntimeSettings.Instance.foliageDefault.grasses)
                {
                    CreateNewGrassPrototypesGroup = true;
                }

                if (CreateNewGrassPrototypesGroup)
                {
                    grassesGroup = ScriptableObject.CreateInstance <GGrassPrototypeGroup>();

#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        string path      = AssetDatabase.GetAssetPath(DesData);
                        string directory = Path.GetDirectoryName(path);
                        string filePath  = Path.Combine(directory, string.Format("Grasses_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks));
                        AssetDatabase.CreateAsset(grassesGroup, filePath);
                    }
#endif
                    DesData.Foliage.Grasses = grassesGroup;
                }

                grassesGroup.Prototypes.Clear();

                DetailPrototype[] detailPrototypes = SrcData.detailPrototypes;
                for (int i = 0; i < detailPrototypes.Length; ++i)
                {
                    GGrassPrototype proto = (GGrassPrototype)detailPrototypes[i];
                    grassesGroup.Prototypes.Add(proto);
                }
                GCommon.SetDirty(grassesGroup);
            }

            List <GGrassInstance> grasses = new List <GGrassInstance>();
            int detailResolution          = SrcData.detailResolution;
            int detailLayerCount          = SrcData.detailPrototypes.Length;
            for (int layer = 0; layer < detailLayerCount; ++layer)
            {
                int[,] density = SrcData.GetDetailLayer(0, 0, detailResolution, detailResolution, layer);
                DoImportDetailLayer(layer, density, grasses);
            }

            DesData.Foliage.ClearGrassInstances();
            DesData.Foliage.AddGrassInstances(grasses);
            if (DesTerrain != null)
            {
                DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                DesTerrain.UpdateGrassPatches(-1, true);
                DesData.Foliage.ClearGrassDirtyRegions();
            }

            DesData.SetDirty(GTerrainData.DirtyFlags.Foliage);
            //GC.Collect();
        }
示例#30
0
 public void Internal_UpdateFalloffTexture()
 {
     if (falloffTexture != null)
     {
         GUtilities.DestroyObject(falloffTexture);
     }
     falloffTexture = GCommon.CreateTextureFromCurve(Falloff, 256, 1);
 }