Graphics Reference
In-Depth Information
19. We then assign the G-Buffer SRVs, set the Output Merger blend state, retrieve the
camera parameters from the frustum, and then iterate over each of the lights.
// Retrieve device context
var context = this.DeviceManager.Direct3DContext;
// backup existing context state
int oldStencilRef = 0;
Color4 oldBlendFactor;
int oldSampleMaskRef;
using(var oldVertexLayout =
context.InputAssembler.InputLayout)
using(var oldPixelShader = context.PixelShader.Get())
using (var oldVertexShader = context.VertexShader.Get())
using (var oldBlendState = context.OutputMerger
.GetBlendState(out oldBlendFactor, out oldSampleMaskRef))
using (var oldDepthState = context.OutputMerger
.GetDepthStencilState(out oldStencilRef))
using (var oldRSState = context.Rasterizer.State)
{
// Assign shader resources
context.PixelShader.SetShaderResources(0,
gbuffer.SRVs.ToArray().Concat(new[] { gbuffer.DSSRV
}).ToArray());
// Assign the additive blend state
context.OutputMerger.BlendState = blendStateAdd;
// Retrieve camera parameters
SharpDX.FrustumCameraParams cameraParams =
Frustum.GetCameraParams();
// For each configured light
for (var i = 0; i < Lights.Count; i++)
{
... see next step
}
// Reset pixel shader resources (all to null)
context.PixelShader.SetShaderResources(0, new
ShaderResourceView[gbuffer.SRVs.Count + 1]);
// Restore context states
context.PixelShader.Set(oldPixelShader);
context.VertexShader.Set(oldVertexShader);
context.InputAssembler.InputLayout = oldVertexLayout;
context.OutputMerger.SetBlendState(oldBlendState,
oldBlendFactor, oldSampleMaskRef);
 
Search WWH ::




Custom Search