float3 directionToLight = normalize(lightPosition - In.WorldPosition) float3 norm = normalize(In.WorldNormal); float nDotL = saturate(dot(directionToLight, norm)); // Calculate the half angle: the half the angle between our light direction and camera view // Note: CameraView should be equal to (cameraPosition - worldPosition) float3 halfAngle = normalize(normalize(in.CameraView) + directionToLight); //Get Specular component specular = pow(saturate(dot(norm, halfAngle)), specularPower) * specularLightColor * specularIntensity * nDotL;
To make that look even better you can add the normalization term to your specular.
As for spot lights, the only difference between a point light and a spot light is an additional attenuation term. Typically for a point light you use some attenuation term that you multiply into the light intensity that's based on the distance from the surface to the light source. For a spot light you can use this same distance attenutation, and then multiply it with an additional term based on the light direction and cone angles.