Directional light
Calculate light direction
We can just define a light direction in Light class
Point Light
Calculate Attenuation
reduce the intensity of light over the distance a light ray travels
Spot Light
We need: the spotlight’s position vector (to calculate the fragment-to-light’s direction vector), the spotlight’s direction vector and the cutoff angle.
Caculate Angles
We pass the cosine value because it is easier to compare
calculate the theta θ value and compare this with the cutoff ϕ value to determine if we’re in or outside the spotlight:
if cosθ > cutOff, we can know that θ < ϕ
Smooth Edges
Set γ as outer cone angle value
intensity = (θ−γ) / (ϕ−γ)