Example #1
0
        void Render()
        {
            frameAccumulator += _frameDelta;
            ++frameCount;
            if (frameAccumulator >= 1.0f)
            {
                FramesPerSecond = frameCount / frameAccumulator;

                frameAccumulator = 0.0f;
                frameCount       = 0;
            }

            // Clear targets
            _device.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
            _device.ClearRenderTargetView(renderView, ambient);
            _device.ClearRenderTargetView(gBufferLightView, ambient);
            _device.ClearRenderTargetView(gBufferNormalView, ambient);
            _device.ClearRenderTargetView(gBufferDiffuseView, ambient);

            meshFactory.InitInstancedRender();

            // Depth map pass
            if (shadowsEnabled)
            {
                _device.ClearDepthStencilView(lightDepthView, DepthStencilClearFlags.Depth, 1.0f, 0);
                outputMerger.SetDepthStencilState(lightDepthStencilState, 0);
                outputMerger.SetRenderTargets(0, new RenderTargetView[0], lightDepthView);
                shadowGenPass.Apply();
                OnRender();
                effect2.GetVariableByName("lightDepthMap").AsShaderResource().SetResource(lightDepthRes);
            }

            // Render pass
            outputMerger.SetDepthStencilState(depthStencilState, 0);
            outputMerger.SetRenderTargets(3, gBufferViews, depthView);
            gBufferGenPass.Apply();
            OnRender();


            // G-buffer render pass
            outputMerger.SetDepthStencilState(null, 0);
            outputMerger.SetRenderTargets(1, renderViews, null);
            gBufferRenderPass.Apply();

            inputAssembler.SetVertexBuffers(0, quadBinding);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
            inputAssembler.InputLayout       = quadBufferLayout;
            _device.Draw(4, 0);

            Info.OnRender(FramesPerSecond);

            _swapChain.Present(0, PresentFlags.None);
        }
Example #2
0
 private void RenderLightDepthMap()
 {
     _immediateContext.ClearDepthStencilView(lightDepthView, DepthStencilClearFlags.Depth, 1.0f, 0);
     if (shadowsEnabled)
     {
         outputMerger.SetDepthStencilState(lightDepthStencilState);
         outputMerger.SetRenderTargets(lightDepthView);
         shadowGenPass.Apply(_immediateContext);
         OnRender();
         shadowLightDepthBufferVar.SetResource(lightDepthRes);
     }
 }
        void RenderLights()
        {
            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            inputAssembler.InputLayout       = lightVolumeInputLayout;
            inputAssembler.SetVertexBuffers(0, pointLightVolumeVertexBufferBinding);
            inputAssembler.SetIndexBuffer(pointLightVolumeIndexBuffer, Format.R32_UInt, 0);

            lightDepthBufferVar.SetResource(depthBufferRes);
            lightNormalBufferVar.SetResource(normalBufferRes);

            Vector3 eyePosition = MathHelper.Convert(Demo.Freelook.Eye);

            var previousState = _immediateContext.Rasterizer.State;

            // Camera outside light volume
            _immediateContext.Rasterizer.State = backCullState;
            outputMerger.SetDepthStencilState(outsideLightVolumeDepthState);
            foreach (var light in lights)
            {
                float radius = light.Radius;
                float bias   = radius * 2;
                if ((light.Position - eyePosition).LengthSquared() >= (radius * radius) + bias)
                {
                    RenderLight(light);
                }
            }

            // Camera inside light volume
            _immediateContext.Rasterizer.State = frontCullState;
            outputMerger.SetDepthStencilState(insideLightVolumeDepthState);
            foreach (var light in lights)
            {
                float bias = light.Radius * 2;
                if ((light.Position - eyePosition).LengthSquared() < (light.Radius * light.Radius) + bias)
                {
                    RenderLight(light);
                }
            }

            _immediateContext.Rasterizer.State = previousState;
        }
Example #4
0
        void Render()
        {
            // Clear targets
            _immediateContext.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
            //_immediateContext.ClearRenderTargetView(renderView, ambient);
            //_immediateContext.ClearRenderTargetView(gBufferLightView, ambient);
            _immediateContext.ClearRenderTargetView(gBufferNormalView, ambient);
            _immediateContext.ClearRenderTargetView(gBufferDiffuseView, ambient);

            _meshFactory.InitInstancedRender(Demo.World.CollisionObjectArray);

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

            // Render to G-buffer
            lightBufferVar.SetResource(null);
            normalBufferVar.SetResource(null);
            diffuseBufferVar.SetResource(null);
            depthMapVar.SetResource(null);
            lightDepthMapVar.SetResource(null);

            outputMerger.SetDepthStencilState(depthStencilState);
            outputMerger.SetTargets(depthView, gBufferViews);
            gBufferGenPass.Apply(_immediateContext);
            OnRender();

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

            outputMerger.SetDepthStencilState(null);
            info.OnRender(Demo.FramesPerSecond);


            outputMerger.SetTargets(renderView);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            // Render G-buffer
            lightBufferVar.SetResource(lightBufferRes);
            normalBufferVar.SetResource(normalBufferRes);
            diffuseBufferVar.SetResource(diffuseBufferRes);
            depthMapVar.SetResource(depthRes);
            lightDepthMapVar.SetResource(lightDepthRes);
            gBufferRenderPass.Apply(_immediateContext);
            _immediateContext.Draw(3, 0);


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

            _swapChain.Present(0, PresentFlags.None);
        }
Example #5
0
        void Render()
        {
            // Clear targets
            _device.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
            _device.ClearRenderTargetView(renderView, ambient);
            _device.ClearRenderTargetView(gBufferLightView, ambient);
            _device.ClearRenderTargetView(gBufferNormalView, ambient);
            _device.ClearRenderTargetView(gBufferDiffuseView, ambient);

            _meshFactory.InitInstancedRender(Demo.World.CollisionObjectArray);

            // Light depth map pass
            if (shadowsEnabled)
            {
                _device.ClearDepthStencilView(lightDepthView, DepthStencilClearFlags.Depth, 1.0f, 0);
                outputMerger.SetDepthStencilState(lightDepthStencilState, 0);
                outputMerger.SetRenderTargets(0, new RenderTargetView[0], lightDepthView);
                shadowGenPass.Apply();
                OnRender();
                lightDepthMapVar.SetResource(lightDepthRes);
            }

            // Render pass
            lightBufferVar.SetResource(null);
            normalBufferVar.SetResource(null);
            diffuseBufferVar.SetResource(null);
            depthMapVar.SetResource(null);
            lightDepthMapVar.SetResource(null);

            outputMerger.SetDepthStencilState(depthStencilState, 0);
            outputMerger.SetRenderTargets(3, gBufferViews, depthView);
            gBufferGenPass.Apply();
            OnRender();

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

            outputMerger.SetDepthStencilState(null, 0);
            info.OnRender(Demo.FramesPerSecond);


            // G-buffer render pass
            lightBufferVar.SetResource(lightBufferRes);
            normalBufferVar.SetResource(normalBufferRes);
            diffuseBufferVar.SetResource(diffuseBufferRes);
            depthMapVar.SetResource(depthRes);
            lightDepthMapVar.SetResource(lightDepthRes);

            outputMerger.SetRenderTargets(1, renderViews, null);
            gBufferRenderPass.Apply();

            inputAssembler.SetVertexBuffers(0, quadBinding);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
            inputAssembler.InputLayout       = quadBufferLayout;
            _device.Draw(4, 0);


            // G-buffer overlay pass
            diffuseBufferVar.SetResource(info.OverlayBufferRes);
            gBufferOverlayPass.Apply();
            _device.Draw(4, 0);

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