This shader also uses the illuminate construct, but it supplies not just the spotlight position, but also a cone of illumination:
light spotlight (
float intensity = 1;
color lightcolor = 1;
point from = point "shader" (0,0,0);
point to = point "shader" (0,0,1);
float coneangle = radians(30);
float conedeltaangle = radians(5);
float beamdistribution = 2)
{
float atten, cosangle;
uniform vector A = normalize(to-from);
illuminate (from, A, coneangle) {
cosangle = (L.A) / length(L);
atten = pow(cosangle, beamdistribution) / (L.L);
atten *= smoothstep(cos(coneangle),
cos(coneangle-conedeltaangle),
cosangle);
Cl = atten * intensity * lightcolor ;
}
}
The latter is specified as a direction, A, and a width,
specified in radians by the coneangle instance variable.