public void BeginRenderPass(
IGameContext gameContext,
IRenderContext renderContext,
IRenderPass previousPass,
RenderTarget2D postProcessingSource)
{
_colorRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_colorRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.Depth24, null);
_normalRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_normalRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.None, null);
_depthRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_depthRenderTarget, gameContext, SurfaceFormat.Single, DepthFormat.None, null);
_specularRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_specularRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.None, null);
_diffuseLightRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_diffuseLightRenderTarget, gameContext, null, DepthFormat.None, null);
_specularLightRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_specularLightRenderTarget, gameContext, null, DepthFormat.None, null);
if (_rasterizerStateCullNone == null)
{
_rasterizerStateCullNone = new RasterizerState();
_rasterizerStateCullNone.CullMode = CullMode.None;
_rasterizerStateCullNone.FillMode = FillMode.Solid;
_rasterizerStateCullNone.DepthBias = 0;
_rasterizerStateCullNone.MultiSampleAntiAlias = true;
_rasterizerStateCullNone.ScissorTestEnable = false;
_rasterizerStateCullNone.SlopeScaleDepthBias = 0;
_rasterizerStateCullNone.DepthClipEnable = true;
}
if (_rasterizerStateCullClockwiseFace == null)
{
_rasterizerStateCullClockwiseFace = new RasterizerState();
_rasterizerStateCullClockwiseFace.CullMode = CullMode.CullClockwiseFace;
_rasterizerStateCullClockwiseFace.FillMode = FillMode.Solid;
_rasterizerStateCullClockwiseFace.DepthBias = 0;
_rasterizerStateCullClockwiseFace.MultiSampleAntiAlias = true;
_rasterizerStateCullClockwiseFace.ScissorTestEnable = false;
_rasterizerStateCullClockwiseFace.SlopeScaleDepthBias = 0;
_rasterizerStateCullClockwiseFace.DepthClipEnable = true;
}
if (_rasterizerStateCullCounterClockwiseFace == null)
{
_rasterizerStateCullCounterClockwiseFace = new RasterizerState();
_rasterizerStateCullCounterClockwiseFace.CullMode = CullMode.CullCounterClockwiseFace;
_rasterizerStateCullCounterClockwiseFace.FillMode = FillMode.Solid;
_rasterizerStateCullCounterClockwiseFace.DepthBias = 0;
_rasterizerStateCullCounterClockwiseFace.MultiSampleAntiAlias = true;
_rasterizerStateCullCounterClockwiseFace.ScissorTestEnable = false;
_rasterizerStateCullCounterClockwiseFace.SlopeScaleDepthBias = 0;
_rasterizerStateCullCounterClockwiseFace.DepthClipEnable = true;
}
if (_depthStencilState == null)
{
_depthStencilState = DepthStencilState.Default;
}
if (_lightDepthStencilState == null)
{
_lightDepthStencilState = DepthStencilState.None;
}
if (_blendState == null)
{
_blendState = BlendState.Opaque;
}
if (_lightBlendState == null)
{
_lightBlendState = BlendState.AlphaBlend;
}
renderContext.PushRenderTarget(
_colorRenderTarget,
_normalRenderTarget,
_depthRenderTarget,
_specularRenderTarget);
// Clear the geometry buffer before moving into main rendering.
_graphicsBlit.Blit(
renderContext,
null,
null,
_gbufferClearEffect.Effect);
_previousDepthStencilState = renderContext.GraphicsDevice.DepthStencilState;
_previousRasterizerState = renderContext.GraphicsDevice.RasterizerState;
_previousBlendState = renderContext.GraphicsDevice.BlendState;
renderContext.GraphicsDevice.DepthStencilState = _depthStencilState;
renderContext.GraphicsDevice.RasterizerState = _rasterizerStateCullCounterClockwiseFace;
renderContext.GraphicsDevice.BlendState = _blendState;
}