private static void BackupAlbedoMap(GStylizedTerrain t, string backupName) { Color32[] albedoColor = t.TerrainData.Shading.AlbedoMap.GetPixels32(); byte[] albedoR = new byte[albedoColor.Length]; byte[] albedoG = new byte[albedoColor.Length]; byte[] albedoB = new byte[albedoColor.Length]; byte[] albedoA = new byte[albedoColor.Length]; for (int i = 0; i < albedoColor.Length; ++i) { albedoR[i] = albedoColor[i].r; albedoG[i] = albedoColor[i].g; albedoB[i] = albedoColor[i].b; albedoA[i] = albedoColor[i].a; } albedoR = GCompressor.Compress(albedoR); albedoG = GCompressor.Compress(albedoG); albedoB = GCompressor.Compress(albedoB); albedoA = GCompressor.Compress(albedoA); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_R_SUFFIX), albedoR); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_G_SUFFIX), albedoG); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_B_SUFFIX), albedoB); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_A_SUFFIX), albedoA); }
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 RenderTexture GetPreviewTexture(GStylizedTerrain t, string mapName, int resolution, FilterMode filter) { if (previewTextures == null) { previewTextures = new Dictionary <string, RenderTexture>(); } string key = string.Format("{0}_{1}", t.GetInstanceID(), mapName); if (!previewTextures.ContainsKey(key) || previewTextures[key] == null) { RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); rt.wrapMode = TextureWrapMode.Clamp; previewTextures[key] = rt; } else if (previewTextures[key].width != resolution || previewTextures[key].height != resolution) { previewTextures[key].Release(); Object.DestroyImmediate(previewTextures[key]); RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); rt.wrapMode = TextureWrapMode.Clamp; previewTextures[key] = rt; } previewTextures[key].filterMode = filter; return(previewTextures[key]); }
private void DrawLivePreview(GStylizedTerrain t, Camera cam) { if (t.transform.rotation != Quaternion.identity || t.transform.lossyScale != Vector3.one) { return; } List <Rect> dirtyRects = new List <Rect>(instance.SplineCreator.SweepDirtyRect(t)); Rect r = new Rect(0, 0, 0, 0); for (int i = 0; i < dirtyRects.Count; ++i) { r.xMin = Mathf.Min(r.xMin, dirtyRects[i].xMin); r.xMax = Mathf.Max(r.xMax, dirtyRects[i].xMax); r.yMin = Mathf.Min(r.yMin, dirtyRects[i].yMin); r.yMax = Mathf.Max(r.yMax, dirtyRects[i].yMax); } RenderTexture rt = GetPreviewTexture(t); instance.Internal_Apply(t, rt, instance.SplineCreator.Editor_Vertices); GLivePreviewDrawer.DrawMasksLivePreview( t, cam, new Texture[] { rt }, new Color[] { GGriffinSettings.Instance.SplineToolSettings.PositiveHighlightColor }, r); }
private void UpdatePreview() { IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator(); while (terrains.MoveNext()) { GStylizedTerrain t = terrains.Current; if (t.TerrainData == null) { continue; } if (instance.GroupId >= 0 && instance.GroupId != t.GroupId) { continue; } if (instance.Channel == GTextureStampChannel.AlbedoMetallicSmoothness) { SetupAlbedoMetallicSmoothnessPreview(t); } else if (instance.Channel == GTextureStampChannel.Splat) { SetupSplatPreview(t); } } }
private void GetUvPoints(GStylizedTerrain t, Vector3[] worldPoint, Vector2[] uvPoint) { for (int i = 0; i < uvPoints.Length; ++i) { uvPoints[i] = t.WorldPointToUV(worldPoints[i]); } }
private void DrawLivePreview(GStylizedTerrain t, Camera cam) { if (t.transform.rotation != Quaternion.identity || t.transform.lossyScale != Vector3.one) { return; } //Mesh previewMesh = GGriffinSettings.Instance.GetLivePreviewMesh(t.TerrainData.Geometry.MeshResolution); RenderTexture rt = GetPreviewTexture(t); instance.GetQuad(worldPoints); for (int i = 0; i < normalizedPoints.Length; ++i) { normalizedPoints[i] = t.WorldPointToUV(worldPoints[i]); } Rect dirtyRect = GUtilities.GetRectContainsPoints(normalizedPoints); if (instance.Channel == GGeometryStamper.GStampChannel.Elevation) { GLivePreviewDrawer.DrawGeometryLivePreview(t, cam, rt, dirtyRect); } else if (instance.Channel == GGeometryStamper.GStampChannel.Visibility) { Matrix4x4 worldToMaskMatrix = Matrix4x4.TRS( worldPoints[0], instance.Rotation, instance.Scale).inverse; GLivePreviewDrawer.DrawVisibilityLivePreview(t, cam, rt, dirtyRect, instance.Stamp, worldToMaskMatrix); } }
public static void SetShader(GStylizedTerrain terrain, GLightingModel lighting, GTexturingModel texturing, GSplatsModel splats = GSplatsModel.Splats4) { if (terrain.TerrainData == null) { throw new NullReferenceException("The selected terrain doesn't have terrain data."); } if (terrain.TerrainData.Shading.CustomMaterial == null) { throw new NullReferenceException("The selected terrain doesn't have material. Make sure you've assigned a material for it."); } Material mat = GRuntimeSettings.Instance.terrainRendering.GetClonedMaterial( GCommon.CurrentRenderPipeline, lighting, texturing, splats); if (mat == null) { throw new Exception("Fail to get template material. Try re-install render pipeline extension package."); } terrain.TerrainData.Shading.CustomMaterial.shader = mat.shader; terrain.TerrainData.Shading.UpdateMaterials(); GUtilities.DestroyObject(mat); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); GStylizedTerrain terrain = instance.Terrain; if (terrain.TerrainData == null) { return; } string label = "Vertex Count"; string id = "vertexcount" + instance.GetInstanceID(); GEditorCommon.Foldout(label, false, id, () => { EditorGUILayout.LabelField("Vertex Count"); for (int i = 0; i < terrain.TerrainData.Geometry.LODCount; ++i) { Mesh m = terrain.TerrainData.GeometryData.GetMesh(GTerrainChunk.GetChunkMeshName(instance.Index, i)); if (m != null) { EditorGUILayout.LabelField(string.Format("LOD {0}", i.ToString()), m.vertexCount.ToString()); } else { EditorGUILayout.LabelField(string.Format("LOD {0}", i.ToString()), "null"); } } }); }
private void ApplyAlbedoAndMetallic(GStylizedTerrain t, List <Vector4> worldPoints) { int albedoResolution = t.TerrainData.Shading.AlbedoMapResolution; RenderTexture rtAlbedo = new RenderTexture(albedoResolution, albedoResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); Internal_ApplyAlbedo(t, worldPoints, rtAlbedo); RenderTexture.active = rtAlbedo; t.TerrainData.Shading.AlbedoMap.ReadPixels(new Rect(0, 0, albedoResolution, albedoResolution), 0, 0); t.TerrainData.Shading.AlbedoMap.Apply(); RenderTexture.active = null; rtAlbedo.Release(); Object.DestroyImmediate(rtAlbedo); int metallicResolution = t.TerrainData.Shading.MetallicMapResolution; RenderTexture rtMetallic = new RenderTexture(metallicResolution, metallicResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); Internal_ApplyMetallic(t, worldPoints, rtMetallic); RenderTexture.active = rtMetallic; t.TerrainData.Shading.MetallicMap.ReadPixels(new Rect(0, 0, metallicResolution, metallicResolution), 0, 0); t.TerrainData.Shading.MetallicMap.Apply(); RenderTexture.active = null; rtMetallic.Release(); Object.DestroyImmediate(rtMetallic); }
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); }
internal static RenderTexture Internal_GetRenderTexture(GStylizedTerrain t, int resolution, int id = 0) { if (internal_RenderTextures == null) { internal_RenderTextures = new Dictionary <string, RenderTexture>(); } string key = string.Format("{0}_{1}", t != null ? t.GetInstanceID() : 0, id); if (!internal_RenderTextures.ContainsKey(key) || internal_RenderTextures[key] == null) { RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear); internal_RenderTextures[key] = rt; } else if (internal_RenderTextures[key].width != resolution || internal_RenderTextures[key].height != resolution || internal_RenderTextures[key].format != GGeometry.HeightMapRTFormat) { internal_RenderTextures[key].Release(); Object.DestroyImmediate(internal_RenderTextures[key]); RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear); internal_RenderTextures[key] = rt; } internal_RenderTextures[key].wrapMode = TextureWrapMode.Clamp; return(internal_RenderTextures[key]); }
private static void RestoreAlbedoMap(GStylizedTerrain t, string backupName) { string albedoRFileName = string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_R_SUFFIX); string albedoGFileName = string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_G_SUFFIX); string albedoBFileName = string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_B_SUFFIX); string albedoAFileName = string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_A_SUFFIX); byte[] albedoRData = GBackupFile.ReadAllBytes(backupName, albedoRFileName); byte[] albedoGData = GBackupFile.ReadAllBytes(backupName, albedoGFileName); byte[] albedoBData = GBackupFile.ReadAllBytes(backupName, albedoBFileName); byte[] albedoAData = GBackupFile.ReadAllBytes(backupName, albedoAFileName); if (albedoRData != null && albedoGData != null && albedoBData != null && albedoAData != null) { albedoRData = GCompressor.Decompress(albedoRData); albedoGData = GCompressor.Decompress(albedoGData); albedoBData = GCompressor.Decompress(albedoBData); albedoAData = GCompressor.Decompress(albedoAData); Color32[] albedoColors = new Color32[albedoRData.Length]; for (int i = 0; i < albedoRData.Length; ++i) { albedoColors[i] = new Color32(albedoRData[i], albedoGData[i], albedoBData[i], albedoAData[i]); } int resolution = Mathf.RoundToInt(Mathf.Sqrt(albedoRData.LongLength)); t.TerrainData.Shading.AlbedoMapResolution = resolution; t.TerrainData.Shading.AlbedoMap.SetPixels32(albedoColors); t.TerrainData.Shading.AlbedoMap.Apply(); t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading); } }
public static void Restore(string backupName) { List <GStylizedTerrain> terrains = new List <GStylizedTerrain>(GStylizedTerrain.ActiveTerrains); for (int i = 0; i < terrains.Count; ++i) { GStylizedTerrain t = terrains[i]; if (t.TerrainData == null) { continue; } try { #if UNITY_EDITOR GCommonGUI.ProgressBar("Restoring", "Restoring " + t.name + " data...", 1f); #endif RestoreTerrain(t, backupName); } catch (System.Exception e) { Debug.LogError(string.Format("Error on restoring {0}: {1}", e.ToString(), t.name)); } finally { #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif } } GStylizedTerrain.MatchEdges(-1); GUndoCompatibleBuffer.Instance.CurrentBackupName = backupName; }
public void Apply() { if (falloffTexture != null) { Object.DestroyImmediate(falloffTexture); } Internal_UpdateFalloffTexture(); Internal_UpdateLayerTransitionTextures(); IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator(); try { while (terrains.MoveNext()) { GStylizedTerrain t = terrains.Current; if (groupId < 0 || (groupId >= 0 && groupId == t.GroupId)) { Apply(t); } } } catch (GProgressCancelledException) { Debug.Log("Stamp process canceled, result may be incorrect. Use History to clean up!"); #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif } }
public void CreateStaticObstacles() { transform.root.position = Vector3.zero; transform.root.rotation = Quaternion.identity; transform.root.localScale = Vector3.one; transform.position = Vector3.zero; transform.rotation = Quaternion.identity; transform.localScale = Vector3.one; try { IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator(); while (terrains.MoveNext()) { GStylizedTerrain t = terrains.Current; if (groupId < 0 || (groupId >= 0 && groupId == t.GroupId)) { CreateStaticObstacles(t); } } } catch (GProgressCancelledException) { Debug.Log("Create static obstacles process canceled!"); #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif } }
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); } }
public override void Apply() { if (SplineCreator == null) { return; } if (falloffTexture != null) { Object.DestroyImmediate(falloffTexture); } Internal_UpdateFalloffTexture(); int groupId = SplineCreator.GroupId; IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator(); while (terrains.MoveNext()) { GStylizedTerrain t = terrains.Current; if (groupId < 0 || (groupId >= 0 && groupId == t.GroupId)) { Apply(t); } } GStylizedTerrain.MatchEdges(groupId); }
private void ClearTrees(GStylizedTerrain t) { if (t.TerrainData == null) { return; } if (t.TerrainData.Foliage.Trees == null) { return; } Vector3 terrainSize = new Vector3( t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length); Vector3 scale = new Vector3( GUtilities.InverseLerpUnclamped(0, terrainSize.x, Scale.x), GUtilities.InverseLerpUnclamped(0, terrainSize.y, Scale.y), GUtilities.InverseLerpUnclamped(0, terrainSize.z, Scale.z)); Matrix4x4 matrix = Matrix4x4.TRS( t.WorldPointToNormalized(Position), Rotation, scale); Matrix4x4 normalizeToStamp = matrix.inverse; t.TerrainData.Foliage.TreeInstances.RemoveAll(tree => { Vector3 stampSpacePos = normalizeToStamp.MultiplyPoint(tree.Position); return (stampSpacePos.x >= -0.5f && stampSpacePos.x <= 0.5f && stampSpacePos.y >= 0f && stampSpacePos.y <= 1f && stampSpacePos.z >= -0.5f && stampSpacePos.z <= 0.5f); }); t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Foliage); }
public void Configure(GStylizedTerrain terrain, int prototypeIndex, MaterialPropertyBlock propertyBlock) { GGrassPrototype proto = terrain.TerrainData.Foliage.Grasses.Prototypes[prototypeIndex]; propertyBlock.SetTexture(NOISE_TEX, GRuntimeSettings.Instance.foliageRendering.windNoiseTexture); IEnumerator <GWindZone> windZone = GWindZone.ActiveWindZones.GetEnumerator(); if (windZone.MoveNext()) { GWindZone w = windZone.Current; propertyBlock.SetVector(WIND, w.GetWindParams()); } propertyBlock.SetColor(COLOR, proto.Color); if (proto.Shape != GGrassShape.DetailObject && proto.Texture != null) { propertyBlock.SetTexture(MAIN_TEX, proto.Texture); } propertyBlock.SetFloat(BEND_FACTOR, proto.BendFactor); if (terrain.TerrainData.Foliage.EnableInteractiveGrass) { propertyBlock.SetTexture(VECTOR_FIELD, terrain.GetGrassVectorFieldRenderTexture()); propertyBlock.SetMatrix(WORLD_TO_NORMALIZED, terrain.GetWorldToNormalizedMatrix()); } float fadeMaxDistance = terrain.TerrainData.Rendering.GrassDistance; float fadeMinDistance = Mathf.Clamp(terrain.TerrainData.Rendering.GrassFadeStart, 0f, 0.99f) * fadeMaxDistance; propertyBlock.SetFloat(FADE_MIN_DISTANCE, fadeMinDistance); propertyBlock.SetFloat(FADE_MAX_DISTANCE, fadeMaxDistance); }
private RenderTexture GetPreviewTexture(GStylizedTerrain t) { if (previewTextures == null) { previewTextures = new Dictionary <GStylizedTerrain, RenderTexture>(); } int resolution = t.TerrainData.Geometry.HeightMapResolution; if (!previewTextures.ContainsKey(t) || previewTextures[t] == null) { RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear); previewTextures[t] = rt; } else if (previewTextures[t].width != resolution || previewTextures[t].height != resolution || previewTextures[t].format != GGeometry.HeightMapRTFormat) { previewTextures[t].Release(); Object.DestroyImmediate(previewTextures[t]); RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear); previewTextures[t] = rt; } previewTextures[t].wrapMode = TextureWrapMode.Clamp; return(previewTextures[t]); }
private void ClearObjects(GStylizedTerrain t) { if (t.TerrainData == null) { return; } Vector3 terrainSize = new Vector3( t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length); Vector3 scale = new Vector3( GUtilities.InverseLerpUnclamped(0, terrainSize.x, Scale.x), GUtilities.InverseLerpUnclamped(0, terrainSize.y, Scale.y), GUtilities.InverseLerpUnclamped(0, terrainSize.z, Scale.z)); Matrix4x4 matrix = Matrix4x4.TRS( t.WorldPointToNormalized(Position), Rotation, scale); Matrix4x4 normalizeToStamp = matrix.inverse; GSpawner.DestroyIf(t, (g) => { Vector3 normalizePos = t.WorldPointToNormalized(g.transform.position); Vector3 stampSpacePos = normalizeToStamp.MultiplyPoint(normalizePos); return (stampSpacePos.x >= -0.5f && stampSpacePos.x <= 0.5f && stampSpacePos.y >= 0f && stampSpacePos.y <= 1f && stampSpacePos.z >= -0.5f && stampSpacePos.z <= 0.5f); }); }
private RenderTexture GetPreviewTexture(GStylizedTerrain t) { if (previewTextures == null) { previewTextures = new Dictionary <GStylizedTerrain, RenderTexture>(); } int resolution = instance.MaskResolution; if (!previewTextures.ContainsKey(t) || previewTextures[t] == null) { RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); previewTextures[t] = rt; } else if (previewTextures[t].width != resolution || previewTextures[t].height != resolution) { previewTextures[t].Release(); Object.DestroyImmediate(previewTextures[t]); RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); previewTextures[t] = rt; } previewTextures[t].wrapMode = TextureWrapMode.Clamp; return(previewTextures[t]); }
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 }
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]); // } //} }
private void RenderGeometryHeightMap(GStylizedTerrain terrain, RenderTexture targetRt) { GGeneralParams param = GTextureToolParams.Instance.General; RenderTexture rt = terrain.GetHeightMap(param.Resolution); GCommon.CopyToRT(rt, targetRt); }
private void DrawNeighboringGUI() { string label = "Neighboring"; string id = "polaris-v2-neighboring"; GenericMenu menu = new GenericMenu(); menu.AddItem( new GUIContent("Reset"), false, () => { ResetNeighboring(); }); menu.AddItem( new GUIContent("Connect"), false, () => { GStylizedTerrain.ConnectAdjacentTiles(); }); isNeighboringFoldoutExpanded = GEditorCommon.Foldout(label, false, id, () => { EditorGUI.BeginChangeCheck(); terrain.AutoConnect = EditorGUILayout.Toggle("Auto Connect", terrain.AutoConnect); terrain.GroupId = EditorGUILayout.DelayedIntField("Group Id", terrain.GroupId); terrain.TopNeighbor = EditorGUILayout.ObjectField("Top Neighbor", terrain.TopNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain; terrain.BottomNeighbor = EditorGUILayout.ObjectField("Bottom Neighbor", terrain.BottomNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain; terrain.LeftNeighbor = EditorGUILayout.ObjectField("Left Neighbor", terrain.LeftNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain; terrain.RightNeighbor = EditorGUILayout.ObjectField("Right Neighbor", terrain.RightNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain; if (EditorGUI.EndChangeCheck()) { if (terrain.TopNeighbor != null || terrain.BottomNeighbor != null || terrain.LeftNeighbor != null || terrain.RightNeighbor != null) { GAnalytics.Record(GAnalytics.MULTI_TERRAIN, true); } } }, menu); }
private void OnBeginRender(Camera cam) { if (cam.cameraType != CameraType.SceneView) { return; } if (painter.Editor_EnableLivePreview) { bool canDrawLivePreview = painter.ActivePainter != null && painter.ActivePainter is IGTexturePainterWithLivePreview; if (canDrawLivePreview) { Ray r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (GStylizedTerrain.Raycast(r, out hit, float.MaxValue, painter.GroupId)) { DrawLivePreview(cam, hit); } } } if (painter.EnableTerrainMask) { DrawMask(cam); } }
private void DrawCursorProjected(GStylizedTerrain t) { for (int i = 0; i < normalizedPoints.Length; ++i) { normalizedPoints[i] = t.WorldPointToUV(worldPoints[i]); } Rect dirtyRect = GUtilities.GetRectContainsPoints(normalizedPoints); GTerrainChunk[] chunks = t.GetChunks(); for (int i = 0; i < chunks.Length; ++i) { Rect uvRect = chunks[i].GetUvRange(); if (!uvRect.Overlaps(dirtyRect)) { continue; } Mesh m = chunks[i].MeshFilterComponent.sharedMesh; if (m == null) { continue; } Graphics.DrawMeshNow( m, Matrix4x4.TRS(chunks[i].transform.position, chunks[i].transform.rotation, chunks[i].transform.lossyScale)); } }
public static void Create(string backupName, int terrainGroupId, List <GTerrainResourceFlag> flags) { List <GStylizedTerrain> terrains = new List <GStylizedTerrain>(GStylizedTerrain.ActiveTerrains); for (int i = 0; i < terrains.Count; ++i) { GStylizedTerrain t = terrains[i]; if (t.TerrainData == null) { continue; } if (terrainGroupId >= 0 && terrainGroupId != t.GroupId) { continue; } try { BackupTerrain(t, backupName, flags); } catch (System.Exception e) { Debug.LogError(string.Format("Error on creating backup for {0}: {1}", t.name, e.ToString())); } } GBackupFile.SetBackupCreationTime(backupName, System.DateTime.Now); GUndoCompatibleBuffer.Instance.CurrentBackupName = backupName; if (Changed != null) { Changed.Invoke(); } }