That will give you a normalized direction vector pointing from the camera to the surface, in view space. You actually want a vector pointing from the surface -> light source, so you'd want to negate the vector. You would also need to make sure that the normal is converted to view space, otherwise you'll be working with vectors in two different coordinate spaces which wouldn't work. So you could do this:
float3 surfacePosVS = mul(float4(surfacePosWS, 1.0f), ViewMatrix); float3 normalVS = mul(float4(normalWS, 0.0f), ViewMatrix); float3 surfaceToLightVS = normalize(-surfacePosVS); float lighting = saturate(dot(normalVS, surfaceToLightVS));
Or if you'd rather do everything in world space, you can do it like this:
float3 surfaceToLightWS = normalize(CameraPosWS - surfacePosWS); float lighting = saturate(dot(normalWS, surfaceToLightWS));
For the second version, you just need to somehow pass your world space camera position through a constant buffer.