Skip to main content
GameDev.net gamedev.net
🔒 Locked

"POSITION" is an invalid input semantic ?!

Started by DeeFar Aug 9, 2006 at 8:31 AM 2 replies 8.4k views
Original Post
DeeFar
DeeFar
I am trying to write a shader of ShadowMap. But once i compile it in FXcomposser, it told me that "POSITION" is an invalid input semantic even i using vs_3_0 & ps_3_0. How could this be ? This is my shader, anyone give me a hand T_T.
float4x4	g_mCamToLight;			// 将投影后的摄像机坐标系下的位置转换为投影后的光源坐标系的矩阵
float4x4	g_mWorldViewProjCamera;	// 摄像机的变换矩阵
float4x4	g_mWorldViewProjLight;  // 光的变换矩阵
float		g_fTanPhi;				// 锥形光的顶角的1/2,用于判断定点是否在光照的范围以内
float		g_fWidth;				// 方向光有效范围的宽
float		g_fHeight;				// 方向光有效范围的高
texture		g_tShadowMap;			// ShadowMap

sampler sShadowMap = 
sampler_state
{
    Texture = <g_tShadowMap>;
    MipFilter = POINT;
    MinFilter = POINT;
    MagFilter = POINT;
};

//struct VS_OUTPUT
//{
//    float4 Pos			: POSITION;
//};

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  
};

float4 SHADOW_Dispose ()
{
	return float4 (0,0,1,0);
}

float4 NOSHADOW_Dispose ()
{
	return float4 (0,1,0,0);
}

float4 OUTOFLIGHT_Dispose ()
{
	return float4 (1,1,1,0);
}

float4 VS_RenderShadowMap( float4 vPos : POSITION ) : POSITION
{
    float4 Pos;    
    Pos= mul(vPos,g_mWorldViewProjLight);
    return Pos;    
}

PS_OUTPUT SPOT_RenderShadowMapPS( float4 Pos : POSITION) 
{ 
    PS_OUTPUT Out;
    float fDepth = Pos.z;
    //下面将深度数据写入像素信息中
    fDepth *= 0.00390625;		//  1.0f/256.0f
    //fDepth *= 0.01;
	Out.RGBColor.r = frac(fDepth);
	fDepth -= Out.RGBColor.r;
	fDepth *= 0.00390625;	
	//fDepth *= 0.01;
	Out.RGBColor.g = frac(fDepth);
	fDepth -= Out.RGBColor.g;
	fDepth *= 0.00390625;	
	//fDepth *= 0.01;
	Out.RGBColor.b = frac(fDepth);
	fDepth -= Out.RGBColor.b;
	fDepth *= 0.00390625;
	//fDepth *= 0.01;	
	Out.RGBColor.a = frac(fDepth);
	
    return Out;
}

float4 VS_RenderShadowToObj( float4 vPos : POSITION ): POSITION
{
    float4 Pos;    
    Pos = mul(vPos,g_mWorldViewProjCamera);
    return Pos;    
}

PS_OUTPUT SPOT_RenderShadowToObjPS ( float4 Pos : POSITION )
{
	PS_OUTPUT Out;
	float4 vColor = float4(0,0,0,0);
	float4 vShadowMapCoord = mul( Pos, g_mCamToLight );
	float2 vUV = float2( vShadowMapCoord.x / vShadowMapCoord.w, vShadowMapCoord.y / vShadowMapCoord.w );
	vColor = tex2D( sShadowMap, vUV );
	Out.RGBColor = vColor;//forTest
	return Out;
}

PS_OUTPUT DIR_RenderShadowMapPS( float4 Pos : POSITION) 
{ 
	PS_OUTPUT Out;
	Out.RGBColor = float4(0,0,0,0);
    return Out;
}

PS_OUTPUT DIR_RenderShadowToObjPS ( float4 Pos : POSITION )
{
	PS_OUTPUT Out;
	Out.RGBColor = float4(0,0,0,0);
	return Out;
}

technique SPOT_RenderShadowMap
{
	pass P0
	{
		VertexShader = compile vs_3_0 VS_RenderShadowMap();
        PixelShader  = compile ps_3_0 SPOT_RenderShadowMapPS( );
	}
}

technique SPOT_RenderShadowToObj
{
	pass P0
	{
		VertexShader = compile vs_3_0 VS_RenderShadowToObj();
		PixelShader	 = compile ps_3_0 SPOT_RenderShadowToObjPS();
	}
}

technique DIR_RenderShadowMap
{
	pass P0
	{
		VertexShader = compile vs_3_0 VS_RenderShadowMap();
        PixelShader  = compile ps_3_0 DIR_RenderShadowMapPS( );
	}
}

technique DIR_RenderShadowToObj
{
	pass P0
	{
		VertexShader = compile vs_3_0 VS_RenderShadowToObj();
		PixelShader	 = compile ps_3_0 DIR_RenderShadowToObjPS();
	}
}
EDIT: Please remember to use 'source' tags.
jollyjeffers
jollyjeffers
It'd be useful if you stated which line the compiler complained about. I'm guessing:

PS_OUTPUT SPOT_RenderShadowMapPS( float4 Pos : POSITION)


Which, importantly, is a pixel shader. Look up the SDK documentation - you'll see that the VS and PS units have different legal semantics. POSITION is for the VS only, not the PS. If you want position data you'll have to get the VS to clone it via a TEXCOORD...

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
DeeFar
DeeFar
THX ,i've worked that out. Why i didn't note this is because the shader i wrote before was successfully compiled even i made the same mistake.Why this one can be compiled and runs well?

What's more , how to use that 'souce' tag? T_T
float4x4	g_mWorld;               // World matrix for objectfloat4x4	g_mWorldViewProj;float4		g_vLightPos;			//光源位置float3		g_vLightDir;			//光的方向float3		g_vAxisV;				//贴图坐标v轴在世界空间中的向量float		g_fTanPhi;					//锥形光的顶角的1/2float		g_fWidth;				//方向光光源的宽float		g_fHeight;				//方向光光源的高texture		g_tShadowMap;sampler sShadowMap = sampler_state{    Texture = <g_tShadowMap>;    MipFilter = POINT;    MinFilter = POINT;    MagFilter = POINT;};struct VS_OUTPUT{    float4 Position			: POSITION;       float3 vPosInWorld		: TEXCOORD1;    float3 vNormalInWorld	: TEXCOORD2;};struct PS_OUTPUT{    float4 RGBColor : COLOR0;  };float4 SHADOW_Dispose (){	return float4 (0,0,1,0);}float4 NOSHADOW_Dispose (){	return float4 (0,1,0,0);}float4 OUTOFLIGHT_Dispose (){	return float4 (1,1,1,0);}VS_OUTPUT VS( float4 vPos : POSITION ,float4 vNormal : NORMAL0){    VS_OUTPUT Out;        Out.Position = mul(vPos,g_mWorldViewProj);    Out.vPosInWorld.xyz = (float3)(mul(vPos,g_mWorld));    Out.vNormalInWorld = normalize(mul(vNormal, (float3x3)g_mWorld));    return Out;    }PS_OUTPUT SPOT_RenderShadowMapPS( VS_OUTPUT In) {     PS_OUTPUT Out;    float3 vDist = In.vPosInWorld - (float3)g_vLightPos;    float fDepth = dot(vDist,vDist);    //下面将深度数据写入像素信息中    fDepth *= 0.00390625;		//  1.0f/256.0f    //fDepth *= 0.01;	Out.RGBColor.r = frac(fDepth);	fDepth -= Out.RGBColor.r;	fDepth *= 0.00390625;		//fDepth *= 0.01;	Out.RGBColor.g = frac(fDepth);	fDepth -= Out.RGBColor.g;	fDepth *= 0.00390625;		//fDepth *= 0.01;	Out.RGBColor.b = frac(fDepth);	fDepth -= Out.RGBColor.b;	fDepth *= 0.00390625;	//fDepth *= 0.01;		Out.RGBColor.a = frac(fDepth);	    return Out;}PS_OUTPUT SPOT_RenderShadowToObjPS ( VS_OUTPUT In ){	PS_OUTPUT Out;	float4 vColor = float4(0,0,0,0);		float  fCosTheta = dot( normalize( In.vPosInWorld - (float3)g_vLightPos) , g_vLightDir );	float  fTanTheta = sqrt(1 - fCosTheta * fCosTheta) / fCosTheta;	if ( ( (g_fTanPhi>0) && ((fTanTheta>g_fTanPhi)||(fTanTheta<0)) )		||((g_fTanPhi<0)&&(fTanTheta>g_fTanPhi)&&(fTanTheta<0)) )//判断该顶点是否在锥形光的光照范围内	{		Out.RGBColor = OUTOFLIGHT_Dispose();//即不投影也不光照	}	else	{		if (dot(In.vNormalInWorld,In.vPosInWorld - (float3)g_vLightPos) > 0)//判断顶点是否背向光源			Out.RGBColor = float4(1,0,0,0);//NOSHADOW_Dispose()光照(因为背向光源,所以只有Ambient。		else		{			//计算该顶点对应的ShadowMap的贴图坐标			float  fLength = 0.5 * fTanTheta / g_fTanPhi;			float3 vUVInWorld = normalize(In.vPosInWorld - g_vLightDir * dot( In.vPosInWorld , g_vLightDir)) ;			vUVInWorld *= fLength;			float3 vAxisU = normalize( cross( g_vAxisV , g_vLightDir ) ) ;			float2 vUV = float2 (dot( vUVInWorld , vAxisU) + 0.5, -(dot( vUVInWorld , g_vAxisV) - 0.5));			vColor = tex2D ( sShadowMap , vUV );			float  fShadowDepth = vColor.r * 2.56e2 + vColor.g * 6.5536e4 + vColor.b * 1.6777216e7 + vColor.a * 4.294967296e9;//从ShadowMap中读出深度数据			float3 vDist = (float3)g_vLightPos - In.vPosInWorld;						//判断顶点到光源的距离是否小于ShadowMap中的深度 			//fixme:会出现严重的精度丢失问题			if (fShadowDepth < dot(vDist,vDist))					{				Out.RGBColor = SHADOW_Dispose();//投影			}			else				Out.RGBColor = NOSHADOW_Dispose();//光照		}	}	//Out.RGBColor = vColor;//forTest	return Out;}PS_OUTPUT DIR_RenderShadowMapPS( VS_OUTPUT In) { 	PS_OUTPUT Out;    float3 vDist = In.vPosInWorld - (float3)g_vLightPos;    float fDepth = dot(vDist,g_vLightDir);    fDepth *= fDepth;    //fDepth += 5.0f;    //下面将深度数据写入像素信息中    fDepth *= 0.00390625;		//  1.0f/256.0f		Out.RGBColor.r = frac(fDepth);	fDepth -= Out.RGBColor.r;	fDepth *= 0.00390625;		Out.RGBColor.g = frac(fDepth);	fDepth -= Out.RGBColor.g;	fDepth *= 0.00390625;		Out.RGBColor.b = frac(fDepth);	fDepth -= Out.RGBColor.b;	fDepth *= 0.00390625;			Out.RGBColor.a = frac(fDepth);	    return Out;}PS_OUTPUT DIR_RenderShadowToObjPS ( VS_OUTPUT In ){	PS_OUTPUT Out;	float4 vColor = float4(0,0,0,0);		float3 vPos = In.vPosInWorld - (float3)g_vLightPos;	float fDist = dot(vPos,g_vLightDir); 	if(fDist < 0)//判断是否在光源的背面	{		Out.RGBColor = OUTOFLIGHT_Dispose();//即不投影也不光照	}	else	{		float3 vUVInWorld = vPos - fDist * g_vLightDir;		float3 vAxisU = normalize( cross( g_vAxisV , g_vLightDir ) ) ;		float2 vUV = float2 (dot( vUVInWorld , vAxisU) / g_fWidth + 0.5, -(dot( vUVInWorld , g_vAxisV) / g_fHeight - 0.5));			if(vUV.x>=0.0f && vUV.x<1.0f && vUV.y>=0.0f && vUV.y<1.0f)//判断是否在光照的方形范围内		{			if (dot(In.vNormalInWorld,g_vLightDir) > 0)//判断顶点是否背向光源				Out.RGBColor = float4 (1,0,0,0);//NOSHADOW_Dispose			else			{				vColor = tex2D(sShadowMap,vUV);				float fShadowDepth =  vColor.r * 2.56e2 + vColor.g * 6.5536e4 + vColor.b * 1.6777216e7 + vColor.a * 4.294967296e9;//从ShadowMap中读出深度数据				if (fShadowDepth < dot(fDist,fDist))//判断顶点到光源的距离是否小于ShadowMap中的深度						{					Out.RGBColor = SHADOW_Dispose();//投影				}				else					Out.RGBColor = NOSHADOW_Dispose();//光照			}		}		else			Out.RGBColor = OUTOFLIGHT_Dispose(); //即不投影也不光照		}	//Out.RGBColor = vColor;	return Out;}technique SPOT_RenderShadowMap{	pass P0	{		VertexShader = compile vs_1_1 VS( );        PixelShader  = compile ps_2_0 SPOT_RenderShadowMapPS( );	}}technique SPOT_RenderShadowToObj{	pass P0	{		VertexShader = compile vs_1_1 VS();		PixelShader	 = compile ps_2_0 SPOT_RenderShadowToObjPS();	}}technique DIR_RenderShadowMap{	pass P0	{		VertexShader = compile vs_1_1 VS( );        PixelShader  = compile ps_2_0 DIR_RenderShadowMapPS( );	}}technique DIR_RenderShadowToObj{	pass P0	{		VertexShader = compile vs_1_1 VS();		PixelShader	 = compile ps_2_0 DIR_RenderShadowToObjPS();	}}


[Edited by - Muhammad Haggag on August 9, 2006 10:55:23 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.