private CombinedRT CreateRT(Texture2DDescription desc)
        {
            var ret = new CombinedRT();

            ret.Texture = new Texture2D(game.Device, desc);
            ret.RTV     = new RenderTargetView(game.Device, ret.Texture);
            ret.RV      = new ShaderResourceView(game.Device, ret.Texture);

            return(ret);
        }
        public DeferredRenderer(DX11Game game)
        {
            this.game = game;
            var device = game.Device;

            context = device.ImmediateContext;

            screenWidth  = game.Form.Form.ClientSize.Width;
            screenHeight = game.Form.Form.ClientSize.Height;
            int width  = screenWidth;
            int height = screenHeight;

            gBuffer     = new GBuffer(game.Device, width, height);
            texturePool = new TexturePool(game);

            meshesRenderer = new DeferredMeshesRenderer(game, gBuffer, TexturePool);

            directionalLightRenderer = new DirectionalLightRenderer(game, GBuffer);
            spotLightRenderer        = new SpotLightRenderer(game, GBuffer);
            pointLightRenderer       = new PointLightRenderer(game, GBuffer);

            combineFinalRenderer = new CombineFinalRenderer(game, GBuffer);

            var desc = new Texture2DDescription
            {
                BindFlags =
                    BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.R16G16B16A16_Float,
                Width             = screenWidth,
                Height            = screenHeight,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1
            };

            hdrImage = new Texture2D(device, desc);

            hdrImageRtv = new RenderTargetView(device, hdrImage);
            hdrImageRV  = new ShaderResourceView(device, hdrImage);

            calculater = new AverageLuminanceCalculater(game, hdrImageRV);

            toneMap = new ToneMapRenderer(game);


            var tempDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.None,
                CpuAccessFlags    = CpuAccessFlags.Read,
                Format            = Format.R32_Float,
                Height            = 1,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Staging,
                Width             = 1
            };

            tempTex = new Texture2D(device, tempDesc);



            ssao = new HorizonSSAORenderer(game, screenWidth, screenHeight);



            Vector3 radius = new Vector3(500, 1000, 500);

            frustumCuller = new FrustumCuller(new BoundingBox(-radius, radius), 1);

            gbufferView           = frustumCuller.CreateView();
            meshesRenderer.Culler = frustumCuller;

            Texture2D skyColorTexture;// = Texture2D.FromFile(game.Device, TWDir.GameData.CreateSubdirectory("Core") + "\\skyColor.bmp");

            var strm = new DataStream(16 * 4, true, true);

            var multiplier = 2;

            strm.Write(new Half4(new Half(135f / 255f * multiplier), new Half(206f / 255f * multiplier), new Half(235 / 255f * multiplier), new Half(1)));
            strm.Position = 0;
            var dataRectangle = new DataRectangle(16 * 4, strm);

            skyColorTexture = new Texture2D(game.Device, new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.R16G16B16A16_Float,
                Height            = 1,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                Width             = 1
            }, dataRectangle);

            skyColorRV = new ShaderResourceView(game.Device, skyColorTexture);


            postProcessRT1 = CreateBackbufferLikeRT();
            postProcessRT2 = CreateBackbufferLikeRT();

            fogRenderer = new FogEffect(game);

            backgroundDepthStencilState = DepthStencilState.FromDescription(game.Device, new DepthStencilStateDescription()
            {
                IsDepthEnabled  = true,
                DepthComparison = Comparison.LessEqual,
                DepthWriteMask  = DepthWriteMask.Zero,
            });

            lineManager = new LineManager3D(game.Device);
            updateRasterizerState();
        }