Time for action – the vertex shader
1. Modify the default code for the
VertexShaderFunction
function to include setting texture coordinates:VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; float4 worldPosition = mul(input.Position, World); float4 viewPosition = mul(worldPosition, View); output.Position = mul(viewPosition, Projection); output.TextureCoordinate = input.TextureCoordinate; return output; }
What just happened?
Similar to a C# function, an HLSL function declaration begins with a return type, followed by the function name and the parameters it takes inside the parenthesis. The first line of the function declares a variable to hold the output value that will be returned at the end of the function.
The next
three lines use the World
, View
, and Projection
matrices to transform the input position of the vertex to position them properly for display on the screen. As we can see, the first step is to multiply the position...