I'm trying to learn DirectX and SlimDX but I'm having a terrible time getting started.
I'm taking the Triangle tutorial and trying to add color and transformations.
Starting with controlling color, I've updated the .fx file to the following:
cbuffer cbPerObject
{
float4x4 gWVP;
};
struct vsInput
{
float4 positionLS : POSITION;
float4 color : COLOR;
};
struct vsOutput
{
float4 positionCS : POSITION;
float4 color : COLOR;
};
struct psInput
{
float4 positionCS : POSITION;
float4 color : COLOR;
};
vsOutput VShader(vsInput input)
{
vsOutput output;
output.positionCS = input.positionLS; //mul(position, gWVP);
output.color = input.color;
return output;
}
float4 PShader(psInput input) : SV_TARGET
{
return input.color;
}
And the code updates limited to the following lines:
// create test vertex data, making sure to rewind the stream afterward
var vertices = new DataStream(16 * 6, true, true);
vertices.Write(new Vector4(0.0f, 0.5f, 0.5f, 1f)); // What is W (of POSITION)
vertices.Write(new Color4(.8f, 1f, 0f, 0f)); // What should it's value be?
vertices.Write(new Vector4(0.5f, -0.5f, 0.5f, 1f));
vertices.Write(new Color4(.8f, 0f, 1f, 0f));
vertices.Write(new Vector4(-0.5f, -0.5f, 0.5f, 1f));
vertices.Write(new Color4(.8f, 0f, 0f, 1f));
vertices.Position = 0;
// create the vertex layout and buffer
// Thanks to Mārtiņš Možeiko for fixing these next lines
var elements = new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0)
};
var layout = new InputLayout(device, inputSignature, elements);
var vertexBuffer = new SlimDX.Direct3D11.Buffer(device,
vertices,
(int)vertices.Length,
ResourceUsage.Default,
BindFlags.VertexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
After a few other attempts at using SV_POSITION, COLOR, and SV_TARGET in the wrong spots, it finally executes without error; however, the triangle does not appear.
- Please help me get the triangle working again with this updated shader.
- Sample code for SetConstantBuffer() for populating gWVP for standard perspective.
Thanks!