Graphics Reference
In-Depth Information
You may have noticed that although we updated the input layout in our C# code, we have not
yet changed the HLSL shader code to reflect this. When the input layout is being created,
it will match the layout to the vertex shader's input signature. If any semantics are missing
in the input signature, they will simply be ignored. This does not work in the other direction.
Any semantics defined in the vertex shader's input signature must also be defined in our
input layout; otherwise, we will receive a The parameter is incorrect error message.
There's moreā€¦
As we already know, data within constant buffers should be grouped by its update frequency.
As the View / Projection matrix is only updated once per frame, an improvement upon
our implementation would be to store the View / Projection matrix within the PerFrame
constant buffer. The World matrix would remain within the PerObject constant buffer and
then the calculation of the final World / View / Projection matrix would be performed within
the vertex shader (for example, float4x4 wvp = mul(World, ViewProjection); ).
This would reduce the amount of data being sent to the constant buffer per object.
Preparing the vertex and constant buffers
for materials and lighting
In this recipe, we will update the vertex and pixel shader structures and our constant buffers
to provide additional information that our vertex shader and pixel shader need to be able to
perform material and lighting operations.
After extending our per object constant buffer to support the transformation of the normal
vector and position into world space, we will also add a per frame constant buffer that will
contain our camera position and light configuration. How to create C# structures that reflect
the HLSL constant buffers is also covered.
Our vertex shader input structure will be changed to accept the normal vector and UV
coordinates from the previous recipe, and then update the pixel shader input structure to
receive the normal vector transformed to world space in addition to the world space position
and the UV coordinates.
As our shaders are becoming more complex, we will split them into multiple files; to support
this, we will use the HLSL #include directive. We will implement a simple shader that
outputs the depth to the red channel to demonstrate how to re-use this code.
 
Search WWH ::




Custom Search