Trying to implement spotlight inside the shader.
My current code:
With NdotL calculations in the bottom part, i achieve proper shading, but it also removes light cone visibility from certain surfaces ofcourse.
Notice area marked red. Light are missed due to NdotL calculations.
So, im not really understand atm how i can achieve proper shading?
the dot product returns -1 to 1 values, by using the saturate node after the dot product all the info in the 0 to -1 range is sheared off. however you will need that info. So instead of the saturate node use the constant bias scale to convert the values from -1 to 1 into 0 to 1, then tweak the gradient with add,mult/div,power.
the gradient function and the constantbiasScale node could probably be combined to save a couple instructions.
Well, in that case problem was solved by using dot product of “light direction vector” and “surface point to light” vector (light position - world position), instead of pixel normal. ← WRONG
UPD: problem was solved by using dot product of “surface point to light” vector and pixelnormal vector.
I should sleep more before writing something.