예제 #1
0
        /// <summary>
        /// 描画
        /// </summary>
        public void Draw()
        {
            var context = GraphicsCore.ImmediateContext;

            UpdateDraw();

            {
                // シャドウマップ
                using (new MyGpuProfilePoint(context, "Create ShadowMap")) {
                    shadowMap_.BeginRender(context);
                    {
                        SceneDraw(context);
                    }
                    shadowMap_.EndRender(context);
                }

                // キューブマップ
                if (cubeMapRenderEnable_ && !cubeMapRendered_)
                {
                    RenderCubeMap();
                    cubeMapRendered_ = true;
                }

                // ディファードパス
                using (new MyGpuProfilePoint(context, "Deferred Path")) {
                    // GBuffer
                    using (new MyGpuProfilePoint(context, "Render GBuffer")) {
                        GraphicsCore.CurrentDrawCamera = GraphicsCore.Camera3D;
                        RenderGBuffer();
                    }
                    context.SetRenderTargets(new Texture[4], null);                     // unbind

                    // ライティングCS
                    using (new MyGpuProfilePoint(context, "Lighting")) {
                        csMgr_.Bind();
                        int x = Lib.ComputeShader.CalcThreadGroups(gbuffers_[0].Width, 32);
                        int y = Lib.ComputeShader.CalcThreadGroups(gbuffers_[0].Height, 32);
                        csMgr_.Dispatch(gbuffers_[0].Width, gbuffers_[0].Height);
                        csMgr_.UnBind();
                    }
                }

                // フォワードパス
                using (new MyGpuProfilePoint(context, "Forward Path")) {
                    context.SetRenderTargets(forwardBuffer_.color_buffer_, forwardBuffer_.depth_stencil_);
                    {
                        // キューブマップデバッグ
                        if (cubeMapRenderEnable_)
                        {
                            //globalCapture_.DebugDraw();
                            //foreach (var c in localCapture_) {
                            //	c.DebugDraw();
                            //}
                        }

                        //// ライトのデバッグ描画
                        //if (ViewModel.IsDrawLights
                        //	&& ViewModel.ViewIndex == (int)ViewItems.Type.Result
                        //	&& ViewModel.TiledRenderView != (int)TiledRenderItems.Type.LightCount
                        //	) {
                        //	lightMgr_.DebugDraw();
                        //}
                    }
                }

                // トーンマップ
                using (new MyGpuProfilePoint(context, "HDR Resolve")) {
                    if (viewModel_.IsEnableToneMap)
                    {
                        toneMap_.CalcLuminance(context, uav_);
                        context.SetRenderTargets(hdrResultBuffer_.color_buffer_, null);
                        toneMap_.KeyValue = viewModel_.ToneMapKeyValue;
                        toneMap_.ResolveHDR(context, uav_);
                    }
                    else
                    {
                        context.SetRenderTargets(hdrResultBuffer_.color_buffer_, null);
                        toneMap_.ResolveGamma(context, uav_);
                    }
                }

                // 最終レンダリング
                GraphicsCore.BeginRender();
                {
                    context.ClearDepthStencil(GraphicsCore.DefaultDepthBuffer, 1.0f);

                    // ライティング結果
                    if (ViewModel.IsEnableFXAA && ViewModel.ViewIndex == (int)ViewItems.Type.Result)
                    {
                        using (new MyGpuProfilePoint(context, "FXAA")) {
                            fxaaPrim_.Draw(context);
                        }
                    }
                    else
                    {
                        prim_.Draw(context);
                    }
                }
            }
        }