0
votes

I'm trying to draw a fullscreen quad with a shader applied to it, but I keep getting the following error when drawing:

An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, TEXCOORD0.

This is how I declared my verticies for the quad:

_vertices = new VertexPositionTexture[4];
_vertices[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0));
_vertices[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0));
_vertices[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1));
_vertices[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));

And this is how I'm drawing the quad (with un-needed thing omitted out)

foreach (var pass in _lightEffect1.CurrentTechnique.Passes)
{
    pass.Apply();
    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 2, VertexPositionTexture.VertexDeclaration);
}

And here is the shader that is being applied to the quad

// Vertex shader input structure
struct VertexShaderInput
{
    float4 Pos : SV_Position;
    float2 TexCoord : TEXCOORD0;
};

// Vertex shader output structure
struct VertexShaderOutput
{
    float4 Pos : SV_Position;
    float2 TexCoord : TEXCOORD0;
};

VertexShaderOutput VertexToPixelShader(VertexShaderInput input)
{
    VertexShaderOutput output;

    output.Pos = input.Pos;
    output.TexCoord = input.TexCoord;

    return output;
}

float4 PointLightShader(VertexShaderOutput PSIn) : COLOR0
{
    //Pixel shader code here....
    return float4(shading.r, shading.g, shading.b, 1.0f);
}

technique DeferredPointLight
{
    pass Pass1
    {
        VertexShader = compile vs_4_0_level_9_1 VertexToPixelShader();
        PixelShader = compile ps_4_0_level_9_1 PointLightShader();
    }
}

One thing I noticed is that the definition in VertexPositionTexture that MonoGame provides is a vec3 for the position and a vec2 for the texcoords. However in the shader it's a float4 for the position and a float2 for the texcoords.

I tried changing it to the float3, but the shader does not compile. So I then tried to create my own "VertexPositionTexture" struct that had a vec4 with my own definition but I ended up getting the same error.

I'm not all that good at DirectX, and I tried looking all over google, but I cannot find anything that might be the cause of the problem.

Did I do something wrong in the shader? Am I missing something?

1

1 Answers

0
votes

It turns out this was a really silly fix.

The Content Pipeline tool was not compiling the converted .fx files where I thought it would, and a fix I made (changing POSITION to SV_POSITION) was not actually being used...

The shader now works, now that it's actually using the correct shader