\begin{algorithm}[t]
	\caption{\label{alg:diffRadiances}
		Unbiased Monte Carlo estimator of $\Lind$ and $\dLind$
	}
	\begin{algorithmic}[1]
		\Function{radiance}{$\bx$, $\dbx$, $\bom$, $\dbom$}
			\State Calculate $\dist$ and $\ddist$ based on $\bx$, $\dbx$, $\bom$, and $\dbom$
			\State Sample free-flight distance $\tau$ \label{alg1:line:free_distance}
			\If{$\tau < \dist$} \Comment{volumetric}
				\State $\bx' \gets \bx - \tau\bom$, $\dbx' \gets \dbx - \tau\dbom$
					\Comment{$\bx' \in \domain \setminus \boundary$} \label{alg1:line:vol_start}
				\State $\alpha \gets \sigS(\bx')/\sigT(\bx')$ \label{alg1:line:vol_alpha}
				\State $\beta \gets (\dot{\sigS}(\bx') - \intSigT(\bx, \bom, \tau)\,\sigS(\bx'))/\sigT(\bx')$
					\Comment{\eqref{eqn:rte3d_int_sigT}} \label{alg1:line:vol_beta}
				\State Draw $\bom' \sim \phase(\bx', -\bom', \bom)$ \label{alg1:line:vol_newdir}
				\CSTATE{purpleL} $(\Lind, \dLind) \gets \textsc{radiance}(\bx', \dbx', \bom', \bm{0})$
					\Comment{recursion}	\label{alg1:line:vol_recurse}
				\CSTATE{purpleL} $\Lins \gets \Lind$ \label{alg1:line:vol_Lins_0}
				\CSTATE{purpleL} $\dLins \gets \dLind + (\dphase(\bx', -\bom', \bom)/\phase(\bx', -\bom', \bom)) \,\Lind$
					\label{alg1:line:vol_dLins_1}
				\CSTATE{greenL} $\Lins \gets \Lins + \int_{\Sph} \phase(\bx', -\bom', \bom) \,\Ldir(\bx', \bom') \,\D\bom'$
					\label{alg1:line:vol_Lins_1}
				\CSTATE{greenL} $\dLins \gets \dLins + \int_{\Sph} \sdev[\phase(\bx', -\bom', \bom) \,\Ldir(\bx', \bom')] \,\D\bom'$
					\label{alg1:line:vol_dLins_2}
				\CSTATE{orangeL} $\dLins \gets \dLins + \textsc{edgeIntegral}(\bx', \dbx', \bom, \phase)$
					\Comment{Alg.~\ref{alg:edgeIntegral}} \label{alg1:line:vol_dLins_3}
				\State $\Lind \gets \alpha\,\Lins$, $\dLind \gets \alpha\,\dLins + \beta\,\Lins$
					\label{alg1:line:vol_end}
			\Else \Comment{interfacial}
				\State $\bx_0 \gets \bx - \dist\bom$, $\dbx_0 \gets \dbx - \ddist\bom - \dist\dbom$
					\Comment{$\bx_0 \in \boundary$}  \label{alg1:line:surf_start}
				\State Draw $\bom'$ with probability $p(\bom')$
				\State $\alpha \gets \bsdf(\bx_0, \bom', \bom)/p(\bom')$
				\State $\beta \gets \intSigT(\bx, \bom, \dist) + \ddist \,\sigT(\bx_0)$
					\Comment{(\ref{eqn:rte3d_int_sigT})} \label{alg1:line:surf_beta}
				\CSTATE{purpleL} $(\Lind, \dLind) \gets \textsc{radiance}(\bx_0, \dbx_0, \bom', \bm{0})$
					\Comment{recursion} \label{alg1:line:surf_recurse}
				\CSTATE{purpleL} $\Lr \gets \alpha\,\Lind$
				\CSTATE{purpleL} $\dLr \gets \alpha\,\dLind + (\dbsdf(\bx_0, -\bom', \bom)/p(\bom')) \,\Lind$
					\label{alg1:line:surf_dLr_1}
				\CSTATE{greenL} $\Lr \gets \Lr + \int_{\Sph} \bsdf(\bx_0, -\bom', \bom) \,\Ldir(\bx_0, \bom') \,\D\bom'$
					\label{alg1:line:surf_Lr_1}
				\CSTATE{greenL} $\dLr \gets \dLr + \int_{\Sph} \sdev[\bsdf(\bx_0, -\bom', \bom) \,\Ldir(\bx_0, \bom')] \,\D\bom'$
					\label{alg1:line:surf_dLr_2}
				\CSTATE{orangeL} $\dLr \gets \dLr + \textsc{edgeIntegral}(\bx_0, \dbx_0, \bom, \bsdf)$
					\Comment{Alg.~\ref{alg:edgeIntegral}} \label{alg1:line:surf_dLr_3}
				\CSTATE{orangeL} $\Lins \gets \textsc{inScatRadiance}(\bx_0, \bom)$ \Comment{Appendix~\ref{sec:mc_ext}}
					\label{alg1:line:surf_Lins}
				\State $\Lind \gets \Lr$, $\dLind \gets  -\beta\,\Lr + \dLr + \ddist \,\sigS(\bx_0)\,\Lins$
					\label{alg1:line:surf_end}
			\EndIf
			\State \Return $(\Lind, \dLind)$
		\EndFunction
	\end{algorithmic}
\end{algorithm}

