invalid input semantic 'POSITION': Legal indices are in [1,15]
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();
}
}
大侠帮忙解决,谢谢
[解决办法]
ps的输入参数不支持POSITION,改用
struct PS_INPUT{ float2 texcoord :TEXCOORD0; };
[解决办法]
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();
}
}