2012-11-20 44 views
2

任何人都可以知道爲什麼我得到這個錯誤:XNA/HLSL高度圖從VertexShader

當前的頂點聲明並沒有包括所有當前頂點着色器所需的元素。 TextureCoordinate0缺失。

隨着標準的頂點着色器,一切都很好。

這裏是我的Shader文件:

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(); 
} 
} 

回答

1

你試圖要繪製的模型頂點不包含紋理座標。

您的頂點着色器需要一個紋理座標才能工作,如您的技術中指定的頂點着色器使用的結構所示​​。

struct VS_INPUT 
{ 
    float4 position : POSITION; 
    float4 uv : TEXCOORD0; 
}; 

technique Technique1 
{ 
    pass Pass1 
    {  
     VertexShader = compile vs_3_0 Transform(); 

所以,你有兩個選擇:

1)從VS_INPUT

2刪除 「UV」)紋理coordiante字段添加到您的型號所使用的頂點。

0

我通過在3D Studio Max中打開模型,添加「UVM Map」修改器並導出回來解決了同樣的問題。不是一個滿意的解決方案,但爲我工作。