<p>TLDR: As long as you write your algorithms correctly you are approximating the same integral regardless whether you trace forward or backward. It's just approximations of different reformulations of the same integral, i.e., <span class="math-container">$\langle W_e, L_i\rangle$</span> vs <span class="math-container">$\langle W_i, L_e\rangle$</span>. There are even more variants, which you typically implement when you consider bidirectional path tracing (BDPT).</p>
<p>Regarding the inversion: For most bsdfs <span class="math-container">$f^*(p,\omega_o, \omega_i) = f(p, \omega_i, \omega_o)$</span> indeed, i.e., the outgoing and incident directions get flipped. And in more general cases this still holds up to some multiplier <span class="math-container">$f^*(p,\omega_o, \omega_i) =  C(p, \omega_i, \omega_o) f(p, \omega_i, \omega_o)$</span>.</p>
<hr />
<p>The approximation model that you typically  use in path tracing is the rendering equation (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, page 90, (3.19)):</p>
<p><span class="math-container">$$L_o(p,\omega_o) = L_e(p, \omega_o) + \int_{\mathbb{S}^2} L_i(p, \omega_i) f(p, \omega_o, \omega_i) |\cos\theta_i| \, d\sigma(\omega_i), \tag{1}$$</span>
where <span class="math-container">$L_o$</span> is the total outgoing radiance from a point <span class="math-container">$p\in\mathbb{R}^3$</span> along a direction <span class="math-container">$\omega_o\in\mathbb{S}^2$</span> (where <span class="math-container">$\mathbb{S}^2$</span> is the unit <span class="math-container">$2$</span>-sphere), <span class="math-container">$L_e$</span> is the emitted radiance along the same, <span class="math-container">$f$</span> is the <a href="https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function" rel="nofollow noreferrer">BRDF</a>, <span class="math-container">$L_i$</span> is the incident radiance, and <span class="math-container">$\sigma$</span> is the solid angle measure (in Veach's thesis you typically see <span class="math-container">$\sigma^{\perp}$</span> instead, where <span class="math-container">$\sigma^{\perp} = |\cos\theta|\sigma$</span>).
In vacuum <span class="math-container">$L_i(p, \omega) = (GL_o)(p,\omega) := L_o(r(p, \omega), -\omega)$</span>, where <span class="math-container">$r$</span> is the ray-tracing function.</p>
<p>For brevity you may rewrite <span class="math-container">$(1)$</span> in operator form: <span class="math-container">$L = L_e + TL$</span> (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, page 112, (4.15)). Then the solution is given as an infinite sum of integrals of increasing dimensionality (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, page 113, (4.18)):</p>
<p><span class="math-container">$$L_o=L_e + TL_o = L_e + T(L_e+TL_o) = \ldots = \sum_{k=0}^{\infty} T^kL_e = SL_e.$$</span></p>
<p>In practice you want to compute the response of an array of sensors to said radiance. So the contribution at sensor <span class="math-container">$j$</span> with sensitivity function <span class="math-container">$W^j_e$</span> is (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, page 89, (3.18)):
<span class="math-container">$$I_j = \langle W_e^j, L_i\rangle = \int_{\mathcal{M}} \int_{\mathbb{S}^2} W_e^j(p,\omega) L_i(p,\omega) |\cos\theta| \, d\sigma(\omega) \, dA(p).$$</span></p>
<p>You can now plug <span class="math-container">$L_i = GL_o =  GSL_e$</span> into the above yielding:</p>
<p><span class="math-container">$$\langle W_e^j, L_i\rangle = \left\langle W_e^j, GSL_e\right\rangle = \left\langle (GS)^* W_e^j, L_e\right\rangle = \langle W_i^j, L_e\rangle.$$</span></p>
<p>Here <span class="math-container">$(GS)^*$</span> is the adjoint operator to <span class="math-container">$GS$</span> which is defined in a similar way except with the adjoint BRDF <span class="math-container">$f^*$</span> (the latter differs for non-symmetric BRDFs). Formally it doesn't matter whether we compute <span class="math-container">$\langle W_e^j, L_i\rangle$</span> or <span class="math-container">$\langle W_i^j, L_e\rangle$</span> since they are equal (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, 119, (4.29)). Applying a path tracing technique to the latter yields the backwards tracing method. Notably, you are solving the equation for the importance (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, 91, (3.20)):</p>
<p><span class="math-container">$$W_o(p, \omega_o) = W_e(p, \omega_o) + \int_{\mathbb{S}^2} W_i(p, \omega_i) f^*(p, \omega_o, \omega_i)|\cos\theta_i| \, d\omega_i.$$</span></p>
<p>In Chapter 5 of Veach's thesis he has a discussion about cases when <span class="math-container">$f^*(p,\omega_o,\omega_i)\ne f(p,\omega_i,\omega_o)$</span>. One of those is physical and occurs on refraction into a medium with a different index of refraction (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, 147, (5.15)). The other is due to a hack known as shading normals, used to fake shading properties of smoother geometry than the one we actually have. That one is non-physical but is still covered by choosing the appropriate <span class="math-container">$f^*$</span> (<a href="https://graphics.stanford.edu/papers/veach_thesis/" rel="nofollow noreferrer">Veach</a>, 152, (5.18)) such that <span class="math-container">$T$</span> and <span class="math-container">$T^*$</span> are adjoint.</p>

CC BY-SA 4.0
2024-10-17T17:58:22.683Z
The idea of the two being adjoint makes sense. And just wondering, would Veach's thesis be a good place to start with the more mathematical foundations for this type of stuff? Or is there some sort of textbook to look at?
Vasting
CC BY-SA 4.0
2024-10-17T18:21:31.447Z
@Vasting Veach's thesis works if you have enough mathematical background. Some of the material is also discussed in the book advanced global illumination, and the physically based rendering book, but they don't have everything that's in Veach's thesis, and they are derivative works off of it.The only more mathematically involved thesis on the topic I know is the one by Christian Lessig.
lightxbulb
CC BY-SA 4.0
2024-10-16T07:30:33.370Z
2024-10-16T16:03:59.553Z
2024-10-16T16:03:59.553Z
lightxbulb
<p>This is a more theoretical question. I've been following a <a href="https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html#overview" rel="nofollow noreferrer">ray tracing tutorial</a> and I'm a little confused about how some of the properties of these surfaces are rendered. There's a basic diffuse surface (Lambertian) which is programmed to scatter rays, let's say uniformly randomly, off the surface (so we generate a random unit vector in a hemisphere and let that be the scattering).</p>
<p>The ray tracer basically works by sending a ray from the camera/eye to the pixel we want to render, hitting the surface, and scattering off by the rule I just outlined. Let's keep things simple and say that the scattered ray either hits a light or doesn't. Then we sample pixel a bunch of times and average.</p>
<p>The part that I'm trying to work through is the following: in real life light rays leave some light source and are picked up by our eyes. It's very expensive to simulate this because most rays don't hit our eyes. But do we end up with the same thing at the end? Or in other words, to find the color of a pixel &quot;on&quot;  some diffuse surface listed above, the ray-tracer impelementation computes the integral
<span class="math-container">$$ \int_{\text{hemisphere}} \frac{1}{2\pi}\text{light}(v)\,dv$$</span>
where <span class="math-container">$v$</span> is the direction of the scatter and <span class="math-container">$\text{light}(v)$</span> is the intensity of the light that it hits after scattering (let's ignore the color of the material for now). In real life, we compute the integral
<span class="math-container">$$\int_{\text{lights}} \mathbb{1}_{\text{pixel-eye}}(w)\cdot\text{light}(w)\,dw$$</span>
where we now consider all light rays <span class="math-container">$w$</span> leaving all light sources, and integrate up the final intensity of the rays that bounce off the pixel and into our eye.</p>
<p>Not sure if these integrals are perfectly correct, but I guess my general question is how one can &quot;prove&quot; in a sense that these ray-tracers approximate real life when it seems that everything is being run &quot;backwards&quot; and whether we have to run the physics &quot;backwards&quot; as well. The property of the diffuse surface is based on how they work in real life when light scatters off of it, but then it seems like when we shoot a ray out of the camera, we should be &quot;inverting&quot; the scattering process of light to see where the ray should go, if that makes any sense.</p>

<raytracing><pathtracing><physically-based><physics>
Do we have to adapt what we know from physics to forwards vs. backwards ray-tracing?
Vasting
# Do we have to adapt what we know from physics to forwards vs. backwards ray-tracing?

(Asked by: username_0 on 2024-10-14)

This is a more theoretical question. I've been following a [ray tracing tutorial](https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html#overview) and I'm a little confused about how some of the properties of these surfaces are rendered. There's a basic diffuse surface (Lambertian) which is programmed to scatter rays, let's say uniformly randomly, off the surface (so we generate a random unit vector in a hemisphere and let that be the scattering).

The ray tracer basically works by sending a ray from the camera/eye to the pixel we want to render, hitting the surface, and scattering off by the rule I just outlined. Let's keep things simple and say that the scattered ray either hits a light or doesn't. Then we sample pixel a bunch of times and average.

The part that I'm trying to work through is the following: in real life light rays leave some light source and are picked up by our eyes. It's very expensive to simulate this because most rays don't hit our eyes. But do we end up with the same thing at the end? Or in other words, to find the color of a pixel "on" some diffuse surface listed above, the ray-tracer impelementation computes the integral
$$ \int\_{\text{hemisphere}} \frac{1}{2\pi}\text{light}(v)\,dv$$
where $v$ is the direction of the scatter and $\text{light}(v)$ is the intensity of the light that it hits after scattering (let's ignore the color of the material for now). In real life, we compute the integral
$$\int\_{\text{lights}} \mathbb{1}\_{\text{pixel-eye}}(w)\cdot\text{light}(w)\,dw$$
where we now consider all light rays $w$ leaving all light sources, and integrate up the final intensity of the rays that bounce off the pixel and into our eye.

Not sure if these integrals are perfectly correct, but I guess my general question is how one can "prove" in a sense that these ray-tracers approximate real life when it seems that everything is being run "backwards" and whether we have to run the physics "backwards" as well. The property of the diffuse surface is based on how they work in real life when light scatters off of it, but then it seems like when we shoot a ray out of the camera, we should be "inverting" the scattering process of light to see where the ray should go, if that makes any sense.

**Tags:** raytracing, pathtracing, physically-based, physics


---

## 1 answers

### Answer by username_1 on 2024-10-16. Score: 4 | Accepted answer

TLDR: As long as you write your algorithms correctly you are approximating the same integral regardless whether you trace forward or backward. It's just approximations of different reformulations of the same integral, i.e., $\langle W\_e, L\_i\rangle$ vs $\langle W\_i, L\_e\rangle$. There are even more variants, which you typically implement when you consider bidirectional path tracing (BDPT).

Regarding the inversion: For most bsdfs $f^\*(p,\omega\_o, \omega\_i) = f(p, \omega\_i, \omega\_o)$ indeed, i.e., the outgoing and incident directions get flipped. And in more general cases this still holds up to some multiplier $f^\*(p,\omega\_o, \omega\_i) = C(p, \omega\_i, \omega\_o) f(p, \omega\_i, \omega\_o)$.

---

The approximation model that you typically use in path tracing is the rendering equation ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), page 90, (3.19)):

$$L\_o(p,\omega\_o) = L\_e(p, \omega\_o) + \int\_{\mathbb{S}^2} L\_i(p, \omega\_i) f(p, \omega\_o, \omega\_i) |\cos\theta\_i| \, d\sigma(\omega\_i), \tag{1}$$
where $L\_o$ is the total outgoing radiance from a point $p\in\mathbb{R}^3$ along a direction $\omega\_o\in\mathbb{S}^2$ (where $\mathbb{S}^2$ is the unit $2$-sphere), $L\_e$ is the emitted radiance along the same, $f$ is the [BRDF](https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function), $L\_i$ is the incident radiance, and $\sigma$ is the solid angle measure (in Veach's thesis you typically see $\sigma^{\perp}$ instead, where $\sigma^{\perp} = |\cos\theta|\sigma$).
In vacuum $L\_i(p, \omega) = (GL\_o)(p,\omega) := L\_o(r(p, \omega), -\omega)$, where $r$ is the ray-tracing function.

For brevity you may rewrite $(1)$ in operator form: $L = L\_e + TL$ ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), page 112, (4.15)). Then the solution is given as an infinite sum of integrals of increasing dimensionality ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), page 113, (4.18)):

$$L\_o=L\_e + TL\_o = L\_e + T(L\_e+TL\_o) = \ldots = \sum\_{k=0}^{\infty} T^kL\_e = SL\_e.$$

In practice you want to compute the response of an array of sensors to said radiance. So the contribution at sensor $j$ with sensitivity function $W^j\_e$ is ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), page 89, (3.18)):
$$I\_j = \langle W\_e^j, L\_i\rangle = \int\_{\mathcal{M}} \int\_{\mathbb{S}^2} W\_e^j(p,\omega) L\_i(p,\omega) |\cos\theta| \, d\sigma(\omega) \, dA(p).$$

You can now plug $L\_i = GL\_o = GSL\_e$ into the above yielding:

$$\langle W\_e^j, L\_i\rangle = \left\langle W\_e^j, GSL\_e\right\rangle = \left\langle (GS)^\* W\_e^j, L\_e\right\rangle = \langle W\_i^j, L\_e\rangle.$$

Here $(GS)^\*$ is the adjoint operator to $GS$ which is defined in a similar way except with the adjoint BRDF $f^\*$ (the latter differs for non-symmetric BRDFs). Formally it doesn't matter whether we compute $\langle W\_e^j, L\_i\rangle$ or $\langle W\_i^j, L\_e\rangle$ since they are equal ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), 119, (4.29)). Applying a path tracing technique to the latter yields the backwards tracing method. Notably, you are solving the equation for the importance ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), 91, (3.20)):

$$W\_o(p, \omega\_o) = W\_e(p, \omega\_o) + \int\_{\mathbb{S}^2} W\_i(p, \omega\_i) f^\*(p, \omega\_o, \omega\_i)|\cos\theta\_i| \, d\omega\_i.$$

In Chapter 5 of Veach's thesis he has a discussion about cases when $f^\*(p,\omega\_o,\omega\_i)\ne f(p,\omega\_i,\omega\_o)$. One of those is physical and occurs on refraction into a medium with a different index of refraction ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), 147, (5.15)). The other is due to a hack known as shading normals, used to fake shading properties of smoother geometry than the one we actually have. That one is non-physical but is still covered by choosing the appropriate $f^\*$ ([Veach](https://graphics.stanford.edu/papers/veach_thesis/), 152, (5.18)) such that $T$ and $T^\*$ are adjoint.

> **Comments:**
> **username_0**: The idea of the two being adjoint makes sense. And just wondering, would Veach's thesis be a good place to start with the more mathematical foundations for this type of stuff? Or is there some sort of textbook to look at?  
> **username_1**: @username_0 Veach's thesis works if you have enough mathematical background. Some of the material is also discussed in the book advanced global illumination, and the physically based rendering book, but they don't have everything that's in Veach's thesis, and they are derivative works off of it.The only more mathematically involved thesis on the topic I know is the one by Christian Lessig.  

---

