Inheritance: Myre.Entities.Services.Service
Beispiel #1
0
        protected override void BeginTransitionOn()
        {
            _scene = new TestScene(_kernel, _kernel.Get<Game>(), _kernel.Get<ContentManager>(), _kernel.Get<GraphicsDevice>(), new TestScene.SceneConfiguration()
            {
                View = false
            });

            _renderer = _scene.Scene.GetService<Renderer>();
            _renderer.StartPlan()
                    .Then<GeometryBufferComponent>()
                    .Then<EdgeDetectComponent>()
                    .Then<Ssao>()
                    .Then<LightingComponent>()
                    .Then<RestoreDepthPhase>()
                    .Then<TranslucentComponent>()
                    .Then<ToneMapComponent>()
                    .Then<AntiAliasComponent>()
                    .Apply();

            var w = _renderer.Device.Viewport.Width / 2;
            var h = _renderer.Device.Viewport.Height / 2;
            AddCamera("gbuffer_depth", new Viewport { X = 0, Y = 0, Width = w, Height = h });
            AddCamera("gbuffer_normals", new Viewport { X = w, Y = 0, Width = w, Height = h });
            AddCamera("gbuffer_diffuse", new Viewport { X = 0, Y = h, Width = w, Height = h });
            AddCamera("lightbuffer", new Viewport { X = w, Y = h, Width = w, Height = h });

            base.OnShown();
        }
Beispiel #2
0
        public override void Initialise(Renderer renderer, ResourceContext context)
        {            
            // define outputs
            context.DefineOutput(_name, true, null, _targetInfo);

            base.Initialise(renderer, context);
        }
Beispiel #3
0
        protected override void BeginTransitionOn()
        {
            _scene = _kernel.Get<TestScene>();

            _renderer = _scene.Scene.GetService<Renderer>();

            _fullPlan = _renderer.StartPlan()
                               .Then<GeometryBufferComponent>()
                               .Then<EdgeDetectComponent>()
                               .Then<Ssao>()
                               .Then<LightingComponent>()
                               .Then<RestoreDepthPhase>()
                               .Then<TranslucentComponent>()
                               .Then<ToneMapComponent>()
                               .Then<AntiAliasComponent>()
                               .Show("antialiased");

            _noAaPlan = _renderer.StartPlan()
                               .Then<GeometryBufferComponent>()
                               .Then<EdgeDetectComponent>()
                               .Then<Ssao>()
                               .Then<LightingComponent>()
                               .Then<RestoreDepthPhase>()
                               .Then<TranslucentComponent>()
                               .Then<ToneMapComponent>()
                               .Show("tonemapped");

            base.OnShown();
        }
Beispiel #4
0
        public override void End(Renderer renderer)
        {
            base.End(renderer);

            //Restore previous plan
            if (_previousPlan != null)
                _previousPlan.Apply();
            _previousPlan = null;
        }
Beispiel #5
0
        public override void Initialise(Renderer renderer, ResourceContext context)
        {
            // define input
            context.DefineInput("scene");

            // define output
            context.DefineOutput("scene");

            base.Initialise(renderer, context);
        }
Beispiel #6
0
        public override void Draw(Renderer renderer)
        {
            var resolution = renderer.Data.Get<Vector2>("resolution").Value;
            var targetInfo = new RenderTargetInfo((int) resolution.X, (int) resolution.Y, SurfaceFormat.Color, DepthFormat.None, 4, default(bool), default(RenderTargetUsage));

            var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
            renderer.Device.SetRenderTarget(target);
            renderer.Device.Clear(Colour);

            Output("scene", target);
        }
Beispiel #7
0
        public override void Initialise(Renderer renderer, ResourceContext context)
        {
            foreach (var resource in context.SetRenderTargets)
            {
                context.DefineInput(resource.Name);
                context.DefineOutput(resource);
            }

            renderables = renderer.Scene.FindManagers<IRenderable>();
            base.Initialise(renderer, context);
        }
Beispiel #8
0
        public override void Draw(Renderer renderer)
        {
            var resolution = renderer.Data.Get<Vector2>("resolution").Value;
            var targetInfo = new RenderTargetInfo()
            {
                Width = (int)resolution.X,
                Height = (int)resolution.Y,
                SurfaceFormat = SurfaceFormat.Color,
                DepthFormat = DepthFormat.None,
                MultiSampleCount = 4
            };

            var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
            renderer.Device.SetRenderTarget(target);
            renderer.Device.Clear(Colour);

            Output("scene", target);
        }
Beispiel #9
0
        public override void Begin(Renderer renderer)
        {
            base.Begin(renderer);

            //Get or create a plan for this renderer
            RenderPlan plan;
            if (!_plans.TryGetValue(renderer, out plan))
            {
                plan = CreatePlan(renderer);
                _plans[renderer] = plan;
            }

            //Cache plan which is already applied
            _previousPlan = renderer.Plan;

            //If a null plan is returned use the default renderer plan
            if (plan == null)
                return;

            //Apply new plan
            plan.Apply();
        }
Beispiel #10
0
        public override void Draw(Renderer renderer)
        {
            var info = _targetInfo;
            if (info.Width == 0 || info.Height == 0)
            {
                var resolution = renderer.Data.GetValue(new TypedName<Vector2>("resolution"));
                info = new RenderTargetInfo(
                    (int) resolution.X,
                    (int) resolution.Y,
                    info.SurfaceFormat,
                    info.DepthFormat,
                    info.MultiSampleCount,
                    info.MipMap,
                    info.Usage
                );
            }

            var target = RenderTargetManager.GetTarget(renderer.Device, info);
            renderer.Device.SetRenderTarget(target);
            renderer.Device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.Black, 1, 0);

            Output(_name, target);
        }
Beispiel #11
0
 protected override RenderPlan CreatePlan(Renderer renderer)
 {
     return renderer.Plan.Clone()
         .Show(_output);
 }
Beispiel #12
0
 public override void Draw(Renderer renderer)
 {
     foreach (var item in renderables)
         item.Draw(renderer);
 }
Beispiel #13
0
            //protected override void SpecifyResources(IList<Input> inputs, IList<RendererComponent.Resource> outputs, out RenderTargetInfo? outputTarget)
            //{
            //    inputs.Add(new Input() { Name = "gbuffer_depth" });
            //    inputs.Add(new Input() { Name = "gbuffer_depth_downsample" });
            //    inputs.Add(new Input() { Name = "gbuffer_normals" });
            //    inputs.Add(new Input() { Name = "gbuffer_diffuse" });
            //    outputs.Add(new Resource() { Name = "scene", IsLeftSet = true });
            //    outputTarget = new RenderTargetInfo();
            //}
            //protected override bool ValidateInput(RenderTargetInfo? previousRenderTarget)
            //{
            //    return true;
            //}
            public override void Initialise(Renderer renderer, ResourceContext context)
            {
                // define inputs
                context.DefineInput("gbuffer_depth");
                context.DefineInput("gbuffer_depth_downsample");
                context.DefineInput("gbuffer_normals");
                context.DefineInput("gbuffer_diffuse");

                // define outputs
                context.DefineOutput("scene");

                base.Initialise(renderer, context);
            }
Beispiel #14
0
            public override void Draw(Renderer renderer)
            {
                var metadata = renderer.Data;
                var resolution = metadata.GetOrCreate<Vector2>(Names.View.Resolution).Value;
                var targetInfo = new RenderTargetInfo((int) resolution.X, (int) resolution.Y, default(SurfaceFormat), default(DepthFormat), default(int), default(bool), default(RenderTargetUsage));
                var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
                renderer.Device.SetRenderTarget(target);

                var depth = metadata.GetValue<Texture2D>(Names.Deferred.Textures.Depth);
                var normals = metadata.GetValue<Texture2D>(Names.Deferred.Textures.Normals);
                var diffuse = metadata.GetValue<Texture2D>(Names.Deferred.Textures.Diffuse);

                //Save(depth, "depth.jpg");
                //Save(normals, "normal.jpg");
                //Save(diffuse, "diffuse.jpg");

                var halfWidth = (int)(resolution.X / 2);
                var halfHeight = (int)(resolution.Y / 2);

                _batch.GraphicsDevice.Clear(Color.Black);
                _batch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);

                _batch.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                _batch.Draw(depth, new Rectangle(0, 0, halfWidth, halfHeight), Color.White);
                _batch.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

                _batch.Draw(normals, new Rectangle(halfWidth, 0, halfWidth, halfHeight), Color.White);
                _batch.Draw(diffuse, new Rectangle(0, halfHeight, halfWidth, halfHeight), Color.White);
                _batch.End();

                Output("scene", target);
            }
            public override void Draw(Renderer renderer)
            {
                var target = RenderTargetManager.GetTarget(renderer.Device, 1280, 720);
                renderer.Device.SetRenderTarget(target);

                var metadata = renderer.Data;
                var c = metadata.Get<Texture2D>("c").Value;

                spriteBatch.Begin();
                spriteBatch.Draw(c, new Rectangle(590, 335, 100, 50), Color.White);
                spriteBatch.End();

                Output("d", target);
            }
            public override void Draw(Renderer renderer)
            {
                var target = RenderTargetManager.GetTarget(renderer.Device, new RenderTargetInfo(50, 50, default(SurfaceFormat), default(DepthFormat), default(int), default(bool), default(RenderTargetUsage)));
                renderer.Device.SetRenderTarget(target);
                renderer.Device.Clear(Color.White);
                spriteBatch.Begin();
                spriteBatch.DrawString(font, "A", Vector2.Zero, Color.Black);
                spriteBatch.End();

                Output("a", target);
            }
Beispiel #17
0
            //protected override void SpecifyResources(IList<Input> inputs, IList<RendererComponent.Resource> outputs, out RenderTargetInfo? outputTarget)
            //{
            //    inputs.Add(new Input() { Name = "tonemapped" });
            //    inputs.Add(new Input() { Name = "luminancemap" });
            //    outputs.Add(new Resource() { Name = "scene", IsLeftSet = true });
            //    outputTarget = new RenderTargetInfo() { SurfaceFormat = SurfaceFormat.Rgba64, DepthFormat = DepthFormat.Depth24Stencil8 };
            //}
            //protected override bool ValidateInput(RenderTargetInfo? previousRenderTarget)
            //{
            //    return true;
            //}
            public override void Initialise(Renderer renderer, ResourceContext context)
            {
                // define inputs
                context.DefineInput("tonemapped");
                //context.DefineInput("luminancemap");

                // define outputs
                context.DefineOutput("scene", surfaceFormat: SurfaceFormat.Rgba64, depthFormat: DepthFormat.Depth24Stencil8);

                base.Initialise(renderer, context);
            }
Beispiel #18
0
 /// <summary>
 /// Draws this component.
 /// </summary>
 /// <param name="renderer">The renderer</param>
 public abstract void Draw(Renderer renderer);
Beispiel #19
0
 protected abstract RenderPlan CreatePlan(Renderer renderer);
Beispiel #20
0
            public override void Draw(Renderer renderer)
            {
                var metadata = renderer.Data;
                var resolution = renderer.Data.Get<Vector2>("resolution").Value;
                var targetInfo = new RenderTargetInfo((int)resolution.X, (int)resolution.Y, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8, default(int), default(bool), default(RenderTargetUsage));
                var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
                renderer.Device.SetRenderTarget(target);

                var light = metadata.Get<Texture2D>("tonemapped").Value;
                var luminance = metadata.Get<Texture2D>("luminancemap").Value;

                //using (var stream = File.Create("luminance.jpg"))
                //    light.SaveAsJpeg(stream, light.Width, light.Height);

                var width = (int)resolution.X;
                var height = (int)resolution.Y;

                batch.GraphicsDevice.Clear(Color.Black);
                batch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);

                if (drawScene)
                {
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                    batch.Draw(light, new Rectangle(0, 0, width, height), Color.White);
                    //batch.Draw(luminance, new Rectangle(50, height - (height / 5) - 50, height / 5, height / 5), Color.White);
                    //batch.Draw(toneMap.AdaptedLuminance, new Rectangle(50 + 20 + (height / 5), height - (height / 5) - 50, height / 5, height / 5), Color.White);
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                }
                else
                {
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                    batch.Draw(luminance, new Rectangle(0, 0, width, height), Color.White);
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                }

                batch.End();

                Output("scene", target);
            }
Beispiel #21
0
            public override void Draw(Renderer renderer)
            {
                var resolution = renderer.Data.Get<Vector2>("resolution").Value;
                var targetInfo = new RenderTargetInfo((int) resolution.X, (int) resolution.Y, default(SurfaceFormat), default(DepthFormat), default(int), default(bool), default(RenderTargetUsage));
                var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
                renderer.Device.SetRenderTarget(target);

                _batch.Begin();
                _batch.DrawString(Font, "This is being drawn by a RenderPhase!", new Vector2(640, 360).ToXNA(), Color.White);
                _batch.End();

                Output("scene", target);
            }
            public override void Draw(Renderer renderer)
            {
                var target = RenderTargetManager.GetTarget(renderer.Device, new RenderTargetInfo() { Height = 50, Width = 50 });
                renderer.Device.SetRenderTarget(target);
                renderer.Device.Clear(Color.White);
                spriteBatch.Begin();
                spriteBatch.DrawString(font, "A", Vector2.Zero, Color.Black);
                spriteBatch.End();

                Output("a", target);
            }
Beispiel #23
0
 /// <summary>
 /// Initialised this renderer component.
 /// </summary>
 /// <remarks>
 /// Here, components may validate that required inputs are available, and
 /// define their output.
 /// </remarks>
 /// <param name="renderer">The renderer.</param>
 /// <param name="context">The resource context containing environment information and providing means to define inputs and outputs.</param>
 public virtual void Initialise(Renderer renderer, ResourceContext context)
 {
     Initialised = true;
 }
Beispiel #24
0
            public override void Draw(Renderer renderer)
            {
                KeyboardState keyboard = Keyboard.GetState();
                if (keyboard.IsKeyDown(Keys.Space) && previousKeyboard.IsKeyUp(Keys.Space))
                    drawGBuffer = !drawGBuffer;
                previousKeyboard = keyboard;

                var metadata = renderer.Data;
                var resolution = renderer.Data.Get<Vector2>("resolution").Value;
                var targetInfo = new RenderTargetInfo((int)resolution.X, (int)resolution.Y, SurfaceFormat.Rgba64, default(DepthFormat), default(int), default(bool), default(RenderTargetUsage));
                var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
                renderer.Device.SetRenderTarget(target);

                var depth = metadata.Get<Texture2D>("gbuffer_depth").Value;
                var normals = metadata.Get<Texture2D>("gbuffer_normals").Value;
                var diffuse = metadata.Get<Texture2D>("gbuffer_diffuse").Value;
                var light = metadata.Get<Texture2D>("lightbuffer").Value;

                //using (var stream = File.Create("lightbuffer.jpg"))
                //    light.SaveAsJpeg(stream, light.Width, light.Height);

                var halfWidth = (int)(resolution.X / 2);
                var halfHeight = (int)(resolution.Y / 2);

                batch.GraphicsDevice.Clear(Color.Black);
                batch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);

                if (drawGBuffer)
                {
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                    batch.Draw(depth, new Rectangle(0, 0, halfWidth, halfHeight), Color.White);
                    batch.Draw(light, new Rectangle(halfWidth, halfHeight, halfWidth, halfHeight), Color.White);
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

                    batch.Draw(normals, new Rectangle(halfWidth, 0, halfWidth, halfHeight), Color.White);
                    batch.Draw(diffuse, new Rectangle(0, halfHeight, halfWidth, halfHeight), Color.White);
                }
                else
                {
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                    batch.Draw(light, new Rectangle(0, 0, (int)resolution.X, (int)resolution.Y), Color.White);
                    batch.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                }

                batch.End();

                Output("scene", target);
            }
            public override void Draw(Renderer renderer)
            {
                var target = RenderTargetManager.GetTarget(renderer.Device, 50, 100);
                renderer.Device.SetRenderTarget(target);

                var metadata = renderer.Data;
                var a = metadata.Get<Texture2D>("a").Value;
                var b = metadata.Get<Texture2D>("b").Value;

                spriteBatch.Begin();
                spriteBatch.Draw(a, new Rectangle(0, 0, 50, 50), Color.White);
                spriteBatch.Draw(b, new Rectangle(50, 0, 50, 50), Color.White);
                spriteBatch.End();

                Output("c", target);
            }
Beispiel #26
0
            public override void Draw(Renderer renderer)
            {
                var resolution = renderer.Data.Get<Vector2>("resolution").Value;
                var targetInfo = new RenderTargetInfo() { Width = (int)resolution.X, Height = (int)resolution.Y };
                var target = RenderTargetManager.GetTarget(renderer.Device, targetInfo);
                renderer.Device.SetRenderTarget(target);

                batch.Begin();
                batch.DrawString(Font, "This is being drawn by a RenderPhase!", new Vector2(640, 360), Color.White);
                batch.End();

                Output("scene", target);
            }
Beispiel #27
0
 public void Finalise(Renderer renderer, RenderTarget2D target)
 {
     Finaliser(renderer, target);
 }