Ejemplo n.º 1
0
        public override void DrawScene()
        {
            Effects.TerrainFX.SetSsaoMap(_whiteTex);
            Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV);
            Effects.TerrainFX.SetShadowTransform(_shadowTransform);
            _minimap.RenderMinimap(_dirLights);

            var view     = _lightView;
            var proj     = _lightProj;
            var viewProj = view * proj;

            _terrain.Renderer.DrawToShadowMap(ImmediateContext, _sMap, viewProj);
            DrawSceneToShadowMap();

            ImmediateContext.Rasterizer.State = null;
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
            ImmediateContext.Rasterizer.SetViewports(Viewport);

            _terrain.Renderer.ComputeSsao(ImmediateContext, _camera, _ssao, DepthStencilView);

            ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView);
            ImmediateContext.Rasterizer.SetViewports(Viewport);

            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            if (Util.IsKeyDown(Keys.W))
            {
                ImmediateContext.Rasterizer.State = RenderStates.WireframeRS;
            }

            if (Util.IsKeyDown(Keys.S))
            {
                Effects.TerrainFX.SetSsaoMap(_whiteTex);
            }
            else
            {
                Effects.TerrainFX.SetSsaoMap(_ssao.AmbientSRV);
            }
            if (!Util.IsKeyDown(Keys.A))
            {
                Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV);
                Effects.TerrainFX.SetShadowTransform(_shadowTransform);
            }
            else
            {
                Effects.TerrainFX.SetShadowMap(_whiteTex);
            }

            Effects.BasicFX.SetEyePosW(_camera.Position);
            Effects.BasicFX.SetDirLights(_dirLights);
            Effects.BasicFX.SetSsaoMap(_whiteTex);

            ImmediateContext.InputAssembler.InputLayout       = InputLayouts.Basic32;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            for (var p = 0; p < Effects.BasicFX.Light1Tech.Description.PassCount; p++)
            {
                var pass = Effects.BasicFX.Light1Tech.GetPassByIndex(p);
                _unit.Render(ImmediateContext, pass, _camera.View, _camera.Proj);
            }

            _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights);

            ImmediateContext.Rasterizer.State = null;

            _sky.Draw(ImmediateContext, _camera);

            ImmediateContext.Rasterizer.State = null;
            ImmediateContext.OutputMerger.DepthStencilState     = null;
            ImmediateContext.OutputMerger.DepthStencilReference = 0;

            _minimap.Draw(ImmediateContext);

            FontCache.DrawStrings(
                new[] {
                "Currently: " + _unit.Position,
                "Destination: " + _unit.Destination.MapPosition
            },
                Vector2.Zero,
                Color.Yellow
                );
            FontCache.DrawString("bold", "This is bold", new Vector2(Window.ClientSize.Width - 200, 0), Color.Red);
            EndFrame();
        }