I am using MonoGame 3.8.1.303 with Windows/DirectX.
I am just rendering a TriangleList using DrawIndexedPrimitives, but I am always getting this error when starting my game:
D3D11 ERROR: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'SV_POSITION'/0, but the declaration doesn't provide a matching name. [ STATE_CREATION ERROR #163: CREATEINPUTLAYOUT_MISSINGELEMENT]
Exception thrown at 0x00007FFDAF45CD29 in realtimestrategy.exe: Microsoft C++ exception: _com_error at memory location 0x0000008CF917D388. Exception thrown: 'SharpDX.SharpDXException' in
SharpDX.Direct3D11.dll HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
This is my vertex declaration:
public struct VertexTypePosTxtBlend : IVertexType
{
public VertexTypePosTxtBlend(Vector3 pos, Vector2 txtCoord, Color blend)
{
this.pos = pos;
this.txtCoord = txtCoord;
this.blend = blend;
}
public Vector3 pos;
public Vector2 txtCoord;
public Color blend;
public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(sizeof(float) * 0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
new VertexElement(sizeof(float) * 5, VertexElementFormat.Color, VertexElementUsage.Color, 0)
);
readonly VertexDeclaration IVertexType.VertexDeclaration => VertexDeclaration;
};
This is my HLSL shader:
float4x4 World;
float4x4 ViewProjection;
texture UserTexture1;
texture UserTexture2;
texture UserTexture3;
texture UserTexture4;
sampler userMap1 = sampler_state
{
texture = <UserTexture1>;
};
sampler userMap2 = sampler_state
{
texture = <UserTexture2>;
};
sampler userMap3 = sampler_state
{
texture = <UserTexture3>;
};
sampler userMap4 = sampler_state
{
texture = <UserTexture4>;
};
struct VS_INPUT
{
float3 Position : SV_POSITION0;
float2 Texcoord : TEXCOORD0;
float4 Blend : COLOR0;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION0;
float2 Texcoord : TEXCOORD0;
float4 Blend : COLOR0;
};
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.Position = mul(Input.Position, mul(World, ViewProjection));
Output.Texcoord = Input.Texcoord;
Output.Blend = Input.Blend;
return Output;
}
float4 ps_main(VS_OUTPUT Input) : SV_TARGET
{
return tex2D(userMap1, Input.Texcoord) * Input.Blend.r
+ tex2D(userMap2, Input.Texcoord) * Input.Blend.g
+ tex2D(userMap3, Input.Texcoord) * Input.Blend.b
+ tex2D(userMap4, Input.Texcoord) * Input.Blend.a;
}
technique
{
pass
{
PixelShader = compile ps_4_0_level_9_1 ps_main();
VertexShader = compile vs_4_0_level_9_1 vs_main();
}
}
POSITION0is the most correct semantic. Due to shader translation, the SM 3 translation to later shader modles becomes a function of the cross-platform FX compiler(MOJO-shader). Exceptions abound. \$\endgroup\$