Graphics Reference
In-Depth Information
approach doesn't work for deferred rendering, since the tangent frame isn't available in the
lighting pass. 6 Instead, the normal map value must be transformed to view space or world
space, so that it can be used with the light position and direction. In our implementation
we perform the lighting calculations in world space, so we will transform the normal map
value to world space, as well. The first step in doing this is to transform the vertex tangent
frame to world space in the vertex shader. Then the per-vertex tangent frame is interpolated
for each invocation of the pixel shader, which then samples the normal map value and uses
the tangent frame to transform it to world space. The updated vertex and pixel shader pro-
grams are shown in Listing 11.2.
// Constants
cbuffer Transform
{
matrix WorldMatrix;
matrix WorldViewMatrix;
matrix WorldViewProjMatrix;
};
cbuffer MatProperties
{
float3 SpecularAlbedo;
float SpecularPower;
};
// Textures/Samplers
Texture2D DiffuseMap
Texture2D NormalMap
SamplerState AnisoSampler
register( t0 );
register( t1 );
register ( s0 );
// Input/Output structures
struct VSInput
{
float4 Position
float2 TexCoord
float3 Normal
float4 Tangent
POSITION;
TEXCOORDS0;
NORMAL;
TANGENT;
};
struct VSOutput
{
SV_Position;
TEXCOORD;
NORMALWS;
POSITIONWS;
TANGENTWS;
BITANGENTWS;
float4 PositionCS
float2 TexCoord
float3 NormalWS
float3 PositionWS
float3 TangentWS
float3 BitangentWS
};
6 These tangent space basis vectors could be added to the g-buffer, but this would require as many as nine float-
ing point values to describe the space correctly.
Search WWH ::




Custom Search