Graphics Reference
In-Depth Information
3.
Next, we will modify the vertex structure by adding a new Tangent property to the
end of the VertexShaderInput structure in Shaders\Common.hlsl .
struct VertexShaderInput {
...
float4 Tangent: TANGENT; // for normal mapping
};
4.
Now, let's add a new WorldTangent property to the end of the PixelShaderInput
structure within Shaders\Common.hlsl .
struct PixelShaderInput {
...
float4 WorldTangent: TANGENT; // for normal mapping
};
5.
Next, we will modify the vertex skinning (if any) to skin the tangent vector.
void SkinVertex(float4 weights, uint4 bones, inout float4
position, inout float3 normal, inout float4 tangent ) {
// If there are skin weights apply vertex skinning
if (weights.x != 0)
{
... SNIP
// also for the tangent (the w component contains
// the handedness used for calculating bitangent)
tangent = float4(mul(tangent.xyz,
(float3x3)skinTransform),
tangent.w);
}
}
6.
Within each vertex shader in Shaders\VS.hlsl , we add the input tangent to the
parameter list of SkinVertex . Then, we will apply the same transform matrix as
per the WorldNormal property. The new code is highlighted in the following code:
... SNIP vertex shader code
// Apply vertex skinning if any
SkinVertex(vertex.SkinWeights, vertex.SkinIndices, vertex.
Position, vertex.Normal, vertex.Tangent);
... SNIP vertex shader code
result.WorldNormal = mul(vertex.Normal, (float3x3)
WorldInverseTranspose);
result.WorldTangent = float4(mul(vertex.Tangent.xyz,
(float3x3)WorldInverseTranspose), vertex.Tangent.w);
... SNIP vertex shader code
 
Search WWH ::




Custom Search