public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (commonUI.isRaycastHitUnderCursorValid)
            {
                using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "PaintHoles", editContext.brushTexture))
                {
                    if (brushRender.CalculateBrushTransform(out BrushTransform brushXform))
                    {
                        PaintContext paintContext = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1);
                        Material     material     = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial();

                        brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, material, 0);
                    }
                }
            }
        }
Esempio n. 2
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            // only do the rest if user mouse hits valid terrain or they are using the
            // brush parameter hotkeys to resize, etc
            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            // dont render preview if this isnt a repaint. losing performance if we do
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "HydroErosion", editContext.brushTexture))
            {
                if (brushRender.CalculateBrushTransform(out BrushTransform brushXform))
                {
                    PaintContext ctx = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1);

                    brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0);
                }
            }
        }
Esempio n. 3
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            commonUI.OnSceneGUI(terrain, editContext);

            Event evt = Event.current;

            if (evt.control && (evt.type == EventType.ScrollWheel))
            {
                const float k_mouseWheelToHeightRatio = -0.0004f;
                stampToolProperties.m_StampHeight += Event.current.delta.y * k_mouseWheelToHeightRatio * editContext.raycastHit.distance;
                evt.Use();
                editContext.Repaint();
                SaveSetting();
            }

            // We're only doing painting operations, early out if it's not a repaint
            if (evt.type != EventType.Repaint)
            {
                return;
            }

            if (commonUI.isRaycastHitUnderCursorValid)
            {
                Texture brushTexture = editContext.brushTexture;

                using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "Stamp", brushTexture))
                {
                    if (brushRender.CalculateBrushTransform(out BrushTransform brushXform))
                    {
                        PaintContext paintContext = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1);
                        Material     material     = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial();

                        brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, material, 0);

                        // draw result preview
                        {
                            ApplyBrushInternal(brushRender, paintContext, commonUI.brushStrength, brushTexture, brushXform, terrain);

                            // restore old render target
                            RenderTexture.active = paintContext.oldRenderTexture;

                            material.SetTexture("_HeightmapOrig", paintContext.sourceRenderTexture);

                            brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushXform, material, 1);
                        }
                        TerrainPaintUtility.ReleaseContextResources(paintContext);
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            // only do the rest if user mouse hits valid terrain or they are using the
            // brush parameter hotkeys to resize, etc
            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            // dont render preview if this isnt a repaint. losing performance if we do
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (commonUI.isRaycastHitUnderCursorValid)
            {
                Texture brushTexture = editContext.brushTexture;

                using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "Twist", editContext.brushTexture))
                {
                    //draw brush circle
                    if (brushRender.CalculateBrushTransform(out BrushTransform brushXform))
                    {
                        Material     material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial();
                        PaintContext ctx      = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1);

                        brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0);

                        // draw result preview
                        {
                            float finalTwistAmount = m_TwistAmount * -0.002f; //scale to a reasonable value and negate so default mode is clockwise
                            if (Event.current.shift)
                            {
                                finalTwistAmount *= -1.0f;
                            }

                            ApplyBrushInternal(brushRender, ctx, commonUI.brushStrength, finalTwistAmount, brushTexture, brushXform);

                            // restore old render target
                            RenderTexture.active = ctx.oldRenderTexture;

                            material.SetTexture("_HeightmapOrig", ctx.sourceRenderTexture);

                            brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushXform, material, 1);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            // only do the rest if user mouse hits valid terrain or they are using the
            // brush parameter hotkeys to resize, etc
            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            // dont render preview if this isnt a repaint. losing performance if we do
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            using (IBrushRenderPreviewUnderCursor brushPreview =
                       new BrushRenderPreviewUIGroupUnderCursor(commonUI, "NoiseHeightTool", editContext.brushTexture))
            {
                float   brushSize     = commonUI.brushSize;
                float   brushRotation = commonUI.brushRotation;
                float   brushStrength = Event.current.control ? -commonUI.brushStrength : commonUI.brushStrength;
                Vector3 brushPosWS    = commonUI.raycastHitUnderCursor.point;

                BrushTransform brushXform;
                brushPreview.CalculateBrushTransform(out brushXform);

                PaintContext ctx = brushPreview.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1);

                Material material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial();
                brushPreview.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, material, 0);

                ApplyBrushInternal(ctx, brushXform, brushPosWS, commonUI.brushRotation,
                                   brushStrength, brushSize, editContext.brushTexture);

                TerrainPaintUtility.SetupTerrainToolMaterialProperties(ctx, brushXform, material);

                // restore old render target
                RenderTexture.active = ctx.oldRenderTexture;

                material.SetTexture("_HeightmapOrig", ctx.sourceRenderTexture);

                TerrainPaintUtilityEditor.DrawBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture,
                                                           editContext.brushTexture, brushXform, material, 1);

                TerrainPaintUtility.ReleaseContextResources(ctx);
            }
        }
Esempio n. 6
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);

            // only do the rest if user mouse hits valid terrain or they are using the
            // brush parameter hotkeys to resize, etc
            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            // dont render preview if this isnt a repaint. losing performance if we do
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            Texture brushTexture = editContext.brushTexture;

            using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "SetHeightTool", brushTexture))
            {
                if (brushRender.CalculateBrushTransform(out BrushTransform brushTransform))
                {
                    Rect         brushBounds  = brushTransform.GetBrushXYBounds();
                    PaintContext paintContext = brushRender.AcquireHeightmap(false, brushBounds, 1);
                    Material     material     = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial();

                    brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushTransform, material, 0);

                    // draw result preview
                    {
                        ApplyBrushInternal(paintContext, brushRender, commonUI.brushStrength, brushTexture, brushTransform, terrain);

                        // restore old render target
                        RenderTexture.active = paintContext.oldRenderTexture;

                        material.SetTexture("_HeightmapOrig", paintContext.sourceRenderTexture);

                        brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushTransform, material, 1);
                    }
                }
            }
        }
Esempio n. 7
0
        public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext)
        {
            commonUI.OnSceneGUI2D(terrain, editContext);
#if UNITY_2019_1_OR_NEWER
            // Don't paint if eyedropper is selected
            if (m_EyedropperSelected)
            {
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.CustomCursor);
                editContext.Repaint();
                return;
            }
#endif

            // We're only doing painting operations, early out if it's not a repaint
            if (!editContext.hitValidTerrain && !commonUI.isInUse)
            {
                return;
            }

            // update brush UI group
            commonUI.OnSceneGUI(terrain, editContext);

            // Don't render preview if this isn't a repaint. losing performance if we do
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            Texture brushTexture = editContext.brushTexture;

            using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "PaintTextureTool", brushTexture))
            {
                if (brushRender.CalculateBrushTransform(out BrushTransform brushTransform))                 //cute.
                {
                    RenderTexture tmpRT            = RenderTexture.active;
                    Rect          brushBounds      = brushTransform.GetBrushXYBounds();
                    PaintContext  heightmapContext = brushRender.AcquireHeightmap(false, brushBounds, 1);
                    Material      brushMaterial    = GetBrushPreviewMaterial();

                    if (commonUI.brushMaskFilterStack.filters.Count > 0)
                    {
                        // Evaluate the brush mask filter stack
                        Vector3       brushPos = new Vector3(commonUI.raycastHitUnderCursor.point.x, 0, commonUI.raycastHitUnderCursor.point.z);
                        FilterContext fc       = new FilterContext(terrain, brushPos, commonUI.brushSize, commonUI.brushRotation);
                        fc.renderTextureCollection.GatherRenderTextures(heightmapContext.sourceRenderTexture.width, heightmapContext.sourceRenderTexture.height);
                        RenderTexture filterMaskRT = commonUI.GetBrushMask(fc, heightmapContext.sourceRenderTexture);

                        //Composite the brush texture onto the filter stack result
                        RenderTexture compRT   = RenderTexture.GetTemporary(filterMaskRT.descriptor);
                        Material      blendMat = GetBlendMaterial();
                        blendMat.SetTexture("_BlendTex", editContext.brushTexture);
                        blendMat.SetVector("_BlendParams", new Vector4(0.0f, 0.0f, -(commonUI.brushRotation * Mathf.Deg2Rad), 0.0f));
                        TerrainPaintUtility.SetupTerrainToolMaterialProperties(heightmapContext, brushTransform, blendMat);
                        Graphics.Blit(filterMaskRT, compRT, blendMat, 0);

                        RenderTexture.active = tmpRT;

                        BrushTransform identityBrushTransform = TerrainPaintUtility.CalculateBrushTransform(commonUI.terrainUnderCursor, commonUI.raycastHitUnderCursor.textureCoord, commonUI.brushSize, 0.0f);
                        TerrainPaintUtility.SetupTerrainToolMaterialProperties(heightmapContext, identityBrushTransform, brushMaterial);
                        TerrainPaintUtilityEditor.DrawBrushPreview(heightmapContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, compRT, identityBrushTransform, brushMaterial, 0);
                        RenderTexture.ReleaseTemporary(compRT);
                    }

                    brushRender.RenderBrushPreview(heightmapContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushTransform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0);
                }
            }
        }