任何人都可以告诉我为什么会收到此错误:
当前顶点声明不包含当前顶点着色器所需的所有元素。 TextureCoordinate0缺失。
使用标准的顶点着色器,一切都很好。
这是我的着色器文件:
float4x4 World;
float4x4 View;
float4x4 Projection;
float4 color;
float seaLevel;
texture myTexture;
float maxHeight = 128;
float height;
sampler2D mySampler = sampler_state
{
Texture = <myTexture>;
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertexShaderInput
{
float4 Position : POSITION0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
};
struct VS_INPUT
{
float4 position : POSITION;
float4 uv : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 position : POSITION;
float4 uv : TEXCOORD0;
float4 worldPos : TEXCOORD1;
};
VS_OUTPUT Transform(VS_INPUT In)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
float4x4 viewProj = mul(View, Projection);
float4x4 worldViewProj= mul(World, viewProj);
float height = tex2Dlod ( mySampler, float4(In.uv.xy , 0 , 0 ) );
In.position.y = height * maxHeight;
Out.worldPos = mul(In.position, World);
Out.position = mul( In.position , worldViewProj);
Out.uv = In.uv;
return Out;
}
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4 worldPosition = mul(input.Position, World);
worldPosition = float4(normalize(worldPosition.xyz) * seaLevel, 1);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
return color;
}
technique Technique1
{
pass Pass1
{
VertexShader = compile vs_3_0 Transform();
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
答案 0 :(得分:1)
您尝试绘制的模型具有不包含纹理坐标的顶点。
您的顶点着色器需要纹理坐标才能工作,如技术中指定的顶点着色器所使用的结构中所示。
struct VS_INPUT
{
float4 position : POSITION;
float4 uv : TEXCOORD0;
};
technique Technique1
{
pass Pass1
{
VertexShader = compile vs_3_0 Transform();
所以,你有两个选择:
1)从VS_INPUT
中删除“uv”2)将纹理坐标字段添加到模型使用的顶点。
答案 1 :(得分:0)
我通过在3D Studio Max中打开模型,添加“UVM Map”修改器并导出回来解决了同样的问题。不是一个令人满意的解决方案,但为我工作。