{
	Add veiling glare caused by bright sources to an image.
	Input is direction and illuminances of sources as may
	be determined with the Radiance program, findglare(1).

	N :		Number of glaring sources
	SDx(i) :	x component of normalized direction to source i
	SDy(i) :	y component of same
	SDz(i) :	z component of same
	I(i) :		illuminance (lux) due to i in source's direction
				(multiply the luminance by the solid angle)

	An automated way to get this is to send the output of findglare
	into tabfunc, i.e.:

		findglare [options] | sed -e '1,/^BEGIN glare source$/d' \
				-e '/^END glare source$/,$d' \
			| rcalc -e '$1=recno;$2=$1;$3=$2;$4=$3;$5=$4*$5' \
			| tabfunc SDx SDy SDz I > glrsrc.cal

	Then, simply define N with "N:I(0)" either with a -e option to
	pcomb or as an additional line in glrsrc.cal, i.e.:

		pcomb -f glrsrc.cal -e 'N:I(0)' -f veil.cal orig.pic > veil.pic
}

bound(a,x,b) : if(a-x, a, if(x-b, b, x));
Acos(x) : acos(bound(-1,x,1));

{ mul(t) : if(.5*PI/180-t, 9.2/.5^2, 9.2/(180/PI)^2/(t*t)); }

mul(t) : if(1.58724464*PI/180-t, 9.2/((if(t-.00291,t,.00291)*(180/PI))^3.44),
		9.2/((180/PI*t)*(1.5+180/PI*t)));

Dx1 = Dx(1); Dy1 = Dy(1); Dz1 = Dz(1);		{ minor optimization }

angle(i) = Acos(SDx(i)*Dx1+SDy(i)*Dy1+SDz(i)*Dz1);

sum(i) = if(i-.5, mul(angle(i))*I(i)+sum(i-1), 0);

veil = le(1)/WE * sum(N);

ro = ri(1) + veil;
go = gi(1) + veil;
bo = bi(1) + veil;
