public void AutomaticShadowMapping()
        {
            SceneTests.InitializeScene();
            var content = ImportContent();

            content.OnSceneAttach(SceneManager.Scene);

            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\nissan2.DAE");
            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\talia.DAE");

            if (SceneManager.Scene.Physics != null)
            {
                SceneManager.Scene.Physics.Enable = true;
            }

            if (SceneManager.Scene.Lights.Count == 0)
            {
                var light = new Light()
                {
                    Diffuse  = new Vector3(1, 1, 1),
                    Specular = new Vector3(1, 1, 1),
                    Type     = LightType.Directional,
                    Enable   = true
                };

                SceneManager.Scene.Create("DirectionalLight0", new FrameLight(light),
                                          localRotationEuler: new Euler(0, Numerics.ToRadians(70), 0));
            }
            FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
            _technique    = SceneManager.Scene.Lights.Where(x => x.Node.Technique is ShadowMapTechnique).Select(x => (ShadowMapTechnique)x.Node.Technique).FirstOrDefault();
            _targetCamera = _technique.Camera;

            _technique.Bias = 0.9e-2f;

            SceneManager.Scene.AmbientLight.GroundColor = new Vector3(0, 0, 0);
            SceneManager.Scene.AmbientLight.SkyColor    = new Vector3(0.2f, 0.2f, 0.2f);

            Engine.Presenter.Rendering += Presenter_Rendering;
            SceneManager.Scene.Dynamics.Add(new Dynamic(x =>
            {
                if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D1))
                {
                    _technique.KernelSize = 3;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D2))
                {
                    _technique.KernelSize = 5;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D3))
                {
                    _technique.KernelSize = 7;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D4))
                {
                    _technique.KernelSize = 1;
                }
            }));
        }
        public void CreateThirdPersonController()
        {
            const float startTimeWalk = 34f / 30f;
            const float endTimeWalk   = 63f / 30f;
            const float durationWalk  = endTimeWalk - startTimeWalk;
            const float startTimeIdle = 0;
            const float endTimeIdle   = 0;
            const float durationIdle  = endTimeIdle;
            const float blendDuration = 0.25f;

            const float startTimeRun = 15f / 30f;
            const float endRunTime   = 80f / 30f;
            const float durationRun  = endRunTime - startTimeRun;

            SceneTests.InitializeScene();
            SceneManager.Scene.Physics.Enable  = true;
            SceneManager.Scene.Physics.Visible = false;

            CharacterControllerTagProcessor.ControllerCreated += CharacterControllerTagProcessor_ControllerCreated;

            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\game_level0\game_level0.DAE");
            ContentImporter.ImportAnimation(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\walk.DAE");
            ContentImporter.ImportAnimation(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\run.DAE");

            CharacterController controller = CharacterControllerManager.Instance.Controllers[0];
            var animationWalk = SceneManager.Scene.AnimManager.Animations[1];
            var animationRun  = SceneManager.Scene.AnimManager.Animations[2];

            var character = (((Frame)controller.Affectable)).FindNode((Frame x) => x.Type == FrameType.Bone);

            SceneManager.Scene.FindNode("camera1").BindTo(character);

            ThirdPersonControllerDesc desc = new ThirdPersonControllerDesc
            {
                CollitionController = controller,
                Character           = character,
                CameraMaxDistance   = 100,
                CameraMinDistance   = 20,
                CameraMaxPich       = Numerics.ToRadians(45),
                CameraMinPich       = Numerics.ToRadians(25),
                TransitionTime      = blendDuration,
                Camera = SceneManager.Scene.FindNode("camera1"),
                Idle   = new KeyFrameAnimationPlayback(animationWalk, startTimeIdle, durationIdle, AnimationLooping.Loop),
                Walk   = new KeyFrameAnimationPlayback(animationWalk, startTimeWalk, durationWalk, AnimationLooping.Loop, velocity: 1),
                //Walk = new AnimationPlayback(animationRun, startTimeRun, durationRun, AnimationLooping.Secuential),
            };
            ThirdPersonController characterController = new ThirdPersonController(desc);

            SceneManager.Scene.Dynamics.Add(characterController);

            //EngineState.Shadow.ShadowMapping.Bias = 0.9e-2f;
            FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
        }
        private void CreateLight()
        {
            //Create a light ,the light containg properties like colors and specular powers
            var light = new Light("WhiteLight")
            {
                Diffuse   = new Color3(1, 1, 1),
                Specular  = new Color3(0, 0, 0),
                SpotPower = 8,
                Enable    = true
            };

            //Assign the light to a FrameLight wich acts like and adapter for the scene node
            //so it will set light spatial properties like direccion and position when the scene node change its pose.
            var lightFrame = new FrameLight(light);

            Engine.Scene.Create("LightNode", lightFrame, new Vector3(0, 50, 0), new Euler(0, 60, 0));
        }
        private void CreateLights()
        {
            _lights = new Frame[6];
            Random ran = new Random();

            Color3[] colors = new Color3[8]
            {
                new Color3(Color.Yellow.ToArgb()), new Color3(Color.Red.ToArgb()), new Color3(Color.Green.ToArgb()), new Color3(Color.LightCoral.ToArgb()),
                new Color3(Color.DarkBlue.ToArgb()), new Color3(Color.Gray.ToArgb()), new Color3(Color.IndianRed.ToArgb()), new Color3(Color.LightSalmon.ToArgb())
            };

            float     step      = Numerics.TwoPI / _lights.Length;
            Spherical spherical = new Spherical(Numerics.PIover2, 0);

            for (int i = 0; i < _lights.Length; i++)
            {
                var light = new Light()
                {
                    Diffuse = colors[i % 8],
                    //Diffuse = new Vector3((float)ran.NextDouble(),(float)ran.NextDouble(),(float)ran.NextDouble()),
                    Specular = new Vector3(0.2f, 0.2f, 0.2f),
                    Type     = LightType.Point,
                    Enable   = true
                };
                spherical.Phi = step * i;
                var pos = spherical.ToCartesian() * 300;
                pos.Y = 50;

                var instance = new FrameLight(light);
                var node     = SceneManager.Scene.Create("light" + i, instance,
                                                         localPosition: pos,
                                                         localRotationEuler: Euler.FromDirection(new Vector3(0, -1, 0)),
                                                         localScale: new Vector3(1, 1, 1));
                SceneManager.Scene.Dynamics.Add(new Dynamic(x =>
                {
                    Frame n         = node;
                    n.LocalPosition = Vector3.TransformCoordinates(n.LocalPosition,
                                                                   Matrix.RotationY(Numerics.ToRadians(1)));
                    n.ComputeLocalPose();
                    n.CommitChanges();
                }));
                _lights[i] = node;
            }
        }
        public void Import()
        {
            SceneTests.InitializeScene();

            //RenderManager.PushTechnique<DefferedLigthing<DefferedLightingEffect>>();
            //EngineState.Shadow.Enable = true;
            //EngineState.Shadow.ShadowMapping.Enable = true;
            //Deffered.DrawGBuffers<DefferedShadowRender>();

            // var content = ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\shadowScene.DAE");
            var content = ImportContent();

            if (content == null)
            {
                return;
            }

            if (SceneManager.Scene.Physics != null)
            {
                SceneManager.Scene.Physics.Enable = true;
            }

            if (SceneManager.Scene.Lights.Count == 0)
            {
                var light = new Light()
                {
                    Diffuse  = new Vector3(1, 1, 1),
                    Specular = new Vector3(1, 1, 1),
                    Type     = LightType.Directional,
                    Enable   = true
                };

                SceneManager.Scene.Create("DirectionalLight0", new FrameLight(light),
                                          localRotationEuler: new Euler(0, Numerics.ToRadians(70), 0));

                FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
            }
            _technique = SceneManager.Scene.Lights.Where(x => x.Node.Technique is ShadowMapTechnique).Select(x => (ShadowMapTechnique)x.Node.Technique).FirstOrDefault();
            if (_technique == null)
            {
                FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
                _technique = SceneManager.Scene.Lights.Where(x => x.Node.Technique is ShadowMapTechnique).Select(x => (ShadowMapTechnique)x.Node.Technique).FirstOrDefault();
            }
            _targetCamera         = _technique.Camera;
            _technique.KernelSize = 3;
            //targetCamera.ZNear = 1;
            //targetCamera.ZFar = 1000;
            //targetCamera.AspectRatio = 1;
            //targetCamera.FieldOfView = Numerics.PIover6;
            //targetCamera.Type = ProjectionType.Perspective;
            //targetCamera.CommitChanges();
            _technique.Bias = 0.9e-2f;

            SceneManager.Scene.AmbientLight.GroundColor = new Vector3(0, 0, 0);
            SceneManager.Scene.AmbientLight.SkyColor    = new Vector3(0.2f, 0.2f, 0.2f);
            //EngineState.Lighting.Reflection.UseDefaultTechnique = true;

            Engine.Presenter.Rendering += Presenter_Rendering;
            SceneManager.Scene.Dynamics.Add(new Dynamic(x =>
            {
                if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D1))
                {
                    _technique.KernelSize = 3;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D2))
                {
                    _technique.KernelSize = 5;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D3))
                {
                    _technique.KernelSize = 7;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Igneel.Input.Keys.D4))
                {
                    _technique.KernelSize = 1;
                }
            }));
            //    }
            //}
        }
        public void EdgeFiltering()
        {
            SceneTests.InitializeScene();

            //var content = ImportContent();
            var content = ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\shadowScene.DAE");

            EngineState.Shadow.ShadowMapping.PcfBlurSize = 5;
            content.OnSceneAttach(SceneManager.Scene);

            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\nissan2.DAE");
            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\talia.DAE");

            if (SceneManager.Scene.Physics != null)
            {
                SceneManager.Scene.Physics.Enable = true;
            }

            //if (SceneManager.Scene.Lights.Count == 0)
            //{
            //    var light = new Light()
            //    {
            //        Diffuse = new Vector3(1, 1, 1),
            //        Specular = new Vector3(1, 1, 1),
            //        Type = LightType.Directional,
            //        Enable = true
            //    };

            //    SceneManager.Scene.Create("DirectionalLight0", new LightInstance(light),
            //        localRotationEuler: new Euler(0, Numerics.ToRadians(70), 0));
            //}
            FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
            _technique    = SceneManager.Scene.Lights.Where(x => x.Node.Technique is ShadowMapTechnique).Select(x => (ShadowMapTechnique)x.Node.Technique).FirstOrDefault();
            _targetCamera = _technique.Camera;

            _technique.Bias = 0.9e-2f;

            SceneManager.Scene.AmbientLight.GroundColor = new Vector3(0, 0, 0);
            SceneManager.Scene.AmbientLight.SkyColor    = new Vector3(0.2f, 0.2f, 0.2f);

            EngineState.Shadow.ShadowMapping.PcfBlurSize = 3;
            var edgeTechnique = new EdgeShadowFilteringTechnique();

            RenderManager.PushTechnique(edgeTechnique);
            bool debug = true;

            if (debug)
            {
                Form form = new Form();
                form.BackColor     = Color.Blue;
                form.StartPosition = FormStartPosition.CenterScreen;
                form.Size          = new System.Drawing.Size(edgeTechnique.ShadowFactorTex.Width, edgeTechnique.ShadowFactorTex.Height);

                form.SuspendLayout();

                Canvas3D canvas = new Canvas3D()
                {
                    Width  = form.Width,
                    Height = form.Height
                };
                canvas.Dock = DockStyle.Fill;
                var presenter = canvas.CreateSwapChainPresenter();
                form.Controls.Add(canvas);
                form.ResumeLayout();

                Engine.RenderFrame += () =>
                {
                    presenter.Begin(new Color4(Color.Aqua.ToArgb()));

                    var device = GraphicDeviceFactory.Device;
                    device.Ps.SamplerStacks[0].Push(SamplerState.Linear);
                    device.Blend = SceneTechnique.NoBlend;

                    var texture = edgeTechnique.EdgeSrcTexture;
                    RenderTexture(device, texture, width: texture.Width, height: texture.Height);

                    device.Ps.SamplerStacks[0].Pop();

                    presenter.End();
                };

                form.Show();
            }
        }