1
\$\begingroup\$

I'm 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.

Here is my draw method:

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 in VertexShaderFunction (in LightingEffect), instead of output.UV = input.UV I put output.UV=float2(somefloat,somefloat) I get no error.

There is a another thing, I got this error when I try to load my "Cathedral" model and others, but for "teapot" model I get no error.

Here is my complete code and models.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

The problem is that your vertex buffer's data doesn't contain a channel for texture coordinates, and your shader requires it. You have to edit your model and add proper UV mapping to it.

\$\endgroup\$
0

You must log in to answer this question.

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