Beispiel #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.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
        }
        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);
        }
        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
        }
Beispiel #4
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 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);
        }
Beispiel #6
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GBlurParams   blurParam = param.Blur;
            RenderTexture bg        = CloneBg(targetRt);

            Mat.SetTexture("_MainTex", bg);
            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, blurParam.Radius);
        }
Beispiel #7
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
        }
Beispiel #8
0
        public void Paint(GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Down)
            {
                terrain.ForceLOD(0);
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = true;
            }
            if (args.MouseEventType == GPainterMouseEventType.Up)
            {
                terrain.ForceLOD(-1);
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = false;
                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.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(heightMapResolution);

            GCommon.CopyToRT(bg, rt);

            Material mat = GInternalMaterials.VisibilityPainterMaterial;

            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 : 0;

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

            RenderTexture.active = rt;
            terrain.TerrainData.Geometry.HeightMap.ReadPixels(
                new Rect(0, 0, heightMapResolution, heightMapResolution), 0, 0);
            terrain.TerrainData.Geometry.HeightMap.Apply();
            RenderTexture.active = null;

            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
        public bool Internal_ApplySplat(GStylizedTerrain t, RenderTexture[] rtControls)
        {
            GetQuad(worldPoints);
            GetUvPoints(t, worldPoints, uvPoints);
            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvPoints);

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

            int brushResolution = t.TerrainData.Shading.SplatControlResolution;

            RenderTexture[] brushes = RenderBrushes(t, uvPoints, brushResolution);

            RenderTexture[] bg = new RenderTexture[rtControls.Length];
            for (int i = 0; i < bg.Length; ++i)
            {
                bg[i] = GetRenderTexture("bg" + i.ToString(), brushResolution);
                Texture2D splatControl = t.TerrainData.Shading.GetSplatControl(i);
                GCommon.CopyToRT(splatControl, bg[i]);
                GCommon.CopyToRT(splatControl, rtControls[i]);
            }

            Material paintMaterial = GInternalMaterials.SplatPainterMaterial;

            paintMaterial.SetFloat("_Opacity", 1);
            for (int i = 0; i < brushes.Length; ++i)
            {
                if (Layers[i].Ignore)
                {
                    continue;
                }
                paintMaterial.SetTexture("_Mask", brushes[i]);
                int controlMapCount = rtControls.Length;
                for (int controlIndex = 0; controlIndex < controlMapCount; ++controlIndex)
                {
                    GCommon.CopyToRT(bg[controlIndex], rtControls[controlIndex]);
                    paintMaterial.SetTexture("_MainTex", bg[controlIndex]);
                    if (Layers[i].SplatIndex / 4 == controlIndex)
                    {
                        paintMaterial.SetInt("_ChannelIndex", Layers[i].SplatIndex % 4);
                    }
                    else
                    {
                        paintMaterial.SetInt("_ChannelIndex", -1);
                    }
                    int pass = 0;
                    GCommon.DrawQuad(rtControls[controlIndex], GCommon.FullRectUvPoints, paintMaterial, pass);
                    GCommon.CopyToRT(rtControls[controlIndex], bg[controlIndex]);
                }
            }

            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
            return(true);
        }
Beispiel #10
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GStepParams   stepParam = param.Step;
            RenderTexture bg        = CloneBg(targetRt);

            Mat.SetTexture("_MainTex", bg);
            Mat.SetInt("_Count", stepParam.Count);

            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0);
        }
        public void Generate(RenderTexture targetRt, GNoiseMapGeneratorParams param)
        {
            Mat.SetVector("_Origin", param.Origin);
            Mat.SetFloat("_Frequency", param.Frequency);
            Mat.SetFloat("_Lacunarity", param.Lacunarity);
            Mat.SetFloat("_Persistence", param.Persistence);
            Mat.SetInt("_Octaves", param.Octaves);
            Mat.SetFloat("_Seed", param.Seed);

            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, (int)param.Type);
        }
Beispiel #12
0
        public void RenderPerPixelNormalMap(GNormalMapGeneratorParams param, RenderTexture targetRt)
        {
            Material mat = GInternalMaterials.TerrainPerPixelNormalMapRendererMaterial;

            mat.SetTexture("_HeightMap", param.Terrain.TerrainData.Geometry.HeightMap);
            mat.SetFloat("_Width", param.Terrain.TerrainData.Geometry.Width);
            mat.SetFloat("_Height", param.Terrain.TerrainData.Geometry.Height);
            mat.SetFloat("_Length", param.Terrain.TerrainData.Geometry.Length);
            mat.SetInt("_TangentSpace", param.Space == GNormalMapSpace.Tangent ? 1 : 0);

            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, mat, 0);
        }
Beispiel #13
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GInvertParams invertParam = param.Invert;
            RenderTexture bg          = CloneBg(targetRt);

            Mat.SetTexture("_MainTex", bg);
            Mat.SetInt("_InvertRed", invertParam.InvertRed ? 1 : 0);
            Mat.SetInt("_InvertGreen", invertParam.InvertGreen ? 1 : 0);
            Mat.SetInt("_InvertBlue", invertParam.InvertBlue ? 1 : 0);
            Mat.SetInt("_InvertAlpha", invertParam.InvertAlpha ? 1 : 0);
            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0);
        }
Beispiel #14
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GWarpParams   warpParam = param.Warp;
            RenderTexture bg        = CloneBg(targetRt);

            Mat.SetTexture("_MainTex", bg);
            Mat.SetTexture("_Mask", warpParam.UseBackgroundAsMask ? (Texture)bg : (Texture)warpParam.Mask);
            Mat.SetFloat("_Strength", warpParam.Strength);
            GCommon.SetMaterialKeywordActive(Mat, "MASK_IS_NORMAL", warpParam.MaskIsNormalMap);

            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0);
        }
Beispiel #15
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;
            }
            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
        }
        public void Internal_Apply(GStylizedTerrain t, RenderTexture rt)
        {
            GCommon.CopyToRT(t.TerrainData.Geometry.HeightMap, rt);

            Vector3[] worldCorner = GetQuad();
            Vector2[] uvCorners   = new Vector2[worldCorner.Length];
            for (int i = 0; i < uvCorners.Length; ++i)
            {
                uvCorners[i] = t.WorldPointToUV(worldCorner[i]);
            }

            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners);

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

            Vector3 normalizedPos = t.WorldPointToNormalized(Position);
            float   stampHeight   = GUtilities.InverseLerpUnclamped(0, t.TerrainData.Geometry.Height, Scale.y);

            Material mat = GInternalMaterials.StamperMaterial;

            mat.SetTexture("_HeightMap", t.TerrainData.Geometry.HeightMap);
            mat.SetTexture("_Stamp", Stamp);
            mat.SetTexture("_Falloff", falloffTexture);
            mat.SetInt("_Operation", (int)Operation);
            mat.SetFloat("_LerpFactor", LerpFactor);
            mat.SetFloat("_StampHeight", stampHeight);
            mat.SetFloat("_StampPositionY", normalizedPos.y);
            mat.SetFloat("_Inverse", InverseStamp ? 1 : 0);
            mat.SetFloat("_UseFalloffAsBlendFactor", UseFalloffAsBlendFactor ? 1 : 0);
            mat.SetFloat("_AdditionalMeshResolution", GCommon.SUB_DIV_STEP * AdditionalMeshResolution);
            if (EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", t.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }

            int pass = (int)Channel;

            GCommon.DrawQuad(rt, uvCorners, mat, pass);
        }
Beispiel #17
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);

            RenderTexture noiseMap = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, heightMapResolution, 1);
            RenderNoiseTexture(noiseMap, terrain);

            Material mat = GInternalMaterials.NoisePainterMaterial;
            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.BrushMask);
            mat.SetFloat("_Opacity", Mathf.Pow(args.Opacity, GTerrainTexturePainter.GEOMETRY_OPACITY_EXPONENT));
            mat.SetTexture("_NoiseMap", noiseMap);
            if (args.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", terrain.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            GCommon.SetMaterialKeywordActive(mat, "USE_WORLD_SPACE", GTexturePainterCustomParams.Instance.Noise.UseWorldSpace);
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 : 0;
            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            GLivePreviewDrawer.DrawGeometryLivePreview(terrain, cam, rt, dirtyRect);
#endif
        }
Beispiel #18
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);

            Material mat = GInternalMaterials.SubDivPainterMaterial;
            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.BrushMask);
            mat.SetFloat("_Opacity", Mathf.Pow(args.Opacity, GTerrainTexturePainter.GEOMETRY_OPACITY_EXPONENT));
            if (args.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", terrain.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 : 0;
            GCommon.DrawQuad(rt, uvCorners, mat, pass);

            Matrix4x4 worldToMaskMatrix = Matrix4x4.TRS(
                args.WorldPointCorners[0],
                Quaternion.Euler(0, args.Rotation, 0),
                args.Radius * 2 * Vector3.one).inverse;

            GLivePreviewDrawer.DrawSubdivLivePreview(terrain, cam, rt, dirtyRect, args.BrushMask, worldToMaskMatrix);
#endif
        }
        private void RenderColorMap(GStylizedTerrain t, RenderTexture targetRt)
        {
            GShading shading = t.TerrainData.Shading;

            if (shading.Splats == null)
            {
                return;
            }
            Material mat = GInternalMaterials.SplatsToAlbedoMaterial;

            for (int i = 0; i < shading.SplatControlMapCount; ++i)
            {
                Texture2D controlMap = shading.GetSplatControl(i);
                mat.SetTexture("_Control0", controlMap);
                for (int channel = 0; channel < 4; ++channel)
                {
                    int prototypeIndex = i * 4 + channel;
                    if (prototypeIndex < shading.Splats.Prototypes.Count)
                    {
                        GSplatPrototype p = shading.Splats.Prototypes[prototypeIndex];
                        mat.SetTexture("_Splat" + channel, p.Texture);
                        Vector2 terrainSize  = new Vector2(t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Length);
                        Vector2 textureScale = new Vector2(
                            p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0,
                            p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0);
                        Vector2 textureOffset = new Vector2(
                            p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0,
                            p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0);
                        mat.SetTextureScale("_Splat" + channel, textureScale);
                        mat.SetTextureOffset("_Splat" + channel, textureOffset);
                    }
                    else
                    {
                        mat.SetTexture("_Splat" + channel, null);
                        mat.SetTextureScale("_Splat" + channel, Vector2.zero);
                        mat.SetTextureOffset("_Splat" + channel, Vector2.zero);
                    }
                }

                GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, mat, 0);
            }
        }
Beispiel #20
0
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GHydraulicErosionParams erosionParam = param.HydraulicErosion;
            RenderTexture           writeRt      = null; //buffer to write to
            RenderTexture           readRt       = null; //buffer to read from
            RenderTexture           tmp          = null; //temp buffer for swapping

            CloneBg(targetRt, out writeRt, out readRt);

            //init height field & water level
            Mat.SetTexture("_HeightMap", targetRt);
            GCommon.DrawQuad(writeRt, GCommon.FullRectUvPoints, Mat, 0);
            GCommon.DrawQuad(readRt, GCommon.FullRectUvPoints, Mat, 0);

            //simulate
            for (int i = 0; i < erosionParam.Iteration; ++i)
            {
                Mat.SetTexture("_HeightMap", readRt);
                Mat.SetVector("_Dimension", erosionParam.Dimension);
                Mat.SetFloat("_Rain", erosionParam.Rain);
                Mat.SetFloat("_Transportation", erosionParam.Transportation);
                Mat.SetFloat("_MinAngle", erosionParam.AngleMin);
                Mat.SetFloat("_Evaporation", erosionParam.Evaporation);
                Mat.SetTexture("_WaterSourceMap", erosionParam.WaterSourceMap);
                Mat.SetTexture("_HardnessMap", erosionParam.HardnessMap);
                //Mat.SetFloat("_Seed", Random.value);
                GCommon.DrawQuad(writeRt, GCommon.FullRectUvPoints, Mat, 1);

                //swap buffer
                tmp     = readRt;
                readRt  = writeRt;
                writeRt = tmp;
            }

            //copy result
            GCommon.CopyToRT(writeRt, targetRt);
        }
        public void Generate(RenderTexture targetRt)
        {
            GSteepnessMapGeneratorParams param = GTextureToolParams.Instance.Steepness;

            if (param.Terrain == null || param.Terrain.TerrainData == null)
            {
                GCommon.FillTexture(targetRt, Color.clear);
            }
            else
            {
                GNormalMapGeneratorParams normalMapParam = new GNormalMapGeneratorParams();
                normalMapParam.Terrain = param.Terrain;
                normalMapParam.Space   = GNormalMapSpace.Local;
                normalMapParam.Mode    = param.Mode;

                RenderTexture       normalMap = new RenderTexture(targetRt);
                GNormalMapGenerator gen       = new GNormalMapGenerator();
                if (param.Mode == GNormalMapMode.Sharp)
                {
                    gen.RenderSharpNormalMap(normalMapParam, normalMap);
                }
                else if (param.Mode == GNormalMapMode.Interpolated)
                {
                    gen.RenderInterpolatedNormalMap(normalMapParam, normalMap);
                }
                else if (param.Mode == GNormalMapMode.PerPixel)
                {
                    gen.RenderPerPixelNormalMap(normalMapParam, normalMap);
                }

                Mat.SetTexture("_BumpMap", normalMap);
                GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0);

                normalMap.Release();
                GUtilities.DestroyObject(normalMap);
            }
        }
        public void Apply(RenderTexture targetRt, GTextureFilterParams param)
        {
            GCurveParams  curveParam     = param.Curve;
            RenderTexture bg             = CloneBg(targetRt);
            Texture2D     masterCurveTex = GCommon.CreateTextureFromCurve(curveParam.MasterCurve, 1024, 1);
            Texture2D     redCurveTex    = GCommon.CreateTextureFromCurve(curveParam.RedCurve, 1024, 1);
            Texture2D     greenCurveTex  = GCommon.CreateTextureFromCurve(curveParam.GreenCurve, 1024, 1);
            Texture2D     blueCurveTex   = GCommon.CreateTextureFromCurve(curveParam.BlueCurve, 1024, 1);
            Texture2D     alphaCurveTex  = GCommon.CreateTextureFromCurve(curveParam.AlphaCurve, 1024, 1);

            Mat.SetTexture("_MainTex", bg);
            Mat.SetTexture("_MasterCurve", masterCurveTex);
            Mat.SetTexture("_RedCurve", redCurveTex);
            Mat.SetTexture("_GreenCurve", greenCurveTex);
            Mat.SetTexture("_BlueCurve", blueCurveTex);
            Mat.SetTexture("_AlphaCurve", alphaCurveTex);
            GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0);

            GUtilities.DestroyObject(masterCurveTex);
            GUtilities.DestroyObject(redCurveTex);
            GUtilities.DestroyObject(greenCurveTex);
            GUtilities.DestroyObject(blueCurveTex);
            GUtilities.DestroyObject(alphaCurveTex);
        }
Beispiel #23
0
        public void Paint(GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Down)
            {
            }
            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.Mask.MaskMap;
            int           maskResolution = terrain.TerrainData.Mask.MaskMapResolution;
            RenderTexture rt             = GTerrainTexturePainter.Internal_GetRenderTexture(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);

            RenderTexture.active = rt;
            terrain.TerrainData.Mask.MaskMap.ReadPixels(
                new Rect(0, 0, maskResolution, maskResolution), 0, 0);
            terrain.TerrainData.Mask.MaskMap.Apply();
            RenderTexture.active = null;

            if (!args.ForceUpdateGeometry)
            {
                return;
            }
            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
Beispiel #24
0
        public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (terrain.TerrainData.Shading.Splats == 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;
            }
            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(controlMapResolution);
                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);

                RenderTexture.active = rt;
                splatControl.ReadPixels(new Rect(0, 0, controlMapResolution, controlMapResolution), 0, 0);
                splatControl.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);
        }
Beispiel #25
0
        public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Down)
            {
                terrain.ForceLOD(0);
                GRuntimeSettings.Instance.isEditingGeometry = true;
            }
            if (args.MouseEventType == GPainterMouseEventType.Up)
            {
                terrain.ForceLOD(-1);
                GRuntimeSettings.Instance.isEditingGeometry = false;
                terrain.UpdateTreesPosition();
                terrain.UpdateGrassPatches();
                terrain.TerrainData.Foliage.ClearTreeDirtyRegions();
                terrain.TerrainData.Foliage.ClearGrassDirtyRegions();
                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.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(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.BrushMask);
            mat.SetFloat("_Opacity", Mathf.Pow(args.Opacity, GTerrainTexturePainter.GEOMETRY_OPACITY_EXPONENT));
            mat.SetTexture("_RemapTex", remapTex);
            if (args.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", terrain.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            int pass = 0;

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

            RenderTexture.active = rt;
            terrain.TerrainData.Geometry.HeightMap.ReadPixels(
                new Rect(0, 0, heightMapResolution, heightMapResolution), 0, 0);
            terrain.TerrainData.Geometry.HeightMap.Apply();
            RenderTexture.active = null;

            GUtilities.DestroyObject(remapTex);

            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetTreeRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetGrassRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
Beispiel #26
0
        public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Down)
            {
                terrain.ForceLOD(0);
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = true;
            }
            if (args.MouseEventType == GPainterMouseEventType.Up)
            {
                terrain.ForceLOD(-1);
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = false;
                terrain.UpdateTreesPosition();
                terrain.UpdateGrassPatches();
                terrain.TerrainData.Foliage.ClearTreeDirtyRegions();
                terrain.TerrainData.Foliage.ClearGrassDirtyRegions();
                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.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(heightMapResolution);

            GCommon.CopyToRT(bg, rt);

            RenderTexture noiseMap = GTerrainTexturePainter.Internal_GetRenderTexture(terrain, heightMapResolution, 1);

            RenderNoiseTexture(noiseMap, terrain);

            Material mat = GInternalMaterials.NoisePainterMaterial;

            mat.SetTexture("_MainTex", bg);
            mat.SetTexture("_Mask", args.Mask);
            mat.SetFloat("_Opacity", args.Opacity);
            mat.SetTexture("_NoiseMap", noiseMap);
            GCommon.SetMaterialKeywordActive(mat, "USE_WORLD_SPACE", GTexturePainterCustomParams.Instance.Noise.UseWorldSpace);
            int pass =
                args.ActionType == GPainterActionType.Normal ? 0 :
                args.ActionType == GPainterActionType.Negative ? 1 : 0;

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

            RenderTexture.active = rt;
            terrain.TerrainData.Geometry.HeightMap.ReadPixels(
                new Rect(0, 0, heightMapResolution, heightMapResolution), 0, 0);
            terrain.TerrainData.Geometry.HeightMap.Apply();
            RenderTexture.active = null;

            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetTreeRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetGrassRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
Beispiel #27
0
        public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args)
        {
            if (terrain.TerrainData == null)
            {
                return;
            }
            if (args.ActionType != GPainterActionType.Normal)
            {
                terrain.ForceLOD(-1);
                return;
            }
            if (args.MouseEventType == GPainterMouseEventType.Down)
            {
                terrain.ForceLOD(0);
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = true;
            }
            if (args.MouseEventType == GPainterMouseEventType.Up)
            {
                GGriffinSettings.Instance.IsHidingFoliageOnEditing = false;
                terrain.UpdateTreesPosition();
                terrain.UpdateGrassPatches();
                terrain.TerrainData.Foliage.ClearTreeDirtyRegions();
                terrain.TerrainData.Foliage.ClearGrassDirtyRegions();
                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.Geometry.HeightMap;
            int           heightMapResolution = terrain.TerrainData.Geometry.HeightMapResolution;
            RenderTexture rt = GTerrainTexturePainter.Internal_GetRenderTexture(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);

            RenderTexture.active = rt;
            terrain.TerrainData.Geometry.HeightMap.ReadPixels(
                new Rect(0, 0, heightMapResolution, heightMapResolution), 0, 0);
            terrain.TerrainData.Geometry.HeightMap.Apply();
            RenderTexture.active = null;

            terrain.TerrainData.Geometry.SetRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetTreeRegionDirty(dirtyRect);
            terrain.TerrainData.Foliage.SetGrassRegionDirty(dirtyRect);
            terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
Beispiel #28
0
        public bool Internal_ApplyAlbedoMetallicSmoothness(GStylizedTerrain t, RenderTexture albedoRt, RenderTexture metallicRt)
        {
            GetQuad(worldPoints);
            GetUvPoints(t, worldPoints, uvPoints);
            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvPoints);

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

            int brushResolution = Mathf.Max(t.TerrainData.Shading.AlbedoMapResolution, t.TerrainData.Shading.MetallicMapResolution);

            RenderTexture[] brushes = RenderBrushes(t, uvPoints, brushResolution);

            RenderTexture bg0       = GetRenderTexture("bg0", brushResolution);
            Texture2D     albedoMap = t.TerrainData.Shading.AlbedoMap;

            GCommon.CopyToRT(albedoMap, bg0);
            GCommon.CopyToRT(albedoMap, albedoRt);

            Material mat = GInternalMaterials.AlbedoPainterMaterial;

            mat.SetFloat("_Opacity", 1);
            for (int i = 0; i < brushes.Length; ++i)
            {
                if (Layers[i].Ignore)
                {
                    continue;
                }
                mat.SetTexture("_MainTex", bg0);
                mat.SetTexture("_Mask", brushes[i]);
                mat.SetColor("_Color", Layers[i].Color);
                int pass = 0;
                GCommon.DrawQuad(albedoRt, GCommon.FullRectUvPoints, mat, pass);
                GCommon.CopyToRT(albedoRt, bg0);
            }

            RenderTexture bg1         = GetRenderTexture("bg1", brushResolution);
            Texture2D     metallicMap = t.TerrainData.Shading.MetallicMap;

            GCommon.CopyToRT(metallicMap, bg1);
            GCommon.CopyToRT(metallicMap, metallicRt);

            mat = GInternalMaterials.MetallicPainterMaterial;
            mat.SetFloat("_Opacity", 1);
            for (int i = 0; i < brushes.Length; ++i)
            {
                if (Layers[i].Ignore)
                {
                    continue;
                }
                mat.SetTexture("_MainTex", bg1);
                mat.SetTexture("_Mask", brushes[i]);
                mat.SetColor("_Color", Color.white * Layers[i].Metallic);
                int pass = 3; //fragSet
                GCommon.DrawQuad(metallicRt, GCommon.FullRectUvPoints, mat, pass);
                GCommon.CopyToRT(metallicRt, bg1);
            }

            mat = GInternalMaterials.SmoothnessPainterMaterial;
            mat.SetFloat("_Opacity", 1);
            for (int i = 0; i < brushes.Length; ++i)
            {
                if (Layers[i].Ignore)
                {
                    continue;
                }
                mat.SetTexture("_MainTex", bg1);
                mat.SetTexture("_Mask", brushes[i]);
                mat.SetColor("_Color", Color.white * Layers[i].Smoothness);
                int pass = 3; //fragSet
                GCommon.DrawQuad(metallicRt, GCommon.FullRectUvPoints, mat, pass);
                GCommon.CopyToRT(metallicRt, bg1);
            }

            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
            return(true);
        }