[<< wikibooks] Cg Programming/Unity/Soft Shadows of Spheres
This tutorial covers soft shadows of spheres.

While directional light sources and point light sources produce hard shadows, any area light source generates a soft shadow. This is also true for all real light sources, in particular the sun and any light bulb or lamp. From some points behind the shadow caster, no part of the light source is visible and the shadow is uniformly dark: this is the umbra. From other points, more or less of the light source is visible and the shadow is therefore less or more complete: this is the penumbra. Finally, there are points from where the whole area of the light source is visible: these points are outside of the shadow.
In many cases, the softness of a shadow depends mainly on the distance between the shadow caster and the shadow receiver: the larger the distance, the softer the shadow. This is a well known effect in art; see for example the painting by Caravaggio to the right.

== Computation ==
We are going to approximately compute the shadow of a point on a surface when a sphere of radius

r

sphere

{\displaystyle r_{\text{sphere}}}
at S (relative to the surface point) is occluding a spherical light source of radius

r

light

{\displaystyle r_{\text{light}}}
at L (again relative to the surface point); see the figure to the left.
To this end, we consider a tangent in direction T to the sphere and passing through the surface point. Furthermore, this tangent is chosen to be in the plane spanned by L and S, i.e. parallel to the view plane of the figure to the left. The crucial observation is that the minimum distance

d

{\displaystyle d}
of the center of the light source and this tangent line is directly related to the amount of shadowing of the surface point because it determines how large the area of the light source is that is visible from the surface point. More precisely spoken, we require a signed distance (positive if the tangent is on the same side of L as the sphere, negative otherwise) to determine whether the surface point is in the umbra (

d
<
−

r

light

{\displaystyle d<-r_{\text{light}}}
), in the penumbra (

−

r

light

<
d
<

r

light

{\displaystyle -r_{\text{light}}