Problem compiling shader code

Hi guys, I have a problem compiling this shader code. To be fair with you, I’m no specialist in shaders and probably the issue is quite small and somehow I can’t see it. The compilation is performed for Android, thus with /Profile:OpenGL switch enabled.

VertexToPixel TexturedWithLightsVS(float4 inPos : SV_POSITION, float3 inNormal : NORMAL, float2 inTexCoords : TEXCOORD0)
{
VertexToPixel Output = (VertexToPixel)0;

Output.Position = mul(inPos, WorldViewProjection);
Output.TextureCoords = inTexCoords;

float3 Normal = normalize(mul(normalize(inNormal), xWorld));

Output.LightingFactor = dot(Normal, xLightDirection);
if (Output.LightingFactor<0.30f)
Output.LightingFactor = 0.30f;
Output.clipDistances = dot(inPos, ClipPlane0);
Output.Position3D = mul(inPos, xWorld);
Output.Normal = (mul(inNormal, (float3x3)xWorld));
Output.View=dot(Normal,vecEye-Output.Position3D);
return Output;
}

PixelToFrame TexturedWithLightsPS(VertexToPixel PSIn) : SV_TARGET0
{
if (Clipping) clip(PSIn.clipDistances);
PixelToFrame Output = (PixelToFrame)0;

float diffuseLightingFactor = 0;// PSIn.LightingFactor + DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);

float3 N = mul(PSIn.Normal, PSIn.Position);

float D = saturate(dot(N, diffuseLightingFactor));

float3 R = normalize(reflectionPower * D * N - diffuseLightingFactor);

float S = pow(saturate(dot(R, PSIn.View)), 2)*specularPower;

float4 tmp = mul(PSIn.Position3D, xWorld);
float3 worldPosition = tmp / tmp.w;

float4 light0 = float4(0, 0, 0, 0);
if (Light0Intensity>0) {
float3 L = normalize(Light0Position - worldPosition);
float3 H = normalize(PSIn.View + L);
float2 ret = lit(dot(N, L), dot(N, H), 1).yz;
float intensity = max(L.x, L.z)*Light0Intensity;
light0 = max(dot(L, PSIn.Normal), 0) * Light0Color ret.yintensity;
}

Output.Color = tex2D(TextureSampler, PSIn.TextureCoords) +light0;
Output.Color.rgb *= saturate(PSIn.LightingFactor) + 0.5f;

clip(Output.Color[3] < 0.1f ? -1 : 1);

float dist = distance(vecEye, PSIn.Position3D);
float fog = saturate((dist - FogNear) / (FogNear - FogFar));
Output.Color = lerp(FogColor, Output.Color, fog);

if (forceRed) {
Output.Color.r = 1.0f;
}

Output.Color.a = transparency;
return Output;
}

technique TexturedWithLights
{
pass Pass0
{
AlphaBlendEnable = TRUE;
DestBlend = INVSRCALPHA;
SrcBlend = SRCALPHA;

  VertexShader = compile vs_3_0 TexturedWithLightsVS();
  PixelShader = compile ps_3_0 TexturedWithLightsPS(); 

}
}

And the error is:
error X5631: z or w components of vPos register are not available in this version, and cannot be dcl’d.

Could you please take a look at this?

Try setting the Profile to HiDef in the Game1 constructor.

On gl 3.0 with hi def i think should let you pass the z,w.

If that doesn’t work id just take a guess that it is the bottom line below then by the error msg itself.

float3 N = mul(PSIn.Normal, PSIn.Position); << // truncated to x,y
float2 ret = lit(dot(N, L), dot(N, H), 1).yz; <<< // guessing this line would then error or maybe elsewere too.

… Note…

The error is basically saying that … you can’t declare the z,w portion of the position variable in the pixel shader part of the shader, at the current shader level.

Or Even more directly that position when passed from the vertex shader to the pixel shader only the x,y portion is passed in the sv_position semantic. From what i gather that is because this is used for plotting to the x,y screen position. Also it gets perspective divided. That is why people pass the position 3d variable as a float4.

Think about it like this

You output a color from the pixel shader
Not a color and a position to draw at.
What is being used for the position to draw at ?
Well what the returned Position from the vertex shader is of course and it only needs pixel coordinates to plot to the screen in x,y and the color that you process to give it in the pixel shader.
Later versions with high def allow it to pass the xyzw i think, but im pretty sure those coordinates are changed to homogeneous by the time they get to the pixel shader also.

What sort of shader is that anyways is that a phong shader of some type ?