Graphics Reference
In-Depth Information
public Matrix Projection;
public Matrix InverseProjection;
// Transpose the matrices so that they are in column-major
// order for HLSL (in memory).
internal void Transpose()
{
...
this.ViewProjection.Transpose();
this.View.Transpose();
this.InverseView.Transpose();
this.Projection.Transpose();
this.InverseProjection.Transpose();
}
}
15. We are now ready to fill the G-Buffer within the
D3DApp
class. Compile the vertex and
pixel shaders given previously within
CreateDeviceDependentResources
and
assign each to a new property (for example,
fillGBufferVS
and
fillGBufferPS
).
16. Within the
D3DApp.Run
method, initialize a new
GBuffer
instance as shown in the
following snippet:
GBuffer gbuffer = ToDispose(
new GBuffer(this.RenderTargetSize.Width,
this.RenderTargetSize.Height,
new SampleDescription(1, 0),
Format.R8G8B8A8_UNorm,
Format.R32_UInt,
Format.R8G8B8A8_UNorm));
gbuffer.Initialize(this);
17. Finally, within the render loop we set the vertex and pixel shader to
fillGBufferVS
and
fillGBufferPS
, prepare and bind the render targets of the G-Buffer,
perform any rendering, and then restore the previous render targets:
...
context.VertexShader.Set(fillGBufferVS);
context.PixelShader.Set(fillGBufferPS);
gbuffer.Clear(context, new Color(0, 0, 0, 0));
gbuffer.Bind(context);
meshes.ForEach((m) =>
{