I was testing my hlsl lighting shader, I've copied it from a tutorial and it works perfectly, but all the meshes in the model needs to have texture coordinate, I guess this is because this part:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.WorldPosition = worldPosition;

    output.UV = input.UV; // <--- this line

    output.Normal = mul(input.Normal, World);

    return output;

With this code I get an error: "The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing."

I have a model with many meshes and it would be much easier change the code than map all the meshes.

So I've replaced that line with this:

output.UV = float2(0,0);

and the error disappeared, then I made this:

if (TextureEnabled == true)
    output.UV = input.UV;
    output.UV = float2(0,0);

Then in the game code I pass the parameter: Parameter["TextureEnabled"].SetValue(false) in all the model meshes, just for testing, but the error reappeared! How it can reappear if the shader will never reach that line? What am I doing wrong?

  • \$\begingroup\$ What exactly is VertexShaderInput? \$\endgroup\$ – Chuck Walbourn Aug 18 '14 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.