Example #1
0
        public DeferredRendering(GraphicsDevice graphicsDevice, ContentManager content)
        {
            _graphicsDevice = graphicsDevice;

            quadRenderer = new QuadRenderComponent(graphicsDevice);

            halfPixel = new Vector2()
            {
                X = 0.5f / (float)graphicsDevice.PresentationParameters.BackBufferWidth,
                Y = 0.5f / (float)graphicsDevice.PresentationParameters.BackBufferHeight
            };

            int backbufferWidth  = graphicsDevice.PresentationParameters.BackBufferWidth;
            int backbufferHeight = graphicsDevice.PresentationParameters.BackBufferHeight;

            colorRT  = new RenderTarget2D(graphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);
            normalRT = new RenderTarget2D(graphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.None);
            depthRT  = new RenderTarget2D(graphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Single, DepthFormat.None);
            lightRT  = new RenderTarget2D(graphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.None);

            basicEffect       = new DeferredBasicEffect(graphicsDevice);
            clearBufferEffect = new DeferredClearGBufferEffect(graphicsDevice);
            combineEffect     = new DeferredCombineEffect(graphicsDevice);
            pointLightEffect  = new DeferredPointLightEffect(graphicsDevice);
            spotLightEffect   = new DeferredSpotLightEffect(graphicsDevice);
            sphereModel       = content.Load <Model>(@"sphere");
        }
Example #2
0
        internal void DrawDeferred(GraphicsDevice device, DeferredBasicEffect deferredBasicEffect, Matrix world, Matrix view, Matrix projection)
        {
            deferredBasicEffect.World      = world;
            deferredBasicEffect.View       = view;
            deferredBasicEffect.Projection = projection;

            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    deferredBasicEffect.CurrentTechnique.Passes[0].Apply();
                    device.Textures[0] = ((BasicEffect)part.Effect).Texture;

                    device.SetVertexBuffer(part.VertexBuffer);
                    device.Indices = part.IndexBuffer;
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                 part.VertexOffset, 0, part.NumVertices,
                                                 part.StartIndex, part.PrimitiveCount);
                }
            }
        }