Graphics Reference
In-Depth Information
2.
Within D3DApp.Run , change the existing mesh loading code to the following:
// Create and initialize the mesh renderer
var loadedMesh = Common.Mesh.LoadFromFile("Tree.cmo");
loadedMesh.AddRange(Common.Mesh.LoadFromFile("Plane.cmo"));
loadedMesh.AddRange(Common.Mesh.LoadFromFile("Cube.cmo"));
3.
At this point, you should be able to compile the project and view the models.
The completed sample maps the Backspace key to cycle through the loaded meshes.
How to do it...
As we have often done in previous recipes, we will begin by updating our constant buffers
and structures. Then, we will start updating our shaders and C# rendering code:
1.
We need to modify our per material constant buffer to indicate whether a normal map
is available. The updated PerMaterial HLSL structure in Shaders\Common.hlsl
is as follows:
cbuffer PerMaterial : register (b2)
{
...
bool HasTexture;
bool HasNormalMap;
float4 MaterialEmissive;
float4x4 UVTransform;
};
2.
The updated ConstantBuffers.PerMaterial structure within
ConstantBuffers.cs is as follows (note that we changed the padding property):
public struct PerMaterial {
...
public uint HasTexture; // (0 false, 1 true)
public uint HasNormalMap; // (0 false, 1 true)
float _padding0;
public Color4 Emissive;
public Matrix UVTransform;
}
Note that we have not placed the new property at the end of the buffer.
Instead, we are adding them in such a way that we can efficiently pack
data, given the HLSL 16-byte data alignment.
A bool in HLSL is 4 bytes, and a uint 0 and 1 map to the false and
true values respectively.
 
Search WWH ::




Custom Search