Graphics Reference
In-Depth Information
struct VS_OUTPUT
{
float4 position
:
SV_Position;
float3 normal
:
NORMAL;
float3 light
:
LIGHT;
float2 tex
:
TEXCOORDS;
};
VS_OUTPUT
VSMAIN(
in VS_INPUT input
)
{
VS_OUTPUT output;
// Calculate the output position of the vertex
output.position
= (mul(
float4( input.position,
1.0f ),
SkinMatrices[input.bone.x]
)
*
input.weights.
x);
output.position
+=(mul(
float4( input.position
, 1.0f ),
SkinMatrices[input.bone.y]
)
*
input.weights.
y);
output.position
+= (mul(
float4( input.position,
1.0f ),
SkinMatrices[input.bone.z]
)
*
input.weights.
z);
output.position
+= (mul(
float4( input.position,
1.0f ),
SkinMatrices[input.bone.w]
)
*
input.weights.
w);
// Transform world position
with
viewprojection matrix
output.position
=
mul(
output.position, ViewProjMatrix
);
//
Calculate
the world space normal vector
output.normal
= (mul(
input.normal, (float3x3)SkinNormalMatrices[input.
bone.x]
)
*
input.weights.
x)
.xyz;
output.normal
+= (mul(
input.normal, (float3x3)SkinNormalMatrices[input.
bone.y]
)
*
input.weights.
y)
.xyz;
output.normal
+= (mul(
input.normal, (fioat3x3)SkinNormalMatrices[input,
bone.z]
)
*
input.weights.
z).
xyz;
output.normal
+= (mul(
input.normal, (float3x3)SkinNormalMatrices[input.
bone.w]
)
*
input.weights.
w)
.xyz;
// Calculate the world space
light
vector
output.light
=
LightPositionWS
-
output.position.xyz;
// Pass
the texture coordinates through
output.tex
=
input.tex;
return output;
}
Listing 8.3.
The vertex shader used in the vertex skinning operation.
Search WWH ::
Custom Search