Graphics Reference
In-Depth Information
public SharpDX.Color4 Color;
public SharpDX.Vector3 Direction;
float _padding0;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PerFrame
{
public DirectionalLight Light;
...
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PerMaterial
{
public Color4 Ambient;
public Color4 Diffuse;
public Color4 Specular;
public float SpecularPower;
public uint HasTexture; // Has texture 0 false, 1 true
Vector2 _padding0;
public Color4 Emissive;
public Matrix UVTransform; // Support UV transforms
}
7.
Within our
D3DApp
class, create a new private member field,
perMaterialBuffer
,
and initialize the constant buffer in
CreateDeviceDependentResources
. As the
material constant buffer will be used by both the vertex and pixel shaders, assign the
buffer to each of them using
SetConstantBuffer
with the slot
2
.
We're now ready to update the render loop.
8.
Update the per material constant buffer with the following lines of code.
var perMaterial = new ConstantBuffers.PerMaterial();
perMaterial.Ambient = new Color4(0.2f);
perMaterial.Diffuse = Color.White;
perMaterial.Emissive = new Color4(0);
perMaterial.Specular = Color.White;
perMaterial.SpecularPower = 20f;
perMaterial.HasTexture = 0;
perMaterial.UVTransform = Matrix.Identity;
context.UpdateSubresource(ref perMaterial, perMaterialBuffer);