Exemple #1
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.Mask.MaskMap;
            int           maskResolution = terrain.TerrainData.Mask.MaskMapResolution;
            RenderTexture rt             = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, maskResolution);
            GCommon.CopyToRT(bg, rt);

            Material mat = GInternalMaterials.MaskPainterMaterial;
            mat.SetTexture("_MainTex", bg);
            SetupTextureGrid(terrain, mat);
            mat.SetTexture("_Mask", args.BrushMask);
            mat.SetFloat("_Opacity", args.Opacity);

            GMaskPainterParams param = GTexturePainterCustomParams.Instance.Mask;
            Vector4            channel;
            if (param.Channel == GTextureChannel.R)
            {
                channel = new Vector4(1, 0, 0, 0);
            }
            else if (param.Channel == GTextureChannel.G)
            {
                channel = new Vector4(0, 1, 0, 0);
            }
            else if (param.Channel == GTextureChannel.B)
            {
                channel = new Vector4(0, 0, 1, 0);
            }
            else
            {
                channel = new Vector4(0, 0, 0, 1);
            }
            mat.SetVector("_Channel", channel);

            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.DrawMask4ChannelsLivePreview(
                terrain, cam,
                rt,
                GCommon.UnitRect);
#endif
        }
 private void DrawMask(Camera cam)
 {
     GCommon.ForEachTerrain(painter.GroupId, (t) =>
     {
         if (t.TerrainData == null)
         {
             return;
         }
         if (painter.ActivePainter is GMaskPainter)
         {
             GLivePreviewDrawer.DrawMask4ChannelsLivePreview(t, cam, t.TerrainData.Mask.MaskMap, GCommon.UnitRect);
         }
         else
         {
             GLivePreviewDrawer.DrawTerrainMask(t, cam);
         }
     });
 }