示例#1
0
 private void RenderOverlay()
 {
     info.Render();
     outputMerger.SetBlendState(alphaBlendState);
     diffuseBufferVar.SetResource(info.OverlayBufferView);
     gBufferOverlayPass.Apply(_immediateContext);
     _immediateContext.Draw(4, 0);
 }
示例#2
0
        void Render()
        {
            // Clear targets
            _immediateContext.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
            //_immediateContext.ClearRenderTargetView(renderView, ambient);
            _immediateContext.ClearRenderTargetView(gBufferLightView, Color4.Black);
            _immediateContext.ClearRenderTargetView(gBufferNormalView, Color4.Black);
            _immediateContext.ClearRenderTargetView(gBufferDiffuseView, Color4.Black);


            // Read collision object transforms, create geometry, etc.
            _meshFactory.InitInstancedRender();


            // Light depth map pass
            _immediateContext.ClearDepthStencilView(lightDepthView, DepthStencilClearFlags.Depth, 1.0f, 0);
            if (shadowsEnabled)
            {
                outputMerger.SetDepthStencilState(lightDepthStencilState);
                outputMerger.SetRenderTargets(lightDepthView);
                shadowGenPass.Apply(_immediateContext);
                OnRender();
                shadowLightDepthBufferVar.SetResource(lightDepthRes);
            }

            // Render geometry (colors, normals, depth) to G-buffer
            outputMerger.SetDepthStencilState(depthState);
            outputMerger.SetTargets(depthView, gBufferViews);
            gBufferGenPass.Apply(_immediateContext);
            OnRender();

            if (Demo.IsDebugDrawEnabled)
            {
                debugDrawPass.Apply(_immediateContext);
                (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World);
            }

            // Light accumulation to G-buffer
            if (deferredLightingEnabled)
            {
                outputMerger.SetBlendState(additiveBlendState);
                // Can't set depthView as render target and shader variable at the same time,
                // so early HW depth test is not available for light volumes.
                //outputMerger.SetTargets(depthView, gBufferLightView);
                outputMerger.SetTargets(gBufferLightView);
                RenderLights();
            }


            // Render G-buffer
            outputMerger.SetBlendState(alphaBlendState);
            outputMerger.SetDepthStencilState(null);
            if (depthOfFieldEnabled)
            {
                outputMerger.SetTargets(gBufferPostProcessView);
            }
            else
            {
                outputMerger.SetTargets(renderView);
            }
            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            lightBufferVar.SetResource(lightBufferRes);
            normalBufferVar.SetResource(normalBufferRes);
            diffuseBufferVar.SetResource(diffuseBufferRes);
            depthMapVar.SetResource(depthBufferRes);

            //_immediateContext.ClearRenderTargetView(gBufferPostProcessView, Color4.Black);
            gBufferRenderPass.Apply(_immediateContext);
            _immediateContext.Draw(3, 0);

            if (depthOfFieldEnabled)
            {
                diffuseBufferVar.SetResource(postProcessBufferRes);
                outputMerger.SetTargets(gBufferPostProcessViewBlur1);
                gBufferPostProcessPass.Apply(_immediateContext);
                _immediateContext.Draw(3, 0);

                diffuseBufferVar.SetResource(postProcessBufferBlur1Res);
                outputMerger.SetTargets(gBufferPostProcessViewBlur2);
                gBufferPostProcessPass.Apply(_immediateContext);
                _immediateContext.Draw(3, 0);


                diffuseBufferVar.SetResource(postProcessBufferBlur2Res);
                outputMerger.SetTargets(gBufferPostProcessViewBlur1);
                gBufferPostProcessPass.Apply(_immediateContext);
                _immediateContext.Draw(3, 0);


                diffuseBufferVar.SetResource(postProcessBufferBlur1Res);
                outputMerger.SetTargets(gBufferPostProcessViewBlur2);
                gBufferPostProcessPass.Apply(_immediateContext);
                _immediateContext.Draw(3, 0);


                diffuseBufferVar.SetResource(postProcessBufferRes);
                normalBufferVar.SetResource(postProcessBufferBlur2Res);
                outputMerger.SetTargets(renderView);
                gBufferPostProcessPass2.Apply(_immediateContext);
                _immediateContext.Draw(3, 0);
            }


            // Render overlay
            info.Render();
            outputMerger.SetBlendState(alphaBlendState);
            diffuseBufferVar.SetResource(info.OverlayBufferRes);
            gBufferOverlayPass.Apply(_immediateContext);
            _immediateContext.Draw(4, 0);

            _swapChain.Present(0, PresentFlags.None);
        }