Graphics Reference
In-Depth Information
8.
Next, we will create the necessary shader code to fill the G-Buffer. First we will
update the PerObject constant buffer within Common.hlsl to include the View ,
InverseView , Projection , and InverseProjection matrices shown as follows:
cbuffer PerObject : register(b0)
{
...
// The view matrix
float4x4 View;
// The inverse view matrix
float4x4 InverseView;
// The projection matrix
float4x4 Projection;
// The inverse of the projection matrix
float4x4 InverseProjection;
};
You may notice that these matrices are not necessarily changing per object, and
perhaps should instead be moved to the PerFrame constant buffer. However, for
simplicity we will continue to keep the affine transform matrices together.
9. We'll now put the logic for filling the G-Buffer into a new HLSL file named
FillGBuffer.hlsl . Remember to use ANSI encoding as described in
Chapter 2 , Rendering with Direct3D .
10. Define the necessary input texture references, include the Common.hlsl HLSL file,
and define our pixel shader output structure:
Texture2D Texture0 : register(t0);
Texture2D NormalMap: register(t1);
Texture2D SpecularMap: register(t2);
...
SamplerState Sampler : register(s0);
#include "Common.hlsl"
// From Vertex shader to PSFillGBuffer
struct GBufferPixelIn
{
float4 Position : SV_Position;
float4 Diffuse : COLOR;
float2 TextureUV: TEXCOORD0;
// view-space Normal and tangent
float3 ViewNormal : TEXCOORD1;
float4 ViewTangent : TANGENT; // .w handedness from CMO
};
 
Search WWH ::




Custom Search