\section{Differentiable Radiative Transfer}
\label{sec:diff_rte}
%
We now present our differential theory of radiative transfer that shows how the interior radiance $\Lv$ can be differentiated with respect to some scene parameter $\pi \in \Real$.
To this end, we derive the partial derivative $\dLv := \sdev\Lv$ by differentiating each of the operators on the right-hand side (RHS) of Eq.~\eqref{eqn:rte3d_Lonly}.

\begin{figure}[t]
	\begin{myTitledBox}{Outline of Our Derivations}
		\vspace{-1mm}
		\[
			\dLv = \underbrace{\sdev\kernelT\,\kernelC\,\Lv}_{\text{\normalsize\S\ref{ssec:dev_trans}, \S\ref{ssec:dLins}}}
			\;+\; \underbrace{\sdev\kernelS\,\Lv}_{\text{\normalsize\S\ref{ssec:boundary}}}
			\;+\; \underbrace{\dLdir}_{\text{\normalsize\S\ref{ssec:together}}}.
		\]
		\vspace{-2mm}
	\end{myTitledBox}
	\caption{\label{fig:outline}
		An \textbf{outline of our derivations} in \S\ref{sec:diff_rte}.
		To derive $\dLv$, we differentiate the transport and collision operators $\kernelT$ and $\kernelC$ in \S\ref{ssec:dev_trans}, the interfacial scattering operator $\kernelS$ in \S\ref{ssec:boundary}, and the source term $\Ldir$ in \S\ref{ssec:together}.
	}
\end{figure}

\paragraph{Assumptions}
As most participating media and translucent materials are non-emissive, we neglect the volumetric emission term $\Lve$ in Eqs.~\eqref{eqn:rte3d_src} and \eqref{eqn:rte3d_Ldir} when deriving $\dLv$ in this section.
Additionally, we assume that: (i)~the RTE and RE parameters $\sigT$, $\sigS$, $\phase$, $\Lve$, $\bsdf$, and $\Le$ are \emph{continuous} spatially and directionally;
and (ii)~there are no \emph{zero-measure} light sources (e.g., point and directional) or \emph{ideal specular surfaces} (e.g., perfect mirrors). We generalize our derivations by relaxing some of these assumptions in the supplement.

\paragraph{Overview}
Figure~\ref{fig:outline} outlines the structure of our derivations.
As a preview, based on the assumptions above, the scene partial derivative $\dLv$ will take the form of Eq.~\eqref{eqn:rte3d_dLv_full} with dependencies between the involved quantities summarized in Figure~\ref{fig:dependency}.


\subsection{Differentiation of the Transport \& Collision Operators}
\label{ssec:dev_trans}
%
We start with the first term on the RHS in Figure~\ref{fig:outline}, $\sdev\kernelT\,\kernelC\,\Lv$.
As we derive in Appendix~\ref{ssec:kernelT_deriv}, this derivative comprises the terms:
%
\begin{myMathBox}
	\begin{align}
		& \left(\sdev\kernelT\,\kernelC\,\Lv\right)(\bx, \bom) = \tint_0^{\dist} T(\bx', \bx) \, \sigS(\bx') \,\dLins(\bx', \bom) \,\D\tau \nonumber\\
		& \quad + \tint_0^{\dist} T(\bx', \bx) \left[\dot{\sigS}(\bx') - \intSigT(\bx, \bom, \tau)\,\sigS(\bx')\right] \Lins(\bx', \bom) \,\D\tau \nonumber\\
		& \quad + \ddist \, \trans(\bx_0, \bx) \, \sigS(\bx_0) \,\Lins(\bx_0, \bom), \label{eqn:rte3d_ind_diff}
	\end{align}
\end{myMathBox}
%
\noindent
where $\bx' := \bx - \tau\bom$ is a point on the ray $(\bx, -\bom)$; $\bx_0 := \bx - \dist\bom$ is the location where the ray intersects the medium boundary; $\Lins$ is the in-scattered radiance from Eq.~\eqref{eqn:rte3d_Lins}; and $\intSigT(\bx, \bom, \tau)$, defined as
%
\begin{equation}
	\label{eqn:rte3d_int_sigT}
	\intSigT(\bx, \bom, \tau)
	:= \tint_0^\tau \dot{\sigT}(\bx - \tau'\bom) \,\D\tau',
\end{equation}
%
appears when we differentiate the transmittance $\trans(\bx', \bx)$ (see Appendix~\ref{ssec:trans_deriv}).

In Eqs.~\eqref{eqn:rte3d_ind_diff} and \eqref{eqn:rte3d_int_sigT}, $\dot{\sigT}$ and $\dot{\sigS}$ are essentially \emph{material derivatives} given by~\cite{leal2007advanced}
%
\begin{equation}
	\label{eqn:rte3d_dSigT_dSigS}
	\dot{\sigma}(\bx) = \frac{\partial\sigma}{\partial\param}(\bx) + \langle \dbx, \nabla \sigma(\bx) \rangle,
\end{equation}
%
for $\sigma \in \{\sigT, \sigS\}$ with $\nabla$ being the gradient operator.

Evaluating the RHS of Eq.~\eqref{eqn:rte3d_ind_diff} also requires $\ddist$, $\Lins(\bx_0, \bom)$, and $\dLins(\bx', \bom)$.
In what follows, we derive formulas for these terms.

\paragraph{Derivation of $\ddist$}
In the transport operator of Eq.~\eqref{eqn:rte3d_kernelT}, the upper-bound of the line integral $\dist$ is determined by the distance a light ray originating at $\bx$ with direction $-\bom$ travels before intersecting the medium boundary $\boundary$.
Suppose that the boundary~$\boundary(\param)$ has an implicit representation $F(\by; \param) = 0$ parameterized by $\param$.
Then, substituting $\by$ with the ray equation yields $F(\bx - \dist\bom; \param) = 0$ and $\dist = F^{-1}(0; \bx, \bom, \param)$, with $F^{-1}$ being the inverse function of $F$ with respect to $\dist$.
Then, $\ddist = \sdev F^{-1}(0; \bx, \bom, \param)$.

For piecewise-linear shapes, such as polygonal meshes, it holds that $F(\bx - \dist\bom; \param) = \langle \gnorm^\mathrm{face},\ \bx - \dist\bom - \bp^\mathrm{face} \rangle$, where $\gnorm^\mathrm{face}$ is the normal of the face containing the intersection point, and $\bp^\mathrm{face}$ is an arbitrary point (e.g., a vertex) on that face.
Note that both $\gnorm^\mathrm{face}$ and $\bp^\mathrm{face}$ can depend on the scene parameter $\pi$.
Therefore,
%
\begin{equation}
	\label{eqn:rte3d_ddist_plane}
	\ddist = \sdev F^{-1}(0; \bx, \bom, \param) = \sdev\frac{\langle \gnorm^\mathrm{face}, \bx - \bp^\mathrm{face} \rangle}{\langle \gnorm^\mathrm{face}, \bom \rangle}.
\end{equation}
%
In practice, $\ddist$ can also be obtained by differentiating the ray tracing process using \emph{automated differentiation}.

\begin{figure}[t]
	\centering
	\includegraphics[height=0.95in]{Lins_boundary_2.pdf}
	\caption{\label{fig:Lins_boundary}
		Calculating the in-scattered radiance~$\Lins$ at location $\bx_0 \in \boundary$ with direction $\bom$ pointing toward the interior of the medium (illustrated in gray).
		(a)~When $\bom' \in \bbH_+$ (i.e., pointing toward the exterior of the medium), the interior radiance $\Lv(\bx_0, \bom')$ involving a line integral (indicated as the dashed line in green) from the interior is used.
		(b)~When $\bom' \in \bbH_-$, on the contrary, the interfacial radiance $\Ls(\bx_0, \bom')$ from the interior is used.
		This radiance is in turn determined by interior radiances reflected and refracted by the interface (shown as dashed lines in orange).
	}
\end{figure}

\paragraph{In-scattered radiance at the boundary}
The last term required for evaluating $\sdev \kernelT\,\kernelC\,\Lv$ in Eq.~\eqref{eqn:rte3d_ind_diff} involves the in-scattered radiance~$\Lins$ at boundary point~$\bx_0$.
Caution is needed here since light transport behaves differently at the two sides of the boundary.

$\Lins(\bx_0, \bom)$ is given by the limit of $\Lins(\bx', \bom)$ as $\bx'$ approaches the boundary location $\bx_0$ from the interior of the medium along the direction of $-\bom$.
Namely, $\Lins(\bx_0, \bom) = \lim_{\tau \to \dist^-} \Lins(\bx', \bom)$ with $\bx' := \bx - \tau\bom$.
This limit can be further expressed as
%
\begin{equation}
	\label{eqn:rte3d_Lins_boundary}
	\begin{split}
		\Lins(\bx_0, \bom) =\;& \tint_{\bbH_+} \phase(\bx_0, -\bom', \bom) \, \Lv(\bx_0, \bom') \,\D\bom' \;+\\
		& \tint_{\bbH_-} \phase(\bx_0, -\bom', \bom) \, \Ls(\bx_0, \bom') \,\D\bom',
	\end{split}
\end{equation}
%
where $\bbH_+$ and $\bbH_-$ are the two hemispheres separated by the boundary at $\bx_0$ (see Figure~\ref{fig:Lins_boundary}) given by
%
\begin{equation}
	\begin{aligned}
		\bbH_+ &= \{ \bom' \in \Sph \;:\; \langle \gnorm(\bx_0), \bom' \rangle > 0 \},\\
		\bbH_- &= \{ \bom' \in \Sph \;:\; \langle \gnorm(\bx_0), \bom' \rangle < 0 \},
	\end{aligned}
\end{equation}
%
where $\gnorm(\bx_0)$ is the boundary normal pointing toward the exterior of the medium (i.e., $\langle \gnorm(\bx_0), \bom \rangle < 0$).
