示例#1
0
        /// <summary>
        /// Begins the G-Buffer render.
        /// </summary>
        internal static void Begin(Size size)
        {
            try
            {
                // Multisampling on normal and depth maps makes no physical sense!!
                // Except MSAA is controled like was proposed in the ShaderX7 article.
                // The problem is that the available hardware does not support this technique.

                // The depth texture has a surface format of 32 bits single channel precision. Equation: -DepthVS / FarPlane
                // The normals are store using best fit normals for maximum compression (24 bits), and are stored in view space,
                // but best fit normals works better in world space, this is specially noticed in the presence of big triangles.
                // The specular power is stored in 8 bits following Killzone 2 method.
                // There is room in the depth surface to store a mask for ambient lighting (Crysis 2 and Toy Story 3 method).
                renderTargetBinding = RenderTarget.Fetch(size, SurfaceFormat.Single, DepthFormat.Depth24, SurfaceFormat.Color);

                // Set Render States.
                EngineManager.Device.BlendState        = BlendState.Opaque;
                EngineManager.Device.RasterizerState   = RasterizerState.CullCounterClockwise;
                EngineManager.Device.DepthStencilState = DepthStencilState.Default;
                // If I set the sampler states here and no texture is set then this could produce exceptions
                // because another texture from another shader could have an incorrect sampler state when this shader is executed.

                // With multiple render targets the GBuffer performance can be vastly improved.
                RenderTarget.EnableRenderTargets(renderTargetBinding);
                RenderTarget.ClearCurrentRenderTargets(Color.White);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("GBuffer Pass: Unable to begin the rendering.", e);
            }
        } // Begin
 /// <summary>
 /// Begins the G-Buffer render.
 /// </summary>
 internal static void Begin(Size size)
 {
     try
     {
         renderTargetBinding = RenderTarget.Fetch(size, SurfaceFormat.HdrBlendable, DepthFormat.Depth24Stencil8, SurfaceFormat.HdrBlendable);
         RenderTarget.EnableRenderTargets(renderTargetBinding);
         RenderTarget.ClearCurrentRenderTargets(new Color(0, 0, 0, 0));
     } // try
     catch (Exception e)
     {
         throw new InvalidOperationException("Light Pre Pass: Unable to begin the rendering.", e);
     }
 } // Begin
示例#3
0
        /// <summary>
        /// Begins the G-Buffer render.
        /// </summary>
        internal static void Begin(Size size, Color clearColor)
        {
            try
            {
                sceneTexture = RenderTarget.Fetch(size, SurfaceFormat.HdrBlendable, DepthFormat.Depth24, RenderTarget.AntialiasingType.NoAntialiasing);

                sceneTexture.EnableRenderTarget();

                RenderTarget.ClearCurrentRenderTargets(clearColor);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Scene Pass: Unable to begin the rendering.", e);
            }
        } // Begin
        } // GetParameters

        #endregion

        #region Combine

        /// <summary>
        /// Combine depth and normals (foliage and opaque) for shadows (locals and global)
        /// </summary>
        internal RenderTarget.RenderTargetBinding Render(RenderTarget depthOpaqueTexture, RenderTarget depthFoliageTexture,
                                                         RenderTarget normalOpaqueTexture, RenderTarget normalFoliageTexture)
        {
            try
            {
                EngineManager.Device.BlendState        = BlendState.Opaque;
                EngineManager.Device.DepthStencilState = DepthStencilState.None;
                EngineManager.Device.RasterizerState   = RasterizerState.CullCounterClockwise;

                SetHalfPixel(new Vector2(-1f / depthOpaqueTexture.Width, 1f / depthOpaqueTexture.Height));
                SetDepthFoliageTexture(depthFoliageTexture);
                SetDepthOpaqueTexture(depthOpaqueTexture);
                SetNormalsFoliageTexture(normalFoliageTexture);
                SetNormalsOpaqueTexture(normalOpaqueTexture);

                RenderTarget.RenderTargetBinding renderTargetBinding = RenderTarget.Fetch(depthOpaqueTexture.Size,
                                                                                          depthOpaqueTexture.SurfaceFormat,
                                                                                          DepthFormat.None,
                                                                                          normalOpaqueTexture.SurfaceFormat);

                // With multiple render targets the performance can be improved.
                RenderTarget.EnableRenderTargets(renderTargetBinding);
                RenderTarget.ClearCurrentRenderTargets(Color.White);

                // Start effect (current technique should be set));
                Resource.CurrentTechnique = Resource.Techniques["CombineDepthNormals"];
                Resource.CurrentTechnique.Passes[0].Apply();
                RenderScreenPlane();

                RenderTarget.DisableCurrentRenderTargets();
                return(renderTargetBinding);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Combine Depth and Normals Shader: Unable to render.", e);
            }
        } // Render