Esempio n. 1
0
        //Render SSAO
        void RenderSSAO(GraphicsDevice GraphicsDevice, RenderTargetBinding[] GBuffer,
                        Camera Camera)
        {
            //Set SSAO Target
            GraphicsDevice.SetRenderTarget(SSAOTarget);
            //Clear
            GraphicsDevice.Clear(Color.White);
            //Set Samplers
            GraphicsDevice.Textures[1]      = GBuffer[1].RenderTarget;
            GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
            GraphicsDevice.Textures[2]      = GBuffer[1].RenderTarget;
            GraphicsDevice.SamplerStates[2] = SamplerState.PointClamp;
            GraphicsDevice.Textures[3]      = randomNormals;
            GraphicsDevice.SamplerStates[3] = SamplerState.LinearWrap;
            //Calculate Frustum Corner of the Camera
            Vector3 cornerFrustum = Vector3.Zero;

            cornerFrustum.Y = (float)Math.Tan(Math.PI / 3.0 / 2.0) * Camera.FarClip;
            cornerFrustum.X = cornerFrustum.Y * Camera.AspectRatio;
            cornerFrustum.Z = Camera.FarClip;
            //Set SSAO parameters
            ssao.Parameters["Projection"].SetValue(Camera.Projection);
            ssao.Parameters["cornerFustrum"].SetValue(cornerFrustum);
            ssao.Parameters["sampleRadius"].SetValue(sampleRadius);
            ssao.Parameters["distanceScale"].SetValue(distanceScale);
            ssao.Parameters["GBufferTextureSize"].SetValue(new Vector2(SSAOTarget.Width,
                                                                       SSAOTarget.Height));
            //Apply
            ssao.CurrentTechnique.Passes[0].Apply();
            //Draw
            fsq.Draw(GraphicsDevice);
        }
Esempio n. 2
0
 //Clear GBuffer
 void ClearGBuffer(GraphicsDevice GraphicsDevice)
 {
     //Set to ReadOnly depth for now...
     GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
     //Set GBuffer Render Targets
     GraphicsDevice.SetRenderTargets(GBufferTargets);
     //Set Clear Effect
     Clear.CurrentTechnique.Passes[0].Apply();
     //Draw
     fsq.Draw(GraphicsDevice);
 }