protected override void BeginTransitionOn()
        {
            _material = new Material(_content.Load<Effect>("Basic"), null);
            _quad = new Quad(_device);
            _metadata = new NamedBoxCollection();

            _metadata.Set(new TypedName<Vector4>("colour"), Color.White.ToVector4().FromXNA());

            base.OnShown();
        }
Beispiel #2
0
        private void AddCamera(string show, Viewport v)
        {
            var cameraDesc = _kernel.Get<EntityDescription>();
            cameraDesc.AddProperty(new TypedName<Camera>("camera"));
            cameraDesc.AddProperty(new TypedName<Viewport>("viewport"));
            cameraDesc.AddBehaviour<OutputPlanView>();

            var cameraEntity = cameraDesc.Create();
            cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _scene.Camera;
            cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = v;

            NamedBoxCollection init = new NamedBoxCollection();
            init.Set<string>("output", show);

            _scene.Scene.Add(cameraEntity, init);
        }
Beispiel #3
0
        protected override void BeginTransitionOn()
        {
            if (_scene != null)
                return;

            _scene = _kernel.Get<Scene>();

            var renderer = _scene.GetService<Renderer>();
            renderer.StartPlan()
                    .Then(new CreateTargetComponent(new RenderTargetInfo(0, 0, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 1, false, default(RenderTargetUsage))))
                    .Then<TranslucentComponent>()
                    .Apply();

            var cameraPosition = new Vector3(0, 25, -200);

            _camera = new Camera
            {
                NearClip = 1,
                FarClip = 3000,
                View = Matrix4x4.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY)
            };
            _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip);

            var cameraDescription = _kernel.Get<EntityDescription>();
            cameraDescription.AddProperty(new TypedName<Viewport>("viewport"));
            cameraDescription.AddBehaviour<View>();
            var cameraEntity = cameraDescription.Create();
            cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera;
            cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight };
            _scene.Add(cameraEntity);

            var particleEntityDesc = _kernel.Get<EntityDescription>();
            particleEntityDesc.AddProperty(new TypedName<Vector3>("position"));
            particleEntityDesc.AddBehaviour<ParticleEmitter>();
            var entity = particleEntityDesc.Create();
            entity.GetProperty(new TypedName<Vector3>("position")).Value = Vector3.Zero;
            NamedBoxCollection initData = new NamedBoxCollection();
            initData.Set(new TypedName<ParticleEmitterDescription>("particlesystem"), _content.Load<ParticleEmitterDescription>("Particles/TestEmitter1"));
            _scene.Add(entity, initData);

            base.OnShown();
        }
Beispiel #4
0
        protected override void BeginTransitionOn()
        {
            _scene = _kernel.Get<TestScene>();

            var particleEntityDesc = _scene.Scene.Kernel.Get<EntityDescription>();
            particleEntityDesc.AddProperty(new TypedName<Vector3>("position"));
            particleEntityDesc.AddBehaviour<ParticleEmitter>();
            var entity = particleEntityDesc.Create();
            entity.GetProperty(new TypedName<Vector3>("position")).Value = Vector3.Zero;
            NamedBoxCollection initData = new NamedBoxCollection();
            initData.Set(new TypedName<ParticleEmitterDescription>("particlesystem"), _content.Load<ParticleEmitterDescription>("Particles/TestEmitter1"));
            _scene.Scene.Add(entity, initData);

            var renderer = _scene.Scene.GetService<Renderer>();

            _ssaoIntensity = renderer.Data.GetOrCreate(new TypedName<float>("ssao_intensity"));

            _fullPlan = renderer.StartPlan()
                                .Then<GeometryBufferComponent>()
                                .Then<EdgeDetectComponent>()
                                .Then<Ssao>()
                                .Then<LightingComponent>()
                                .Then<DeferredTransparency>()
                                //.Then<RestoreDepthPhase>()
                                //.Then<TranslucentComponent>()
                                .Then<ToneMapComponent>()
                                .Then<AntiAliasComponent>();

            _ssaoPlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<EdgeDetectComponent>()
                .Then<Ssao>()
                .Show("ssao");

            _lightingPlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<Ssao>()
                .Then<LightingComponent>()
                .Show("directlighting");

            _edgeDetectPlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<EdgeDetectComponent>()
                .Show("edges");

            _normalPlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<LightingComponent>()
                .Then<DeferredTransparency>()
                .Then(new AntiAliasComponent("gbuffer_normals"))
                .Show("antialiased");

            _depthPlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<LightingComponent>()
                .Then<DeferredTransparency>()
                .Show("gbuffer_depth");

            _diffusePlan = renderer.StartPlan()
                .Then<GeometryBufferComponent>()
                .Then<LightingComponent>()
                .Then<DeferredTransparency>()
                .Show("gbuffer_diffuse");

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

            _fullPlan.Apply();

            base.BeginTransitionOn();

            //var game = kernel.Get<TestGame>();
            _game.DisplayUI = true;
            //game.IsFixedTimeStep = true;
        }
Beispiel #5
0
        protected override void BeginTransitionOn()
        {
            _scene = _kernel.Get<Scene>();

            //Camera
            _cameraPosition = new Vector3(5, 0, -50);
            _camera = new Camera
            {
                NearClip = 1,
                FarClip = 700,
                View = Matrix4x4.CreateLookAt(_cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY)
            };
            _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip);
            _cameraRotation = new Vector3(0, MathHelper.Pi, 0);

            //Camera entity
            var cameraDesc = _kernel.Get<EntityDescription>();
            cameraDesc.AddProperty(new TypedName<Camera>("camera"));
            cameraDesc.AddProperty(new TypedName<Viewport>("viewport"));
            cameraDesc.AddBehaviour<View>();
            var cameraEntity = cameraDesc.Create();
            cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera;
            cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight };
            _scene.Add(cameraEntity);

            _view = cameraEntity.GetBehaviour<View>();

            //Skybox
            var skyboxDesc = _kernel.Get<EntityDescription>();
            skyboxDesc.AddBehaviour<Skybox>();
            var skybox = skyboxDesc.Create();
            skybox.GetProperty(new TypedName<TextureCube>("texture")).Value = _content.Load<TextureCube>("StormCubeMap");
            skybox.GetProperty(new TypedName<float>("brightness")).Value = 0.5f;
            skybox.GetProperty(new TypedName<bool>("gamma_correct")).Value = false;
            _scene.Add(skybox);

            //Sphere
            for (int i = 1; i < 7; i++)
            {
                var sphereModel = _content.Load<ModelData>(@"Models\sphere");
                var sphere = _kernel.Get<EntityDescription>();
                sphere.AddProperty(new TypedName<ModelData>("model"));
                sphere.AddProperty(new TypedName<Matrix4x4>("transform"));
                sphere.AddProperty(new TypedName<bool>("is_static"));
                sphere.AddBehaviour<ModelInstance>();
                var sphereEntity = sphere.Create();
                sphereEntity.GetProperty(new TypedName<ModelData>("model")).Value = sphereModel;
                sphereEntity.GetProperty(new TypedName<Matrix4x4>("transform")).Value = Matrix4x4.CreateScale(4 / sphereModel.Meshes.First().BoundingSphere.Radius)
                                                                                        * Matrix4x4.CreateRotationY(MathHelper.PiOver2)
                                                                                        * Matrix4x4.CreateTranslation(0, 0, i * 20);
                sphereEntity.GetProperty(new TypedName<bool>("is_static")).Value = true;
                _scene.Add(sphereEntity);

                var smodel = sphereEntity.GetBehaviour<ModelInstance>();
                smodel.Opacity = 0.15f;
                smodel.SubSurfaceScattering = 0.5f;
                smodel.Attenuation = 0.2f;
            }

            //Particles
            var particleEntityDesc = _scene.Kernel.Get<EntityDescription>();
            particleEntityDesc.AddProperty(new TypedName<Vector3>("position"));
            particleEntityDesc.AddBehaviour<ParticleEmitter>();
            var entity = particleEntityDesc.Create();
            NamedBoxCollection initData = new NamedBoxCollection();
            initData.Set(new TypedName<ParticleEmitterDescription>("particlesystem"), _content.Load<ParticleEmitterDescription>("Particles/TestEmitter1"));
            _scene.Add(entity, initData);

            _scene.GetService<Renderer>()
                  .StartPlan()
                  .Then<GeometryBufferComponent>()
                  .Then<EdgeDetectComponent>()
                  .Then<Ssao>()
                  .Then<LightingComponent>()
                  .Then<DeferredTransparency>()
                  .Then<ToneMapComponent>()
                  .Then<AntiAliasComponent>()
                  .Show("antialiased")
                  .Apply();

            _game.DisplayUI = true;

            base.BeginTransitionOn();
        }
Beispiel #6
0
 public void SetRenderData(NamedBoxCollection metadata)
 {
     metadata.Set<Matrix[]>("bones", _skinTransforms);
 }
Beispiel #7
0
        public void SetMetadata(NamedBoxCollection metadata)
        {
            metadata.Set(Names.View.Camera, this);
            metadata.Set(Names.Matrix.View, View);
            metadata.Set(Names.Matrix.Projection, Projection);
            metadata.Set(Names.Matrix.ViewProjection, ViewProjection);
            metadata.Set(Names.Matrix.InverseView, _inverseView);
            metadata.Set(Names.Matrix.InverseProjection, _inverseProjection);
            metadata.Set(Names.Matrix.InverseViewProjection, _inverseViewProjection);
            metadata.Set(Names.View.ViewFrustum, Bounds);
            metadata.Set(Names.View.NearClip, NearClip);
            metadata.Set(Names.View.FarClip, FarClip);
            metadata.Set(Names.View.CameraPosition, Position);

            _bounds.GetCorners(_frustumCorners);
            for (int i = 0; i < 4; i++)
                _farFrustumCorners[i] = _frustumCorners[i + 4];

            for (int i = 0; i < _farFrustumCorners.Length; i++)
                _farFrustumCorners[i] = Vector3.Transform(_farFrustumCorners[i], _view);

            metadata.Set(Names.View.FarFrustumCorners, _farFrustumCorners);
        }
Beispiel #8
0
        public void SetMetadata(NamedBoxCollection metadata)
        {
            metadata.Set("camera", this);
            metadata.Set("view", View);
            metadata.Set("projection", Projection);
            metadata.Set("viewprojection", ViewProjection);
            metadata.Set("inverseview", _inverseView);
            metadata.Set("inverseprojection", _inverseProjection);
            metadata.Set("inverseviewprojection", _inverseViewProjection);
            metadata.Set("viewfrustum", Bounds);
            metadata.Set("nearclip", NearClip);
            metadata.Set("farclip", FarClip);
            metadata.Set("cameraposition", Position);

            _bounds.GetCorners(_frustumCorners);
            for (int i = 0; i < 4; i++)
                _farFrustumCorners[i] = _frustumCorners[i + 4];
            Vector3.Transform(_farFrustumCorners, ref _view, _farFrustumCorners);
            metadata.Set("farfrustumcorners", _farFrustumCorners);
        }
Beispiel #9
0
        public void Draw(NamedBoxCollection data)
        {
            Debug.Assert(Description.Texture != null, "Particle systems must be initialised before they can be drawn.");
            //Debug.WriteLine(string.Format("retired: {0}, active: {1}, new: {2}, free: {3}", finished, active, newlyCreated, free));

            if (_dirty)
                InitialiseBuffer();

            if (_newlyCreated != _free)
                AddNewParticlesToVertexBuffer();

            if (_vertices.IsContentLost)
                _vertices.SetData(_particles);

            // If there are any active particles, draw them now!
            if (_active != _free)
            {
                _device.BlendState = Description.BlendState;
                _device.DepthStencilState = DepthStencilState.DepthRead;

                // Set an effect parameter describing the viewport size. This is
                // needed to convert particle sizes into screen space point sizes.
                _viewportScaleParameter.SetValue(new Vector2(0.5f / data.GetValue(new TypedName<Viewport>("viewport")).AspectRatio, -0.5f));

                // Set an effect parameter describing the current time. All the vertex
                // shader particle animation is keyed off this value.
                _currentTimeParameter.SetValue(_time);

                data.Set<Matrix4x4>(Names.Matrix.World, Transform);

                // Set the particle vertex and index buffer.
                _device.SetVertexBuffer(_vertices);
                _device.Indices = _indices;

                SelectParticleType();

                // Activate the particle effect.
                foreach (EffectPass pass in _material.Begin(data))
                {
                    pass.Apply();

                    // work around for an xna 4.0 bug
                    _device.SamplerStates[0] = SamplerState.PointClamp;
                    _device.SamplerStates[1] = SamplerState.PointClamp;
                    _device.SamplerStates[2] = SamplerState.PointClamp;

                    if (_active < _free)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        _device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     _active * 4, (_free - _active) * 4,
                                                     _active * 6, (_free - _active) * 2);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        _device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     _active * 4, (Description.Capacity - _active) * 4,
                                                     _active * 6, (Description.Capacity - _active) * 2);

                        if (_free > 0)
                        {
                            _device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                         0, _free * 4,
                                                         0, _free * 2);
                        }
                    }
                }

                // Reset some of the renderstates that we changed,
                // so as not to mess up any other subsequent drawing.
                _device.DepthStencilState = DepthStencilState.Default;
                _device.BlendState = BlendState.AlphaBlend;
            }

            _frameCounter++;
        }
Beispiel #10
0
 void ModelInstance.IRenderDataSupplier.SetRenderData(NamedBoxCollection metadata)
 {
     metadata.Set<Matrix4x4[]>(Names.Animation.Bones, _skinTransforms);
 }