SharpDXException (HRESULT: 0x80070057) when drawing mesh

Hi everyone.

I’ve got simple Phong shader texturing model with noise. When I try to apply this shader to model, program crashes with exception:

System.InvalidOperationException: "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."
Inner exception:
SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

Stack trace:

   at Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(VertexBufferBindings vertexBuffers)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(Boolean applyShaders)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
   at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
   at AS.Fractalyze.Core.FractalyzeGame.Draw(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.DoDraw(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.Tick()
   at Microsoft.Xna.Framework.UAPGameWindow.Tick()
   at Microsoft.Xna.Framework.UAPGamePlatform.<>c.<StartRunLoop>b__11_0(IAsyncAction action)

I have a couple of other shaders (just texturing, no Phong or noise stuff), they are applies ok.
Shader is built ok with pipeline tool; also I tested it in RenderMonkey (lol), it works ok.

What can cause this trouble?

Shader

Output code (little bit simplified)

What type mesh file fbx, obj, x ? most likely yourmesh file does not include normals, try to build your model with createTangentFrames, hopefully it will also generate normals ^_^y

EDIT :

Or try to change your the order of your vertex input

struct VertexShaderInput 
{   
      float4 Position : POSITION0;   
      float3 Normal   : NORMAL0;   
      float2 Texcoord : TEXCOORD0;        
};

Your mesh does not have texture coords.

When you look at one of these you look at the error carefully…

The current vertex declaration includes these elements: SV_Position0, NORMAL0."

Then you look at the shader.

struct VertexShaderInput
{
   float4 Position : POSITION;
   float2 Texcoord : TEXCOORD0;
   float3 Normal :   NORMAL0;
   
};

The shader needs TEXCOORD0 and the input declaration only supplies position and normal.

2 Likes

Yep, I looked for other threads and came up with thought I miss texcoords. Thanks!