Graphics Reference
In-Depth Information
16. Finally, we create the PerLight constant buffer and initialize our shaders.
// Buffer to light parameters
perLightBuffer = ToDispose(new Buffer(device,
Utilities.SizeOf<PerLight>(), ResourceUsage.Default,
BindFlags.ConstantBuffer, CpuAccessFlags.None,
ResourceOptionFlags.None, 0));
...
// Compile and create the vertex shader
using (var bytecode =
ShaderBytecode.CompileFromFile(@"Shaders\Lights.hlsl",
"VSLight", "vs_5_0", shaderFlags, EffectFlags.None, null,
includeHandler))
vertexShader = ToDispose(new VertexShader(device,
bytecode));
// Compile pixel shaders
using (var bytecode = ShaderBytecode.CompileFromFile(@"Shaders\
Lights.hlsl",
"PSAmbientLight", "ps_5_0", shaderFlags,
EffectFlags.None, null, includeHandler))
psAmbientLight = ToDispose(new PixelShader(device,
bytecode));
... psDirectionLight
... psPointLight
17. Like the GBuffer class, we need to be able to bind, unbind, and clear the lighting
render target. The following code snippet shows these methods:
public void Bind(DeviceContext1 context)
{
context.OutputMerger.SetTargets(DSVReadonly, RTV);
}
public void Unbind(DeviceContext1 context)
{
context.OutputMerger.ResetTargets();
}
public void Clear(DeviceContext1 context)
{
context.ClearRenderTargetView(RTV, new Color(0,0,0,1));
}
18. To complete the LightRenderer class, we implement the abstract DoRender
method. This begins by retrieving the device context and backing up the current
context state so that we can restore it after rendering the lights.
 
Search WWH ::




Custom Search