So, I'm trying to use SV_InstanceID as an extra input to a shader, to pick from a small set of vertex colors in code.
It seems to completely ignore the last argument of DrawIndexedInstanced(), and start at 0 per draw call. This seems less than useful, as it would make it impossible to transparently split up an instanced draw call, and defeat a lot of the purpose of having the system value at all.
How would one be expected to use SV_InstanceID properly in this case? The vertex shader looks about like so:
struct VertexInput
{
float4 position : POSITION;
uint instanceid : SV_InstanceID;
};
struct VertexOutput
{
float4 projPos : SV_Position;
float4 color : COLOR0;
};
VertexOutput vs_main( const VertexInput input )
{
VertexOutput output = (VertexOutput)0;
output.projPos = mul( float4( input.position.xyz, 1.0f ), g_ViewProjection );
if ( input.instanceid == 0 )
{
output.color = float4(1,0,0,1);
}
else if ( input.instanceid == 1 )
{
output.color = float4(0,1,0,1);
}
else
{
output.color = float4(0.5,0.5,0.5,1);
}
return output;
}
This results in it always picking red. If I instead dig a color out of a separate vertex buffer, via D3D11_INPUT_PER_INSTANCE_DATA, it works as expected.
How do I make d3d useful?