Assignment 3 Notes

Task 2: Triangle Intersection Notes

Given a triangle defined by points $\mathrm{p_0}$, $\mathrm{p_1}$ and $\mathrm{p_2}$ and a ray given by its origin $\mathrm{o}$ and direction $\mathrm{d}$, the barycentrics of the hit point as well as the t-value of the hit can be obtained by solving the system:

$$ \begin{bmatrix}\mathrm{e_1} & \mathrm{e}_2 & {-\mathrm{d}}\end{bmatrix}\begin{bmatrix} u \\ v \\ t \end{bmatrix} = \mathrm{s} $$

Where:

$$ \mathrm{e_1} = \mathrm{p_1} - \mathrm{p_0} \\ \mathrm{e_2} = \mathrm{p_2} - \mathrm{p_0} \\ \mathrm{s} = \mathrm{o} - \mathrm{p_0} $$

This system can be solved by Cramer's Rule, yielding:

$$ \begin{bmatrix} u \\ v \\ t \end{bmatrix} = \frac{1}{\begin{vmatrix}\mathrm{e_1} & \mathrm{e}_2 & {-\mathrm{d}}\end{vmatrix}}\begin{bmatrix}\begin{vmatrix} \mathrm{s} & \mathrm{e_2} & \mathrm{-d}\end{vmatrix} \\ \begin{vmatrix} \mathrm{e_1} & \mathrm{s} & \mathrm{-d}\end{vmatrix} \\ \begin{vmatrix} \mathrm{e_1} & \mathrm{e_2} & \mathrm{s}\end{vmatrix} \end{bmatrix} $$

In the above, $\begin{vmatrix} \mathrm{a} & \mathrm{b} & \mathrm{c} \end{vmatrix}$ denotes the determinant of the 3x3 with column vectors $\mathrm{a},\mathrm{b}, \mathrm{c}$.

Note that since the determinant is given by: $\begin{vmatrix} \mathrm{a} & \mathrm{b} & \mathrm{c} \end{vmatrix} = (\mathrm{a}\times \mathrm{b}) \cdot \mathrm{c} = (\mathrm{b}\times \mathrm{c}) \cdot \mathrm{a} = (\mathrm{c} \times \mathrm{a}) \cdot \mathrm{b}$, you can rewrite the above as:

$$ \begin{bmatrix} u \\ v \\ t \end{bmatrix} = \frac{1}{(\mathrm{e_1} \times \mathrm{d}) \cdot \mathrm{e_2}}\begin{bmatrix} -(\mathrm{s} \times \mathrm{e_2}) \cdot \mathrm{d} \\ (\mathrm{e_1} \times \mathrm{d}) \cdot \mathrm{s} \\ -(\mathrm{s} \times \mathrm{e_2}) \cdot \mathrm{e_1} \end{bmatrix} $$

Of which you should notice a few common subexpressions that, if exploited in an implementation, make computation of t, u, and v substantially more efficient.

A few final notes and thoughts:

  • If the denominator $(\mathrm{e_1} \times \mathrm{d}) \cdot \mathrm{e_2}$ is zero, what does that mean about the relationship of the ray and the triangle? Can a triangle with this area be hit by a ray?
  • Given $u$ and $v$, how do you know if the ray hits the triangle?
  • Don't forget that the intersection point on the ray should be within the ray's min_t and max_t bounds.

Task 6: Fresnel Equations for a Dielectric

The Fresnel Equations (another link here) describe the amount of reflection from a surface. The description below is an approximation for dielectric materials (materials that don't conduct electricity). In assignment 3 you're asked to implement a glass material, which is a dielectric.

In the description below, $\eta_i$ and $\theta_i$ refer to the index of refraction of the medium containing an incoming ray, and the zenith angle of the ray to the surface of a new medium. $\eta_t$ and $\theta_t$ refer to the index of refraction of the new medium and the angle to the surface normal of a transmitted ray.

The Fresnel equations state that reflection from a surface is a function of the surface's index of refraction, as well as the polarity of the incoming light. Since our renderer doesn't account for polarity, we'll apply a common approximation of averaging the reflectance of polarizes light in perpendicular and parallel polarized light:

$$F_r = \frac{1}{2}(r_{\parallel}^2 + r_{\perp}^2)$$

The parallel and perpendicular terms are given by:

$$r_{\parallel} = \frac{\eta_t \cos \theta_i - \eta_i \cos \theta_t}{\eta_t \cos \theta_i + \eta_i \cos \theta_t}$$

$$r_{\perp} = \frac{\eta_i \cos \theta_i - \eta_t \cos \theta_t}{\eta_i \cos \theta_i + \eta_t \cos \theta_t}$$

Therefore, for a dielectric material, the fraction of reflected light will be given by $F_r$, and the amount of transmitted light will be given by $1-F_r$.

Task 6: Distribution Function for Transmitted Light

We described the BRDF for perfect specular reflection in class, however we did not discuss the distribution function for transmitted light. Since refraction "spreads" or "condenses" a beam, unlike perfect reflection, the radiance along the ray changes due to a refraction event. In your assignment you should use Snell's Law to compute the direction of refraction rays, and use the following distribution function to compute the radiance of transmitted rays. We refer students to Pharr and Humphries for a derivation based on Snell's Law and the relation $d\Phi_t = (1-F_r)d\Phi_i$ (or encourage students to attempt a derivation on their own).

$$f(p,\omega_t, \omega_i) = \frac{\eta_t^2}{\eta_i^2}(1-F_r)\frac{\delta(\omega_i - T(\omega_t, \mathbf{n}))}{|\cos \, \theta_i|}$$

Task 7: Environment Light Importance Sampling

Specifically, a pixel with coordinate $\theta=\theta_0$ subtends an area $\sin \theta \, d\theta \, d\phi$ on the unit sphere (where $d\theta$ and $d\phi$ the angles subtended by each pixel -- as determined by the resolution of the texture). Thus, the flux through a pixel is proportional to $L \, \sin \theta$. (We only care about the relative flux through each pixel to create a distribution.)

Summing the fluxes for all pixels, then normalizing the values so that they sum to one, yields a discrete probability distribution for picking a pixel based on flux through its corresponding solid angle on the sphere.

The question is now how to sample from this 2D discrete probability distribution. We recommend the following process which reduces the problem to drawing samples from two 1D distributions, each time using the inversion method discussed in class:

  • Given p($\phi$, $\theta$) the probability distribution for all pixels, compute the marginal probability distribution p($\theta$) = $\sum_{\phi}$ p($\phi$, $\theta$) for selecting a value from each row of pixels.
  • Given for any pixel, compute the conditional probability p($\phi$ | $\theta$) as $\frac{p(\phi, \theta)}{p(\theta)}$.

Given the marginal distribution for $\theta$ and the conditional distributions p($\phi$ | $\theta$) for environment map rows, it is easy to select a pixel as follows:

  1. Use the inversion method to first select a "row" of the environment map according to p($\theta$).
  2. Given this row, use the inversion method to select a pixel in the row according to p($\phi$ | $\theta$).

Ackwowledgements

The descriptions in these notes follow the explanation in "Physically Based Rendering: From Theory to Implemenation", Pharr and Humphries 2010.

Nina

Useful link to review Cramer's Rule: https://en.wikipedia.org/wiki/Cramer's_rule

Also I am confused about the determinants representation of |a b c|. Say if we want to calculate

\begin{vmatrix} \mathrm{a} & \mathrm{b} & \mathrm{c} ; \ \mathrm{d} & \mathrm{e} & \mathrm{f} ;\ \mathrm{g} & \mathrm{h} & \mathrm{i} ; \end{vmatrix}

= \begin{vmatrix} \mathrm{m} & \mathrm{n} & \mathrm{k} \end{vmatrix}

with m = (a d g)^T, n = (b e h)^T, k = (c f i)^T

The result should be a(ei-hf) - b(di-fg) + c(dh+eg)

But if I use the equation above: |m n k| = (n x k) dot m

The result is a(ei-hf) - d(bi-ch) + g(fb-ce), which is different from result above.

Khryl

What is $ \delta (\omega_i)$ and $T(w_t,n)$ in the distribution function for transmitted light? Should it be like $ \delta (\omega_i - T(w_t,n))$ in this function?

ak-47

@Khryl I think you're right. I think T(w_t, n) is the output of Snell's law, wo if the incoming angle is what fits into Snell's law, $f\ne 0$. Otherwise $f=0$.

kayvonf

@Khryl: sorry I missed your post. You are correct. This is the delta evaluated on whether the incident way w_i and the output ray are related by Snell's Law. In other words:

  • Let w_i be the incident ray that results in the following transmitted ray $T(\omega_i, n)=\omega_t$.
  • Then $T(T(\omega_i, \mathrm{n}),\mathrm{n})=T(\omega_t,\mathrm{n})$ equals $\omega_i$.
  • All in all, this equation is saying that if the bsdf is given rays that are related by refraction, then the value of the bsdf will be non-zero.