Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Im trying to create a very simple game, and am working with HLSL. i got this error in my draw method:

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

and here is my draw method:

C#
public void Draw(Matrix View, Matrix Projection,Vector3 CameraPosition)

{ // Calculate the base transformation by combining translation, rotation, and scaling

        Matrix baseWorld = Matrix.CreateScale(Scale) *
            Matrix.CreateFromYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z) *
            Matrix.CreateTranslation(Position);
        foreach (ModelMesh mesh in Model.Meshes)
        {
            Matrix localWorld = modelTransforms[mesh.ParentBone.Index] * baseWorld;

            foreach (ModelMeshPart part in mesh.MeshParts)
            {
                Effect effect = part.Effect;
                if (part.Effect is BasicEffect)
                {
                    ((BasicEffect)effect).World = localWorld;
                    ((BasicEffect)effect).View = View;
                    ((BasicEffect)effect).Projection = Projection;
                    ((BasicEffect)effect).EnableDefaultLighting();
                }
                else
                {
                    setEffectParameter(effect, "World", localWorld);
                    setEffectParameter(effect, "View", View);
                    setEffectParameter(effect, "Projection", Projection);
                    setEffectParameter(effect, "CameraPosition", CameraPosition);

                    Material.SetEffectParameters(effect);
                }
            }
            mesh.Draw();
        }


but if in VertexShaderFunction (in LightingEffect), instead of "output.UV = input.UV" i put "output.UV=float2(somefloat,somefloat)" i got no error.

and there is a another thing, i got this error when i try to load my "Cathedral" model and others, but for "teapot" model i got no error!

i'm realy confused!

here is my complete code and models. http://www.uploadmb.com/dw.php?id=1336639273

thank you for your helping.
Posted

1 solution

Its very simple. Some of your models have UV coordinates and some do not. The shader tries to use them and gets into problems when none are loaded. And that's exactly what your error message means.

VertexDeclarations determine determine what the data structures in the vertex buffers look like and are set up automatically when a model is loaded. Try setting up the buffers for simple objects like cubes or spheres in your own code (instead of leaving the dirty work to the code that loads 3D models) and you will quickly see how that works and why the shader will get problems when the vertices don't have some component it is looking for.

Look at those tutorials[^]. There, among a few other things, vertex buffers and vertex declarations are set up to create a 3D landscape from a height map.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900