1
\$\begingroup\$

I am learning game development in Monogame via book for XNA 4.0. In the code below which is for drawing the terrain, I get the error in the comment. Im using an effect from Monogame content pipeline folder, and I noticed that there are some differences between the effect file described in the book and the pipeline generated effect. how do i convert the syntax of XNA to Monogame?

    public void Draw(ArcBallCamera camera, Effect effect)
    {
        effect.CurrentTechnique = effect.Techniques["BasicColorDrawing"];
        effect.Parameters["WorldViewProjection"].SetValue(Matrix.Identity * camera.View * camera.Projection);
        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            device.SetVertexBuffer(vertexBuffer);
            device.Indices = indexBuffer;
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount); 
            //ERROR: 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, NORMAL0, TEXCOORD0.

        }
    }

the effect file:

#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

matrix WorldViewProjection;

struct VertexShaderInput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
};

struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
};

VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;

output.Position = mul(input.Position, WorldViewProjection);
output.Color = input.Color;

return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
return input.Color;
}

technique BasicColorDrawing
{
pass P0
{
    VertexShader = compile VS_SHADERMODEL MainVS();
    PixelShader = compile PS_SHADERMODEL MainPS();
}
};

the book is "XNA 4 3D Game Development by Example Beginners Guide" BY Kurt Jaegers, published in 2012

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The type of vertex you're passing in is not consistent with what is expected. The vertex has the types SV_Position0, NORMAL0, TEXCOORD0, whereas the shader expects SV_POSITION, COLOR0. Either change the shader input, or change your vertex type.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .