Graphics Reference
In-Depth Information
{
// Cull front faces and only render where there is
// something located in-front of the back face.
context.Rasterizer.State = rsCullFront;
context.OutputMerger.DepthStencilState =
depthGreaterThan;
}
volume.Render();
23. This completes the LightRenderer class. The following code snippet shows how
you might use this with the G-Buffer and render the result to screen:
// Initialize light renderer and lights
var lightRenderer = ToDispose(new LightRenderer(sphereRenderer,
saQuad, gbuffer));
lightRenderer.Initialize(this);
// Define lights
lightRenderer.Lights.Add(new PerLight
{ Color = new Color4(0.2f, 0.2f, 0.2f, 1.0f),
Type = LightType.Ambient
});
lightRenderer.Lights.Add(new PerLight
{ Color = Color.Red,
Position = new Vector3(0, 8, 1),
Range = 10,
Type = LightType.Point
});
// Fill G-Buffer
...
gbuffer.Unbind(context);
// Lighting pass
context.PixelShader.SetConstantBuffer(0, perObjectBuffer);
// Prepare perObject for use in LightRenderer
perObject.ViewProjection = viewProjection;
...
perObject.InverseProjection =
Matrix.Invert(projectionMatrix);
lightRenderer.PerObject = perObject;
lightRenderer.PerObjectBuffer = perObjectBuffer;
// Assign the Frustum (from projection matrix)
lightRenderer.Frustum = new
BoundingFrustum(projectionMatrix);
 
Search WWH ::




Custom Search