/*
 * arealight.osl - light source shader appropriate for an area light source.
 *
 * Description:
 *   Makes light with cosine falloff from the normal of the light source
 *   surface.  This is perfect for using with area light sources.
 *
 * Parameters:
 *   intensity, lightcolor - same meanings as pointlight
 *   shadowname - the name of the shadow map to use, if any
 *   shadowsamples - how many samples for shadow map sampling (larger is more
 *        expensive but higher quality)
 *   shadowblur - extra additive blur for shadow edges
 *   shadowbias - extra lookup bias to eliminate precision artifacts
 *   
 * Hints:
 *   To use this light to ray trace, just pass shadowname="raytrace".
 *
 */

light
arealight (float  intensity = 1,
	   color  lightcolor = 1,
	   string shadowname = "",
	   int  shadowsamples = 1,
	   float  shadowblur = 0,
	   float  shadowbias = -1 )
{
    emit (P, N, M_PI_2) {
	Cl = (intensity / dot(L,L)) * lightcolor;
        if (shadowname != "")
            Cl *= transmission (Ps, P, "traceset", shadowname,"samples", shadowsamples,
                                      "blur", shadowblur, "bias", shadowbias);
    }
}
