Graphics Reference
In-Depth Information
Texture2D ColorTexture : register( t0 );
SamplerState LinearSampler : register( s0 );
struct VS_INPUT
{
float3 position : POSITION;
float2 tex
: TEXCOORDS0;
float3 normal
: NORMAL;
};
struct VS_OUTPUT
{
float4 position : SV_Position;
float2 tex
: TEXCOORD0;
float3 normal
: NORMAL;
float3 light
: LIGHT;
};
VS_OUTPUT VSMAIN( in VS_INPUT input )
{
VS_OUTPUT output;
// Generate the clip space position for feeding to the rasterizer
output.position = mul( float4( input.position, 1.0f ), WorldViewProjMatrix );
// Generate the world space normal vector
output.normal = mul( input.normal, (float3x3)WorldMatrix );
// Find the world space position of the vertex
float3 PositionWS = mul( float4( input.position, 1.0f ), WorldMatrix ).xyz;
// Calculate the world space light vector
output.light = LightPositionWS - PositionWS;
// Pass through the texture coordinates
output.tex = input.tex;
return output;
}
Listing 8.1 . The vertex shader for static mesh rendering.
Since no hardware tessellation is needed in this technique, we can skip the hull, tessel-
lator, and domain shader stages. We also don't need per-primitive level manipulations of the
model data, so the geometry shader stage is also not used. This means that the vertices emit-
ted from the vertex shader are directly consumed by the rasterizer stage. Once the rasterizer
receives a primitive (consisting of three vertices for our triangle lists) it executes, and produces
fragments to be consumed by the pixel shader. Each fragment uses a format similar to that of
Search WWH ::




Custom Search