# XNA HLSL UV Mapping

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)
{

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;
else
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?

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