invalid input semantic 'POSITION': Legal indices are in [1,15]

chenzhiwei021 2010-03-05 03:11:56
error X4502: invalid input semantic 'POSITION': Legal indices are in [1,15]
error X4502: invalid ps_3_0 input semantic 'POSITION'

float4x4 WorldMatrix;
float4x4 ViewProjMatrix;

float3 lightpos;
float4 lightcolor = float4(1.0,0.0,0.0,1.0);
float3 lightdir;
float lightcosInnerCone = 3.14/4.0;
float lightcosOuterCone = 3.14/3.0;

texture texture0;

sampler Sampler0= sampler_state
{
texture = <texture0>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

//
float spotlight_parameter(float3 pos,
float3 lightposition,
float3 lightdiretion)
{
float3 V = normalize(pos - lightposition);
float cosDirection= dot(V,lightdiretion);
return smoothstep(lightcosOuterCone,lightcosInnerCone,cosDirection);
}

struct VS_INPUT
{
float3 Position :POSITION;
float3 Normal :NORMAL;
float2 TexCoord :TEXCOORD0;
};


struct VS_OUTPUT
{
float4 position :POSITION;
float2 texcoord :TEXCOORD0;
};


VS_OUTPUT mainVS0(VS_INPUT IN)
{
VS_OUTPUT OUT;
float4 finalpos = mul(WorldMatrix,float4(IN.Position,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
//vertex pos
OUT.position = finalpos;

//light pos
finalpos = mul(WorldMatrix,float4(lightpos,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
lightpos = finalpos.xyz;

//light direction
finalpos = mul(WorldMatrix,float4(lightdir,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
lightdir = finalpos.xyz;

OUT.texcoord = IN.TexCoord;
return OUT;
}

float4 mainPS0(VS_OUTPUT IN):COLOR
{
float4 texColor = tex2D(Sampler0,IN.texcoord);
float spotEffect = spotlight_parameter(IN.position.xyz,lightpos,lightdir);
float4 finalcolor;
finalcolor = lerp(texColor,lightcolor,spotEffect);
return finalcolor;
}

technique technique0
{
pass P0
{
CullMode = CCW;
VertexShader = compile vs_3_0 mainVS0();
PixelShader = compile ps_3_0 mainPS0();
}
}

大侠帮忙解决,谢谢
...全文
692 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenzhiwei021 2010-03-05
  • 打赏
  • 举报
回复
谢谢,已经解决了
shader调试真的很麻烦,各位有没有好的办法
xingzhe2001 2010-03-05
  • 打赏
  • 举报
回复
VS_OUTPUT里面必须含有POSITION

float4x4 WorldMatrix;
float4x4 ViewProjMatrix;

float3 lightpos;
float4 lightcolor = float4(1.0,0.0,0.0,1.0);
float3 lightdir;
float lightcosInnerCone = 3.14/4.0;
float lightcosOuterCone = 3.14/3.0;

texture texture0;

sampler Sampler0= sampler_state
{
texture = <texture0>;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

//
float spotlight_parameter(float3 pos,
float3 lightposition,
float3 lightdiretion)
{
float3 V = normalize(pos - lightposition);
float cosDirection= dot(V,lightdiretion);
return smoothstep(lightcosOuterCone,lightcosInnerCone,cosDirection);
}

struct VS_INPUT
{
float3 Position :POSITION;
float3 Normal :NORMAL;
float2 TexCoord :TEXCOORD0;
};


struct VS_OUTPUT
{
float4 position :POSITION;
float2 texcoord :TEXCOORD0;
float4 pos:TEXCOORD1;
};

struct PS_INPUT
{
float2 texcoord :TEXCOORD0;
float4 pos:TEXCOORD1;
};


VS_OUTPUT mainVS0(VS_INPUT IN)
{
VS_OUTPUT OUT;
float4 finalpos = mul(WorldMatrix,float4(IN.Position,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
//vertex pos
OUT.position = finalpos;
OUT.pos = finalpos;

//light pos
finalpos = mul(WorldMatrix,float4(lightpos,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
lightpos = finalpos.xyz;

//light direction
finalpos = mul(WorldMatrix,float4(lightdir,1.0));
finalpos = mul(ViewProjMatrix,finalpos);
lightdir = finalpos.xyz;

OUT.texcoord = IN.TexCoord;
return OUT;
}

float4 mainPS0(PS_INPUT IN):COLOR
{
float4 texColor = tex2D(Sampler0,IN.texcoord);
float spotEffect = spotlight_parameter(IN.pos.xyz,lightpos,lightdir);
float4 finalcolor;
finalcolor = lerp(texColor,lightcolor,spotEffect);
return finalcolor;
}

technique technique0
{
pass P0
{
CullMode = CCW;
VertexShader = compile vs_3_0 mainVS0();
PixelShader = compile ps_3_0 mainPS0();
}
}
chenzhiwei021 2010-03-05
  • 打赏
  • 举报
回复
引用 1 楼 xingzhe2001 的回复:
ps的输入参数不支持POSITION,改用

C/C++ codestruct PS_INPUT
{
float2 texcoord :TEXCOORD0;
};


改成了
struct VS_OUTPUT
{
float2 texcoord :TEXCOORD0;
float4 position :TEXCOORD1;

};

出现了vertex shader must minimally write all four components of POSITION

然后又将vertex shader改成
struct VS_INPUT
{
float3 Position :POSITION0;
float3 Normal :NORMAL;
float2 TexCoord :TEXCOORD0;
};
还是有同样的问题
xingzhe2001 2010-03-05
  • 打赏
  • 举报
回复
ps的输入参数不支持POSITION,改用

struct PS_INPUT
{
float2 texcoord :TEXCOORD0;
};

8,325

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧