Zack_074
Zack_074

Reputation: 167

XNA: The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing

Hey I'm having a little trouble. I've been working with xna for a while, but I'm completely new to 3D. I'm following the code verbatim from the winformsgraphicsdevice sample on the msdn website. It has a control that draws a primitive triangle to the screen. Simple as that, but I get an exception on this line:

GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);

Which says:

"The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing."

I'm assuming it has something to do with my VertexPositionColor variable, vertices. That code is here:

vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.Black);
vertices[1] = new VertexPositionColor(new Vector3( 1, -1, 0), Color.Black);
vertices[2] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Black);

Upvotes: 4

Views: 7966

Answers (2)

Delta
Delta

Reputation: 4328

Your vertex shader is demanding a normal value (used for lighting calculations) but VertexPositionColor struct doesn't have it.

You'll have to create a struct for storing vertex position, color AND normal data as it's not a prebuilt type on XNA.

You can learn how to create it here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php

There he creates a struct called VertexPositionColorNormal, use it instead of VertexPositionColor that you're currently using.

If you don't want any lighting and you're not using BasicEffect, just remove your lighting variables/calculations from the technique you're using. If you are using BasicEffect try setting LightingEnabled and TextureEnabled properties to false.

Upvotes: 5

krolth
krolth

Reputation: 1032

How are you initializing your shader? If you are using BasicEffect, are you setting the VertexColorEnabled property to true?

The error is saying that the shader/effect that you are using does not match the primitive that you are trying to draw. It is also telling you that the shader is trying to find a Normal (used for lighting) and it cannot find it in the provided structure (since you are providing a color instead).

See this BasicEffect sample to see how you can use it if you want to pass lighting information instead http://msdn.microsoft.com/en-us/library/bb203926.aspx

Upvotes: 2

Related Questions