Hello,
I try to create a deferred rendering using MonoGame. This is yet simple but render deferred work. But I do not understand how combine the deferred rendering to forward rendering. How to do ?
Sorry for my practice in English, I am French.
Thank you.
This is my actual method code:
public void Compute(in GameTime gameTime, in EventHandler<DrawingEventArgs> drawing, in EventHandler<LightingEventArgs> lighting)
{
// G-Buffer
graphicsDevice.DepthStencilState = DepthStencilState.Default;
graphicsDevice.SetRenderTargets(depthMap, albedoMap, normalMap, worldPositionMap);
clearGBuffer.CurrentTechnique.Passes[0].Apply();
drawing?.Invoke(this, new DrawingEventArgs(in gameTime));
depthMap = graphicsDevice.GetRenderTargets()[0].RenderTarget as RenderTarget2D;
albedoMap = graphicsDevice.GetRenderTargets()[1].RenderTarget as RenderTarget2D;
normalMap = graphicsDevice.GetRenderTargets()[2].RenderTarget as RenderTarget2D;
worldPositionMap = graphicsDevice.GetRenderTargets()[3].RenderTarget as RenderTarget2D;
// Ligh and Shadow
graphicsDevice.SetRenderTargets(lightMap, shadowMap);
graphicsDevice.Clear(Color.Transparent);
graphicsDevice.BlendState = BlendState.Additive;
lighting?.Invoke(this, new LightingEventArgs(in depthMap, in albedoMap, in normalMap, in worldPositionMap, in vertexData, in indexData));
lightMap = graphicsDevice.GetRenderTargets()[0].RenderTarget as RenderTarget2D;
shadowMap = graphicsDevice.GetRenderTargets()[1].RenderTarget as RenderTarget2D;
graphicsDevice.BlendState = BlendState.Opaque;
// Renderer
graphicsDevice.SetRenderTargets(renderedImageMap);
unpack.Parameters["LightMap"].SetValue(lightMap);
unpack.Parameters["ShadowMap"].SetValue(shadowMap);
unpack.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
renderedImageMap = graphicsDevice.GetRenderTargets()[0].RenderTarget as RenderTarget2D;
graphicsDevice.SetRenderTargets(null);
// Output
get.Parameters["DRColor"].SetValue(renderedImageMap);
get.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
}