Esempio n. 1
0
        /// <inheritdoc />
        public override void Render(GPUContext context, SceneRenderTask task, RenderTarget input, RenderTarget output)
        {
            // Pick a temporary depth buffer
            var customDepth = RenderTarget.GetTemporary(PixelFormat.R32_Typeless, input.Width, input.Height, TextureFlags.DepthStencil | TextureFlags.ShaderResource);

            context.ClearDepth(customDepth);

            // Render selected objects depth
            var actors = Editor.Instance.SceneEditing.Selection.ConvertAll(x => (x as ActorNode)?.Actor).ToArray();

            context.DrawSceneDepth(task, customDepth, true, actors, ActorsSources.CustomActors);

            var near       = task.View.Near;
            var far        = task.View.Far;
            var projection = task.View.Projection;

            // Render outline
            _material.GetParam("OutlineColor0").Value = OutlineColor0;
            _material.GetParam("OutlineColor1").Value = OutlineColor1;
            _material.GetParam("CustomDepth").Value   = customDepth;
            _material.GetParam("ViewInfo").Value      = new Vector4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), (-far * near) / (far - near) / far);
            context.DrawPostFxMaterial(_material, output, input, task);

            // Cleanup
            RenderTarget.ReleaseTemporary(customDepth);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void Render(GPUContext context, SceneRenderTask task, RenderTarget input, RenderTarget output)
        {
            Profiler.BeginEventGPU("Selection Outline");

            // Pick a temporary depth buffer
            var customDepth = RenderTarget.GetTemporary(PixelFormat.R32_Typeless, input.Width, input.Height, TextureFlags.DepthStencil | TextureFlags.ShaderResource);

            context.ClearDepth(customDepth);

            // Get selected actors
            var selection = SelectionGetter();

            if (_actors == null)
            {
                _actors = new List <Actor>();
            }
            else
            {
                _actors.Clear();
            }
            _actors.Capacity = Mathf.NextPowerOfTwo(Mathf.Max(_actors.Capacity, selection.Count));
            for (int i = 0; i < selection.Count; i++)
            {
                if (selection[i] is ActorNode actorNode)
                {
                    _actors.Add(actorNode.Actor);
                }
            }

            // Render selected objects depth
            context.DrawSceneDepth(task, customDepth, true, _actors, ActorsSources.CustomActors);

            _actors.Clear();

            var near       = task.View.Near;
            var far        = task.View.Far;
            var projection = task.View.Projection;

            // Render outline
            _material.GetParam("OutlineColor0").Value = _color0;
            _material.GetParam("OutlineColor1").Value = _color1;
            _material.GetParam("CustomDepth").Value   = customDepth;
            _material.GetParam("ViewInfo").Value      = new Vector4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), (-far * near) / (far - near) / far);
            context.DrawPostFxMaterial(_material, output, input, task);

            // Cleanup
            RenderTarget.ReleaseTemporary(customDepth);

            Profiler.EndEventGPU();
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the brush material for the terrain chunk rendering. It must have domain set to Terrain. Setup material parameters within this call.
        /// </summary>
        /// <param name="position">The world-space brush position.</param>
        /// <param name="color">The brush position.</param>
        /// <param name="sceneDepth">The scene depth buffer (used for manual brush pixels clipping with rendered scene).</param>
        /// <returns>The ready to render material for terrain chunks overlay on top of the terrain.</returns>
        public MaterialInstance GetBrushMaterial(ref Vector3 position, ref Color color, GPUTexture sceneDepth)
        {
            if (!_material)
            {
                var material = FlaxEngine.Content.LoadAsyncInternal <Material>(EditorAssets.FoliageBrushMaterial);
                material.WaitForLoaded();
                _material = material.CreateVirtualInstance();
            }

            if (_material)
            {
                // TODO: cache parameters
                _material.GetParam("Color").Value       = color;
                _material.GetParam("DepthBuffer").Value = sceneDepth;
            }

            return(_material);
        }
Esempio n. 4
0
            public static void OnEditorOptionsChanged(Options.EditorOptions options)
            {
                var param = _highlightMaterial?.GetParam("Color");

                if (param != null)
                {
                    param.Value = options.Visual.HighlightColor;
                }
            }
 private void Start()
 {
     if (Material)
     {
         _materialInstance = Material.CreateVirtualInstance();
         _materialInstance.GetParam(ParamName).Value = new Color(_rng.NextFloat(), _rng.NextFloat(), _rng.NextFloat());
         if (Actor is StaticModel modelActor)
         {
             modelActor.Entries[0].Material = _materialInstance;
         }
     }
 }
Esempio n. 6
0
        /// <inheritdoc />
        public override void Render(GPUContext context, SceneRenderTask task, RenderTarget input, RenderTarget output)
        {
            Profiler.BeginEventGPU("Selection Outline");

            // Pick a temporary depth buffer
            var customDepth = RenderTarget.GetTemporary(PixelFormat.R32_Typeless, input.Width, input.Height, TextureFlags.DepthStencil | TextureFlags.ShaderResource);

            context.ClearDepth(customDepth);

            // Draw objects to depth buffer
            if (_actors == null)
            {
                _actors = new List <Actor>();
            }
            else
            {
                _actors.Clear();
            }
            DrawSelectionDepth(context, task, customDepth);
            _actors.Clear();

            var near       = task.View.Near;
            var far        = task.View.Far;
            var projection = task.View.Projection;

            // Render outline
            _material.GetParam("OutlineColor0").Value = _color0;
            _material.GetParam("OutlineColor1").Value = _color1;
            _material.GetParam("CustomDepth").Value   = customDepth;
            _material.GetParam("ViewInfo").Value      = new Vector4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), (-far * near) / (far - near) / far);
            context.DrawPostFxMaterial(_material, output, input, task);

            // Cleanup
            RenderTarget.ReleaseTemporary(customDepth);

            Profiler.EndEventGPU();
        }
Esempio n. 7
0
        private void OnEnable()
        {
            // Create backbuffer
            if (_output == null)
            {
                _output = RenderTarget.New();
            }
            _output.Init(PixelFormat.R8G8B8A8_UNorm, (int)_resolution.X, (int)_resolution.Y);

            // Create rendering task
            if (_task == null)
            {
                _task = RenderTask.Create <SceneRenderTask>();
            }
            _task.Order   = -100;
            _task.Camera  = Cam;
            _task.Output  = _output;
            _task.Enabled = false;

            if (Material && _material == null)
            {
                // Use dynamic material instance
                if (Material.WaitForLoaded())
                {
                    throw new Exception("Failed to load material.");
                }
                _material = Material.CreateVirtualInstance();

                // Set render task output to draw on model
                _material.GetParam("Image").Value = _output;

                // Bind material to parent model
                if (Actor is StaticModel staticModel && staticModel.Model)
                {
                    staticModel.Model.WaitForLoaded();
                    staticModel.Entries[0].Material = _material;
                }
            }

            _task.Enabled = true;
        }
Esempio n. 8
0
        private void Update()
        {
            task.Enabled = true;

            if (setMaterial)
            {
                setMaterial = false;

                if (material)
                {
                    material.GetParam("Image").Value = output;
                }

                if (Actor is ModelActor)
                {
                    var modelActor = (ModelActor)Actor;
                    if (modelActor.HasContentLoaded)
                    {
                        modelActor.Entries[0].Material = material;
                    }
                }
            }
        }