Graphics Reference
In-Depth Information
10. Update the Vertex structure in Vertex.cs to include the UV coordinate,
and update the constructor(s) appropriately.
public struct Vertex {
...
public Color Color;
public Vector2 UV;
11. After updating the Vertex structure, we must also change our vertex input layout to
include the UV coordinate. The following code snippet shows the necessary changes:
...
// "COLOR"
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 24, 0),
// "UV"
new InputElement("TEXCOORD", 0, Format.R32G32_Float,28, 0),
12. Create a new class file, ConstantBuffers.cs .
13. Add the following code using directives and make the class public and static.
We will add each of the structures within the class.
using System.Runtime.InteropServices;
using SharpDX;
public static class ConstantBuffers
{
// structures defined here
}
14. We will start by defining the PerObject structure as follows:
[StructLayout(LayoutKind.Sequential)]
public struct PerObject
{
public Matrix WorldViewProjection;
// World matrix to calculate lighting in world space
public Matrix World;
// Inverse transpose of World (for normals)
public Matrix WorldInverseTranspose;
// Transpose the matrices so that they are in column
// major order for HLSL
internal void Transpose()
{
this.World.Transpose();
this.WorldInverseTranspose.Transpose();
this.WorldViewProjection.Transpose();
}
}
 
Search WWH ::




Custom Search