protected override void OnEval(FilterContext filterContext, RenderTexture source, RenderTexture dest)
        {
            var     mat           = Material;
            Vector4 smoothWeights = new Vector4(
                Mathf.Clamp01(1.0f - Mathf.Abs(m_Direction)),   // centered
                Mathf.Clamp01(-m_Direction),                    // min
                Mathf.Clamp01(m_Direction),                     // max
                0);

            mat.SetVector("_SmoothWeights", smoothWeights);
            mat.SetInt("_KernelSize", Mathf.Max(1, m_Amount));  // kernel size

            // Two pass blur (first horizontal, then vertical)
            var tmpRT = RTUtils.GetTempHandle(dest.descriptor);

            tmpRT.RT.wrapMode = TextureWrapMode.Clamp;
            mat.SetVector("_BlurDirection", Vector2.right);
            Graphics.Blit(source, tmpRT, mat);
            mat.SetVector("_BlurDirection", Vector2.up);
            Graphics.Blit(tmpRT, dest, mat);
            RTUtils.Release(tmpRT);
        }
        protected override void OnDrawGUI(Rect rect, FilterContext filterContext)
        {
            //Calculate dimensions
            float epsilonLabelWidth  = GUI.skin.label.CalcSize(epsilonLabel).x;
            float modeLabelWidth     = GUI.skin.label.CalcSize(modeLabel).x;
            float strengthLabelWidth = GUI.skin.label.CalcSize(strengthLabel).x;
            float curveLabelWidth    = GUI.skin.label.CalcSize(curveLabel).x;
            float labelWidth         = Mathf.Max(Mathf.Max(Mathf.Max(modeLabelWidth, epsilonLabelWidth), strengthLabelWidth), curveLabelWidth) + 4.0f;

            //Strength Slider
            Rect strengthLabelRect = new Rect(rect.x, rect.y, labelWidth, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(strengthLabelRect, strengthLabel);
            Rect strengthSliderRect = new Rect(strengthLabelRect.xMax, strengthLabelRect.y, rect.width - labelWidth, strengthLabelRect.height);

            m_FilterStrength = EditorGUI.Slider(strengthSliderRect, m_FilterStrength, 0.0f, 1.0f);

            //Epsilon (kernel size) Slider
            Rect epsilonLabelRect = new Rect(rect.x, strengthSliderRect.yMax, labelWidth, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(epsilonLabelRect, epsilonLabel);
            Rect epsilonSliderRect = new Rect(epsilonLabelRect.xMax, epsilonLabelRect.y, rect.width - labelWidth, epsilonLabelRect.height);

            m_Epsilon = EditorGUI.Slider(epsilonSliderRect, m_Epsilon, 1.0f, 20.0f);

            //Value Remap Curve
            Rect curveLabelRect = new Rect(rect.x, epsilonSliderRect.yMax, labelWidth, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(curveLabelRect, curveLabel);
            Rect curveRect = new Rect(curveLabelRect.xMax, curveLabelRect.y, rect.width - labelWidth, curveLabelRect.height);

            EditorGUI.BeginChangeCheck();
            m_RemapCurve = EditorGUI.CurveField(curveRect, m_RemapCurve);
            if (EditorGUI.EndChangeCheck())
            {
                var tex = GetRemapTexture();
                Utility.AnimationCurveToRenderTexture(m_RemapCurve, ref tex);
            }
        }
 /// <summary>
 /// Returns a brush transform that can only be used for its size.
 /// </summary>
 /// <param name="fc">filter context for brush size & rotation</param>
 /// <returns></returns>
 internal static BrushTransform GetBrushTransform(FilterContext fc)
 {
     return(GetBrushTransform(fc.brushRotation, fc.brushSize));
 }
 protected override void OnDrawGUI(Rect rect, FilterContext filterContext)
 {
     value = EditorGUI.FloatField(rect, value);
 }
        protected override void OnEval(FilterContext fc, RenderTexture sourceRenderTexture, RenderTexture destinationRenderTexture)
        {
            FilterUtility.builtinMaterial.SetFloat("_Pow", value);

            Graphics.Blit(sourceRenderTexture, destinationRenderTexture, FilterUtility.builtinMaterial, (int)FilterUtility.BuiltinPasses.Power);
        }
 protected override void OnEval(FilterContext filterContext, RenderTexture sourceRenderTexture, RenderTexture destinationRenderTexture)
 {
     Graphics.Blit(sourceRenderTexture, destinationRenderTexture, FilterUtility.builtinMaterial, (int)FilterUtility.BuiltinPasses.Negate);
 }
 protected override void OnDrawGUI(Rect rect, FilterContext filterContext)
 {
     range = EditorGUI.Vector2Field(rect, "", range);
 }
 /// <summary>
 /// Handle SceneView related logic or rendering
 /// </summary>
 /// <param name="terrain">The target Terrain</param>
 /// <param name="brushContext">The current brush parameters</param>
 protected virtual void OnSceneGUI(SceneView sceneView, FilterContext filterContext)
 {
 }
 protected override void OnEval(FilterContext filterContext, RenderTexture source, RenderTexture dest)
 {
     FilterUtility.builtinMaterial.SetFloat("_Add", value);
     Graphics.Blit(source, dest, FilterUtility.builtinMaterial, (int)FilterUtility.BuiltinPasses.Add);
 }
        protected override void OnSceneGUI(SceneView sceneView, FilterContext filterContext)
        {
            Quaternion windRot = Quaternion.AngleAxis(filterContext.brushRotation, new Vector3(0.0f, 1.0f, 0.0f));

            Handles.ArrowHandleCap(0, filterContext.brushPos, windRot, 0.5f * filterContext.brushSize, EventType.Repaint);
        }
 protected override void OnEval(FilterContext filterContext, RenderTexture source, RenderTexture dest)
 {
     FilterUtility.builtinMaterial.SetVector("_RemapRanges", new Vector4(m_FromRange.x, m_FromRange.y, m_ToRange.x, m_ToRange.y));
     Graphics.Blit(source, dest, FilterUtility.builtinMaterial, (int)FilterUtility.BuiltinPasses.Remap);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Evaluate the Filter. Override this function for custom Filter logic
 /// </summary>
 /// <param name="filterContext">The FilterContext related to the current evaluation</param>
 /// <param name="source">The source RenderTexture on which the Filter operates</param>
 /// <param name="dest">The destination RenderTexture to which the Filter blits the results of the Filter operation</param>
 protected virtual void OnEval(FilterContext filterContext, RenderTexture source, RenderTexture dest)
 {
     Graphics.Blit(source, dest);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Called before OnEval. Use this to set up anything needed before Filter evaluation and to also tell the system
 /// whether or not the Filter is supported based on current hardware, the data provided by the provided
 /// FilterContext, etc. Do this by returning True or False.
 /// </summary>
 /// <param name="filterContext">The FilterContext related to the current evaluation</param>
 /// <returns>Whether or not the Filter is supported and should be evaluated. True = supported and is okay to evaluate.
 /// False = the Filter is not supported with the current hardware and should be skipped</returns>
 public virtual bool ValidateFilter(FilterContext filterContext, out string message)
 {
     message = string.Empty;
     return(true);
 }
        protected override void OnDrawGUI(Rect rect, FilterContext filterContext)
        {
            if (m_noiseSettings == null)
            {
                m_noiseSettings = ScriptableObject.CreateInstance <NoiseSettings>();
            }

            GUIContent localLabel     = NoiseFilter.localLabel;
            GUIContent worldLabel     = NoiseFilter.worldLabel;
            GUIContent heightmapLabel = NoiseFilter.heightmapLabel;
            GUIContent editLabel      = NoiseFilter.editLabel;

            float editWith = GUI.skin.label.CalcSize(editLabel).x + 20f;
            Rect  editRect = new Rect(rect.xMax - editWith, rect.y, editWith, rect.height);

            Rect labelRect = rect;

            labelRect.width = GUI.skin.label.CalcSize(coordinateLabel).x;

            Rect worldRect = labelRect;

            worldRect.x     = labelRect.xMax;
            worldRect.width = GUI.skin.button.CalcSize(worldLabel).x + 10f;

            Rect localRect = worldRect;

            localRect.x     = worldRect.xMax;
            localRect.width = GUI.skin.button.CalcSize(localLabel).x + 10f;

            Rect heightmapRect = localRect;

            heightmapRect.x     = localRect.xMax + 10f;
            heightmapRect.width = GUI.skin.button.CalcSize(heightmapLabel).x + 10f;

            if (editRect.xMin < heightmapRect.xMax + 10f)
            {
                worldRect.x     -= labelRect.width;
                localRect.x     -= labelRect.width;
                heightmapRect.x -= labelRect.width;
                labelRect.width  = 0;
            }

            editRect.x = Mathf.Max(editRect.x, heightmapRect.xMax + 4f);

            if (editRect.xMax > rect.xMax)
            {
                worldLabel          = NoiseFilter.worldShortLabel;
                localLabel          = NoiseFilter.localShortLabel;
                heightmapLabel      = NoiseFilter.heightmapShortLabel;
                worldRect.width     = GUI.skin.label.CalcSize(worldLabel).x + 10f;
                localRect.width     = GUI.skin.label.CalcSize(localLabel).x + 10f;
                heightmapRect.width = GUI.skin.label.CalcSize(heightmapLabel).x + 10f;
                localRect.x         = worldRect.xMax;
                heightmapRect.x     = localRect.xMax + 10f;

                editRect.x = rect.xMax - editWith;
            }

            editRect.x = Mathf.Max(heightmapRect.xMax + 4f, editRect.x);

            if (editRect.xMax > rect.xMax)
            {
                editLabel      = editShortLabel;
                editRect.width = GUI.skin.label.CalcSize(editLabel).x + 10f;
            }

            GUI.Label(labelRect, coordinateLabel);

            if (GUI.Toggle(worldRect, !m_isLocalSpace, worldLabel, GUI.skin.button))
            {
                m_isLocalSpace = false;
            }

            if (GUI.Toggle(localRect, m_isLocalSpace, localLabel, GUI.skin.button))
            {
                m_isLocalSpace = true;
            }

            m_useHeightmap = GUI.Toggle(heightmapRect, m_useHeightmap, heightmapLabel, GUI.skin.button);

            m_noiseSettings.useTextureForPositions = m_useHeightmap;

            if (GUI.Button(editRect, editLabel))
            {
                NoiseWindow wnd = NoiseWindow.Create(m_noiseSettings, m_noiseSource);
                wnd.noiseEditorView.onSettingsChanged += (noise) =>
                {
                    m_noiseSettings.Copy(noise);
                };
                wnd.noiseEditorView.onSourceAssetChanged += (noise) =>
                {
                    m_noiseSource = noise;
                };
                wnd.onDisableCallback += () =>
                {
                    m_window = null;
                };

                m_window = wnd;
            }
        }
        protected override void OnEval(FilterContext fc, RenderTexture sourceRenderTexture, RenderTexture destinationRenderTexture)
        {
            FilterUtility.builtinMaterial.SetVector("_ClampRange", range);

            Graphics.Blit(sourceRenderTexture, destinationRenderTexture, FilterUtility.builtinMaterial, (int)FilterUtility.BuiltinPasses.Clamp);
        }
        protected override void OnEval(FilterContext fc, RenderTexture sourceRenderTexture, RenderTexture destinationRenderTexture)
        {
            if (m_noiseSettings == null)
            {
                m_noiseSettings = ScriptableObject.CreateInstance <NoiseSettings>();
            }

            m_noiseSettings.useTextureForPositions = m_useHeightmap;

            if (m_useHeightmap)
            {
                m_noiseSettings.positionTexture = fc.rtHandleCollection[FilterContext.Keywords.Heightmap];
            }

            Vector3 brushPosWS = fc.brushPos - m_lastBrushPosition;

            brushPosWS.y        = 0;
            m_lastBrushPosition = fc.brushPos;
            float brushSize     = fc.brushSize;
            float brushRotation = fc.brushRotation - m_lastRotation;

            m_lastRotation = fc.brushRotation;
            // TODO(wyatt): remove magic number and tie it into NoiseSettingsGUI preview size somehow
            float previewSize = 1 / 512f;

            // get proper noise material from current noise settings
            NoiseSettings noiseSettings = m_noiseSettings;
            Material      mat           = NoiseUtils.GetDefaultBlitMaterial(noiseSettings);

            // setup the noise material with values in noise settings
            noiseSettings.SetupMaterial(mat);

            // change pos and scale so they match the noiseSettings preview
            bool isWorldSpace = false == m_isLocalSpace;

            brushSize  = isWorldSpace ? brushSize * previewSize : 1;
            brushPosWS = isWorldSpace ? brushPosWS * previewSize : Vector3.zero;

            // compensate for the difference between the size of the rotated brush and the square noise RT
            var brushTransform  = GetBrushTransform(fc);
            var scaleMultiplier = new Vector2(
                1.0f / (fc.brushSize / brushTransform.GetBrushXYBounds().width),
                1.0f / (fc.brushSize / brushTransform.GetBrushXYBounds().height));

            Quaternion rotQ = Quaternion.AngleAxis(-brushRotation, Vector3.up);

            // accumulate transformation delta
            m_noiseToWorld *= Matrix4x4.TRS(brushPosWS, rotQ, Vector3.one);

            mat.SetMatrix(NoiseSettings.ShaderStrings.transform, noiseSettings.trs * m_noiseToWorld * Matrix4x4.Scale(new Vector3(scaleMultiplier.x, 1.0f, scaleMultiplier.y) * brushSize));

            int pass = NoiseUtils.kNumBlitPasses * NoiseLib.GetNoiseIndex(noiseSettings.domainSettings.noiseTypeName);

            var desc = destinationRenderTexture.descriptor;

            desc.graphicsFormat = NoiseUtils.singleChannelFormat;
            desc.sRGB           = false;
            RTHandle rt = RTUtils.GetTempHandle(desc);

            Graphics.Blit(sourceRenderTexture, rt, mat, pass);

            Material blendMat = FilterUtility.blendModesMaterial;

            blendMat.SetTexture("_BlendTex", rt);
            Graphics.Blit(sourceRenderTexture, destinationRenderTexture, blendMat, 1);
            RTUtils.Release(rt);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Draw the GUI for the Filter
 /// </summary>
 /// <param name="rect">The Rect where the GUI should be drawn</param>
 /// <param name="filterContext">The FilterContext related to the current evaluation. Use this to show different information in the Filter GUI</param>
 protected virtual void OnDrawGUI(Rect rect, FilterContext filterContext)
 {
 }