Exemplo n.º 1
0
        private void DoComposite()
        {
            Rectangle screenRect = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice);

            if (DEFERRED_RENDERING)
            {
                //GraphicsDevice.SetRenderTargets(Game1.RENDER_BUFFER);
                Matrixd projection = Matrixd.CreatePerspectiveFieldOfView(Math.PI / 4, GraphicsDevice.Viewport.AspectRatio, 0.5, 2);
                GlobalContent.SSAOShader.Parameters["PixelSize"].SetValue(new Vector2(1.0f / GraphicsDevice.Viewport.Width, 2.0f / GraphicsDevice.Viewport.Height));
                //GlobalContent.SSAOShader.Parameters["Projection"].SetValue(projection.toMatrix());
                //GlobalContent.SSAOShader.Parameters["InverseProjection"].SetValue(Matrixd.Invert(projection).toMatrix());
                Vector4[] randomOffsets = new Vector4[32];
                Random    rand          = new Random(12345);
                for (int i = 0; i < 32; i++)
                {
                    randomOffsets[i] = new Vector4((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1, -(float)rand.NextDouble(), 0);
                    randomOffsets[i].Normalize();
                    randomOffsets[i] = randomOffsets[i] * (float)rand.NextDouble();
                }
                GlobalContent.SSAOShader.Parameters["offsets"].SetValue(randomOffsets);
                float distance = 9 * (float)Math.Pow(0.5, Game1.camera.cameraZoom);
#if WINDOWS
                GlobalContent.SSAOShader.Parameters["AlbedoTexture"].SetValue(Game1.G_BUFFER[2].RenderTarget);
                GlobalContent.SSAOShader.Parameters["NormalTexture"].SetValue(Game1.G_BUFFER[1].RenderTarget);
                GlobalContent.SSAOShader.Parameters["PositionTexture"].SetValue(Game1.G_BUFFER[0].RenderTarget);
#else
                GlobalContent.SSAOShader.Parameters["PNATexture"].SetValue(Game1.G_BUFFER[0].RenderTarget);
#endif
                DrawSquare(GraphicsDevice, GlobalContent.SSAOShader);

                GraphicsDevice.SetRenderTarget(null);
                spriteBatch.Begin();
                spriteBatch.Draw((Texture2D)Game1.RENDER_BUFFER[0].RenderTarget, screenRect, Color.White);
                spriteBatch.End();
            }
            else
            {
                GraphicsDevice.SetRenderTarget(null);
                spriteBatch.Begin();
                spriteBatch.Draw((Texture2D)Game1.RENDER_BUFFER[0].RenderTarget, screenRect, Color.White);
                spriteBatch.End();
            }
        }
Exemplo n.º 2
0
        internal static Matrixd GetWorldProjectiond(double distance, double aspectRatio)
        {
            switch (MODE)
            {
            case 0:
                return(Matrixd.CreatePerspectiveFieldOfView(Math.PI / 2, aspectRatio, distance * 0.1f, distance * 100));

            case 1:
                distance *= M_1;
                return(Matrixd.CreatePerspectiveFieldOfView(Math.PI / 4, aspectRatio, distance * 0.5f, distance * 2));

            case 2:
                distance *= M_2;
                return(Matrixd.CreateOrthographicOffCenter(-0.2 * distance * aspectRatio, 0.2 * distance * aspectRatio, -0.2 * distance, 0.2 * distance, distance * 0.1, distance * 100));

            case 3:
                return(Matrixd.CreatePerspectiveFieldOfView(Math.PI * 80 / 180, aspectRatio, distance * 0.1f, distance * 100));
            }
            throw new NotImplementedException();
        }