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); }
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); } }
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); }
private void DoImportSplats() { GSplatPrototypeGroup splatGroup = DesData.Shading.Splats; if (splatGroup == null || splatGroup == GGriffinSettings.Instance.TerrainDataDefault.Shading.Splats) { CreateNewSplatPrototypesGroup = true; } if (CreateNewSplatPrototypesGroup) { splatGroup = ScriptableObject.CreateInstance <GSplatPrototypeGroup>(); #if UNITY_EDITOR string path = AssetDatabase.GetAssetPath(DesData); string directory = Path.GetDirectoryName(path); string filePath = Path.Combine(directory, string.Format("Splats_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks)); AssetDatabase.CreateAsset(splatGroup, filePath); #endif DesData.Shading.Splats = splatGroup; } List <LPTSplatInfo> layers = SrcData.SurfaceSettings.Splats; GSplatPrototype[] prototypes = new GSplatPrototype[layers.Count]; for (int i = 0; i < layers.Count; ++i) { GSplatPrototype p = (GSplatPrototype)layers[i]; prototypes[i] = p; } splatGroup.Prototypes = new List <GSplatPrototype>(prototypes); int controlResolution = SrcData.SurfaceSettings.ControlResolution; DesData.Shading.SplatControlResolution = controlResolution; Texture[] alphaMaps = SrcData.SurfaceSettings.GetSplatControlTextures(); int maxControlCount = Mathf.Min(alphaMaps.Length, DesData.Shading.SplatControlMapCount); RenderTexture rt = new RenderTexture(controlResolution, controlResolution, 0, RenderTextureFormat.ARGB32); for (int i = 0; i < maxControlCount; ++i) { Texture2D controlMap = DesData.Shading.Internal_GetSplatControl(i); GCommon.CopyToRT(alphaMaps[i], rt); GCommon.CopyFromRT(controlMap, rt); controlMap.filterMode = alphaMaps[i].filterMode; } rt.Release(); GUtilities.DestroyObject(rt); DesData.SetDirty(GTerrainData.DirtyFlags.Shading); GC.Collect(); }
public static Texture2D RenderNormal(GBillboardCreatorArgs args) { args.Mode = GBillboardRenderMode.Normal; RenderTexture rt = null; PrepareRenderTexture(ref rt, args); RenderPreviewNormal(rt, args); Texture2D atlas = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, true, true); GCommon.CopyFromRT(atlas, rt); rt.Release(); GUtilities.DestroyObject(rt); atlas.name = args.Target.name + "_Normal"; return(atlas); }
private void SaveAsset() { RecordAnalytics(); RenderPreviewTexture(); GGeneralParams generalParams = GTextureToolParams.Instance.General; GUtilities.EnsureDirectoryExists(generalParams.Directory); string ext = generalParams.Extension == GImageFileExtension.PNG ? "png" : generalParams.Extension == GImageFileExtension.JPG ? "jpg" : generalParams.Extension == GImageFileExtension.EXR ? "exr" : generalParams.Extension == GImageFileExtension.TGA ? "tga" : "file"; string fileName = string.Format("{0}_{1}.{2}", GCommon.GetTimeTick(), generalParams.Mode.ToString(), ext); string filePath = Path.Combine(generalParams.Directory, fileName); TextureFormat format = generalParams.UseHighPrecisionTexture ? TextureFormat.RGBAFloat : TextureFormat.RGBA32; Texture2D tex = new Texture2D(generalParams.Resolution, generalParams.Resolution, format, false); tex.wrapMode = TextureWrapMode.Clamp; GCommon.CopyFromRT(tex, PreviewRt); byte[] data = generalParams.Extension == GImageFileExtension.PNG ? tex.EncodeToPNG() : generalParams.Extension == GImageFileExtension.JPG ? tex.EncodeToPNG() : generalParams.Extension == GImageFileExtension.EXR ? tex.EncodeToPNG() : generalParams.Extension == GImageFileExtension.TGA ? tex.EncodeToPNG() : new byte[0]; File.WriteAllBytes(filePath, data); GUtilities.DestroyObject(tex); AssetDatabase.Refresh(); Object o = AssetDatabase.LoadAssetAtPath <Texture2D>(filePath); if (o != null) { EditorGUIUtility.PingObject(o); Selection.activeObject = o; } }
private void StampLayer(GStylizedTerrain t, RenderTexture brush, int layerIndex) { GObjectStampLayer layer = Layers[layerIndex]; if (layer.Ignore) { return; } if (layer.InstanceCount == 0) { return; } if (layer.Prototypes.Count == 0 || layer.PrototypeIndices.Count == 0) { return; } Texture2D tex = new Texture2D(brush.width, brush.height, TextureFormat.ARGB32, false, true); GCommon.CopyFromRT(tex, brush); Color[] maskData = tex.GetPixels(); SpawnObjectOnTerrain(t, maskData, layerIndex); }