Mixing 2 different VertexDeclarations in the same C# Monogame

Hi to all

I have a problem now , trying to use 2 different VertexDeclarations in the same Monogame program.
Explaination :
1 - I have begin to write a first part with a big land based on hightmap , some trees , rocks , a good water effect with reflects and refractions , sun specular , and a navigation camera to explore the landscape.
That was good but no avatar to play as a 1rst person … then step 2 :
2 - I have downloaded a fun C# sample , created by Will MOTIL , Making a FBX Skinned Mesh Loader and Animator. Realy good , it works perfectly alone , as a sandbox with only an animated FBX. That was great.
I have mixed my C# with the FBX skinned animation , and the compilation was finally OK , I have crossed my fingers but I’ve been stoped by an exception at the first RUN.

Here is the Exception message : 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, NORMAL1, NORMAL2, BLENDINDICES0, BLENDWEIGHT0.

In fact , for my landscape , I use only a VertexPositionNormalTexture VertexDeclaration , and the VertexDeclaration for the skinned FX is more complex , using bones , weights , …

Obviously , I use the good DRAW procedure for both parts , mine with landscape part based on a prepared VertexBuffer , and the skinned DRAW for the avatar animation using an effect according to the complex VertexDeclaration.

I hope you understand the context , and I hope you will give me a solution to solve this issue.
Is it possible to mix 2 different VertexDeclarations ?
How to force the good VertexDeclaration when needed ?

Chris

Exception reached when trying to DRAW avatar skinned mesh animation.

Skinned VertexDeclaration for animated FBX shader

My simple DRAW from VertexBuffer for my landscape ( based on VertexPositionNormalTexture Vertex declaration )

I’ve seen that exception a couple of times. I forgot exactly what I had done wrong but it was something fairly rudimentary (at least in my case).

Is your shader input matching that declaration?

Is your vertex data matching that declaration?

Is every element in your vertex declaration offset by the right amount?

Cheers

Thak you for your help daggepagge
Except if I loose a detail when I’ve checked those points but all seels OK , as I can show in my screenshots
Chris

Are you still having trouble with this ?

Would need to see the pixel shader vertex input structure to see whats not matched up.
Also you would need two seperate techniques and shaders and call to the correct one based on your if define.

to say all the values here in your vertexdefinition need to match up to the vertex shader input.


so your input would have to look like so.

with color defined you would need to use a vertex in pixel struct like so.
otherwise when color is not used there will be a mis-match on what is sent in data wise and the shader will expect the color to be available in the vertex passed in.

struct VsInSkinColTexNormTanBiTanWeights
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
    float2 TexureCoordinateA : TEXCOORD0;
    float3 Normal : NORMAL0;
    float3 Tangent : NORMAL1;
    float3 BiTangent : NORMAL2;
    float4 BlendIndices : BLENDINDICES0;
    float4 BlendWeights : BLENDWEIGHT0;
};

without color defined you would need to use one like this.
while this will work for both this obviously doesn't use the color.
hence the vertexshader nor the technique cant be the same as the one that does use color.

struct VsInSkin__TexNormTanBiTanWeights
{
    float4 Position : POSITION0;
    //float4 Color : COLOR0;
    float2 TexureCoordinateA : TEXCOORD0;
    float3 Normal : NORMAL0;
    float3 Tangent : NORMAL1;
    float3 BiTangent : NORMAL2;
    float4 BlendIndices : BLENDINDICES0;
    float4 BlendWeights : BLENDWEIGHT0;
};

if USING_COLORED_VERTICES define i don’t recommend doing it this way.
Because you also need to switch techniques to one that uses a pixel shader that expects the proper vertex structure input that would also need to be based on that if define.

I typically directly make two vertice definitions and switch draws and techniques directly to avoid any confusion for stuff like that, which it can cause me later on if i forget wth i did.
Also then both types are available for use at runtime.

.
.
If your using my example off the github project posted as a basis that one is actually old it was the first one i made.
That old one is cool for the basics but it has a major design flaw, that wont let it handle some fbx files.
I had to fundamentally redesign the whole thing to handle more complicated fbx files and its really really messy atm because i was testing to much other stuff with it at the time.

I have been considering pulling if off there and posting the newer one up as its totally different it would be breaking. Though its both simpler and i don’t like it so just beaware it wont handle some fbx files.

I think its about time i clean up the newer one Robust method to import skinned fbx models? and post it as a few people have used it even though i have been recomending people just convert their fbx to gltf and use the sharpgltf project by vpnades

1 Like