/*
 * cosinelight_rts: cosine light with ray traced shadows.
 * A light source that illuminates the lower hemisphere (y < 0) with
 * cosine distribution: full power in the direction 'dir' tapering
 * off to zero power in the directions perpendicular to 'dir'.
 * Shadows are computed with ray tracing.
 */

light
cosinelight_rts(
    float intensity = 1,
    color lightcolor = 1,
    float falloff = 2,   /* default: inverse square fall-off */
    point from = point ("shader",0,0,0),   /* light position */
    vector dir = vector(0, -1, 0)
)
{
    emit(from, dir, M_PI/2) {
        float dist = length(L);
	Cl = intensity * lightcolor * pow(dist, -falloff);   /* fall-off */
        Cl *= -dot(L,dir) / (length(L) * length(dir));   /* cosine term */
	Cl *= transmission(Ps, from);   /* ray traced shadow */
    }
}
