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; } Material mat = GInternalMaterials.SplatPainterMaterial; mat.SetTexture("_Mask", args.Mask); mat.SetFloat("_Opacity", args.Opacity); int controlMapResolution = terrain.TerrainData.Shading.SplatControlResolution; int controlMapCount = terrain.TerrainData.Shading.SplatControlMapCount; for (int i = 0; i < controlMapCount; ++i) { Texture2D splatControl = terrain.TerrainData.Shading.GetSplatControl(i); RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, controlMapResolution, i); GCommon.CopyToRT(splatControl, rt); mat.SetTexture("_MainTex", splatControl); if (args.SplatIndex / 4 == i) { mat.SetInt("_ChannelIndex", args.SplatIndex % 4); } else { mat.SetInt("_ChannelIndex", -1); } int pass = args.ActionType == GPainterActionType.Normal ? 0 : args.ActionType == GPainterActionType.Negative ? 1 : args.ActionType == GPainterActionType.Alternative ? 2 : 0; GCommon.DrawQuad(rt, uvCorners, mat, pass); } Texture[] controls = new Texture[controlMapCount]; for (int i = 0; i < controlMapCount; ++i) { controls[i] = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, controlMapResolution, i); } GLivePreviewDrawer.DrawSplatLivePreview(terrain, cam, controls, dirtyRect); #endif }
private void DrawLivePreview(GStylizedTerrain t, Camera cam) { if (t.transform.rotation != Quaternion.identity || t.transform.lossyScale != Vector3.one) { return; } 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 == GTextureStampChannel.AlbedoMetallicSmoothness) { int albedoResolution = t.TerrainData.Shading.AlbedoMapResolution; FilterMode albedoFilter = t.TerrainData.Shading.AlbedoMap.filterMode; int metallicResolution = t.TerrainData.Shading.MetallicMapResolution; FilterMode metallicFilter = t.TerrainData.Shading.MetallicMap.filterMode; Texture albedo = GetPreviewTexture(t, "albedo", albedoResolution, albedoFilter); Texture metallic = GetPreviewTexture(t, "metallic", metallicResolution, metallicFilter); GLivePreviewDrawer.DrawAMSLivePreview(t, cam, albedo, metallic, dirtyRect); } else if (instance.Channel == GTextureStampChannel.Splat) { int controlMapResolution = t.TerrainData.Shading.SplatControlResolution; Texture[] controls = new Texture[t.TerrainData.Shading.SplatControlMapCount]; for (int i = 0; i < controls.Length; ++i) { Texture currentControl = t.TerrainData.Shading.GetSplatControl(i); controls[i] = GetPreviewTexture(t, "splatControl" + i, controlMapResolution, currentControl.filterMode); } GLivePreviewDrawer.DrawSplatLivePreview(t, cam, controls, dirtyRect); } }
private void SetupSplatPreview(GStylizedTerrain t, Camera cam, Rect dirtyRect) { 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) { rtControls[i] = GetPreviewTexture(t, "splatControl" + i, controlMapResolution, t.TerrainData.Shading.SplatControls[i].filterMode); } instance.Internal_ApplySplat(t, instance.SplineCreator.Editor_Vertices, rtControls); GLivePreviewDrawer.DrawSplatLivePreview(t, cam, rtControls, dirtyRect); }