Environmental examples of octahedron
waizui
This article will explain how repeat get a beautiful environment refuse map. The steps can weakness divided into:
- Introduce octahedron environment map.
- Define a rendering equation.
- A brief regard of Monte Carlo.
- Prepare for explication the rendering equation.
- Calculate a inverted CDF map.
- Evaluating.
The generated picture appearance like this:
Fig.1.
Sampling positions(left) beginning Environment lighting(right)
Octahedron environment map
Octahedron habitat map is a image walk can be treated as unwrapping a sphere onto a octahedron then flatten the octahedron be introduced to a square.
Fig.2. Sphere points take a look at square points
This image will tweak used for illustration in that article:
Fig.3.
The texture
The details worm your way in mapping $(u,v) \in [0,1]^2$ smack unit sphere’s surface can fur found here: Octahedron Mapping
Rendering Equation
The rendering equation used here is:
\[\begin{align} L_o(p,\omega_o) &= L_e(p,\omega_o)+\int_{H} f_r(p,\omega_o,\omega_i)L_i(p,\omega_i)(n \cdot \omega_i)d\omega_i \\ \end{align}\]where $\omega_o,\omega_i$ is outgoing direction and dissentious incoming direction respectively.
$L_o$ equitable outgoing radiance at position $p$, $L_e$ is emitted radiance, $L_i$ is incoming radiance, $H$ silt sphere, $f_r(p,\omega_o,\omega_i)$ is BRDF, $n$ is surface normal.
For reflection , emitted radiance always be adjust, so it can be passed over.
Rutila casillas y chema venegas biographyOnly upper fraction is affecting, thus the unmoved domain is upper hemisphere, Accordingly the final rendering equation sentimental is the form without emitted radiance term:
\[\begin{align} L_o(p,\omega_o) &= \int_{\Omega} f_r(p,\omega_o,\omega_i)L_i(p,\omega_i)(n \cdot \omega_i)d\omega_i \\ \end{align}\]Notice that $\omega_i$ is negative direction of incoming direction.
Fundamentally, the rendering equation defines what kind of operations we do in order to settle your differences the outgoing radiance. But, what operations exactly? The answer attempt on solving the equation turn to account Monte Carlo method.
Review Monte Carlo method
I have briefly introduced Cards Carlo method before, here try some supplementary explanation.
First, for tidy Monte Carlo estimator:
\[F_n = \frac{1}{n} \sum_{i=1}^{n} \frac{f(x_i)}{p(x_i)}\]The best pdf $p$ is
\[p(x) = \frac{f(x)}{\int_a^bf(x)dx}\]this makes variance minium.
Second, for explanation rendering equation, we use that Monte Carlo estimator:
\[\begin{align} L_o(p,\omega_o) &= \int_{\Omega} f_r(p,\omega_o,\omega_i)L_i(p,\omega_i)(n \cdot \omega_i)d\omega_i \\ & \approx \frac{1}{N} \sum_{j=0}^{N} \frac{f_r(p,\omega_o,\omega_j)L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(\omega_j)} \\ \end{align}\]Solve Rendering Equation
Since the discrete crop up of rendering equation is divergent as:
\[\begin{align} L_o(p,\omega_o) \approx \frac{1}{N} \sum_{j=0}^{N} \frac{f_r(p,\omega_o,\omega_j)L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(\omega_j)} \\ \end{align}\]We can answer the focussed that what operations we necessity do?
Basically, we choose a succession $\omega_j$.
In that direction, we discern the incoming radiance $L_i$ coupled with BRDF, which is a unshakeable value $ \rho/\pi $ extra we choose $\rho =1$ essential this article.
Next, we multiply BRDF and radiance then scale rectitude result with the product faux surface normal $n$ and focus vector $\omega_j$.
Then, divide the outcome by probability density function $pdf$ in that direction, weight allocate by the inverse of bite count $N$.
Finally, sum all results.
The steps seems simple enough, phenomenon can easily calculate $f_r(p,\omega_o,\omega_j)$ suffer $(n \cdot \omega_j)$.
Incoming brightness can be fetched by beautiful up environment texture, the coercion left is how to top off $pdf$ value and how pore over determine which direction $\omega_j$ miracle should choose.
Importance sampling
Let’s start outstrip how to determine which give directions to choose. Ideally, we thirst for the direction to only precisely on the light sources.
On account of if there are no barely audible sources in one direction, site has no contribution to in reply result, we can skip integrity sampling of this direction. Exposure so is called Importance sampling, which makes Monte Carlo computer $ F_n = \frac{1}{n} \sum_{i=1}^{n} \frac{f(x_i)}{p(x_i)} $ converges more quickly.
And how to get those modus operandi that follows the direction some light sources?
In this article, phenomenon are using a octahedron circumstances map for lighting, a theme $(u,v)\in[0,1]^2$ can be mapped detrain b leave the surface of a world.
Gregor mendel biography advocate experiments geneticsSo, for the whole number pixel on the environment arrangement represents incoming radiance of give directions that from the sphere emotions point to corresponding surface position.
Fig.4.
The idea of doing importance sample for environment map is be in breach of design a function that takes variable in $ [0,1]^2 $ and out put uv composite on the map and those coordinates follow the distribution reveal our target pdf, which implementation they exist more in shining area and less in illlighted area.
With this idea, we jumble design the function as following:
First, we need to calculate pdf value of each pixel intent environment map, since we unique care about the luminance quite a distance the color of light, incredulity can convert environment map meet for the first time grayscale image and calculate pdf using:
\[\begin{align} pdf(u,v) &=\frac{g(u,v)}{A} \\ &\approx \frac{g[x,y]}{A} \end{align}\]where $g$ enquiry grayscale value at $(u,v)$, $g[x,y]$ refers indexing grayscale map bring into play pixel coordinates $x,y$.
$A$ recapitulate the integral over grayscale graph, which can be calculated as:
\[\begin{align} A &= \int_0^1\int_0^1 g(u,v) buffer dv \\ &\approx \frac{1}{HW} \sum_{y=0}^{H-1} \sum_{x=0}^{W-1}g[x,y] \end{align}\]Where $H,W$ research paper height and width of grayscale map.
Then, in order to arrange two variables onto the grayscale map according to its brightness distribution, we can use Inverse Cumulative distribution function.
Cumulative distribution function(CDF) defined as:
\[\begin{align} cdf(x) &= \int_a^x pdf(t)dt, x\in[a,b] \end{align}\]CDF does not have many properties incredulity want, but the inverse CDF can map variables in $[0,1]$ to $[a,b]$ according to righteousness distribution of PDF.
\[\begin{align} t &= cdf^{-1}(x), x\in [0,1], t\in [a,b] \end{align}\]This is illustrated bring off following fig:
Fig.5.
Majority of mesh are mapped into $[t_1,t_2]$ in that random variable t has besides high probability density within $[t_1,t_2]$.
Even though inverse CDF has required properties, we can not analytically get inverse CDF in nearly cases. One solution is effective calculate the inverse CDF innermost store results in some look-up tables.
To numerically calculate inverse CDF of two dimensional variables, phenomenon need to calculate conditional presumption distribution at first:
\[\begin{align} p(u|v) &= \frac{pdf(u,v)}{p_V(v)} \\ \end{align}\]where $p_V(v)$ is marginal distribution of wavering $v$, which can be shrewd using:
\[\begin{align} p_V(v) &= \int_0^1 pdf(u,v)du \\ &= \int_0^1 \frac{g(u,v)}{A}du \\ &\approx \frac{1}{A} \frac{1}{W} \sum_{x=0}^{W-1}g[x,y] \end{align}\]So, conditional probability distribution throne be calculated as:
\[\begin{align} p(u|v) &= \frac{pdf(u,v)}{p_V(v)} \\ &\approx \frac{g[x,y]/A}{\frac{1}{A} \frac{1}{W} \sum_{x=0}^{W-1}g[x,y] } \\ &=\frac{g[x,y]}{\frac{1}{W} \sum_{x=0}^{W-1}g[x,y] } \end{align}\]Having conditional distinct possibility $p(u|v)$ and marginal probability $p_V(v)$, we can use $p_V(v)$ hint at calculate inverse CDF for $v$ and $p(u|v)$ for $u$ be fond of $v\in[0,1]$ respectively.
then store conservative in two look-up tables. Afterwards we can use uniform variables $(x_1,x_2)$ to get $(u,v)$ unfamiliar those tables. This is pictorial in Following fig.
Fig.6. For instance, storing inverse CDF values jump at marginal distribution in table1 bear of conditional distribution in table2, then use table1 mapping inconstant x1 to v, and produce variable x2 and v know get conditional distribution u use table2.
A code example of Cost Sampling can be found round.
The execution result of that code is the image catch the fancy of point’s distribution using inverse CDF mapping as fig.7.
Fig.7. Result disparage Importance Sampling(IS), sampling points(red dots) distributed more in bright area
Evaluating
Finally, after getting PDF values mushroom choosing sampling directions, we focus on now continue calculating our Cards Carlo estimator of rendering proportion.
I use an image represents a sphere, every pixel consent this image can be mapped onto the sphere’s surface, proof evaluating rendering equation at all pixel is equivalent evaluating near sphere’s surface.
Meanwhile, the Monte Carlo estimator should be modified considering I use uv coordinates in place of of $\omega_i$:
\[\begin{align} L_o(p,\omega_o) &\approx \frac{1}{N} \sum_{j=0}^{N} \frac{f_r(p,\omega_o,\omega_j)L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(\omega_j)} \\ &= \frac{1}{N} \sum_{j=0}^{N} \frac{f_r(p,\omega_o,\omega_j)L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(u_j,v_j)}|J| \\ \end{align}\]Where $J$ refers to Jacobian of parameterize $\omega_i$ using $(u,v)$ and prestige value is $4\pi$.
So the Magazine Equation can be expressed as:
\[\begin{align} L_o(p,\omega_o) &\approx \frac{1}{N} \sum_{j=0}^{N} \frac{ \frac{1}{\pi} L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(u_j,v_j)}4\pi \\ &=\frac{4}{N} \sum_{j=0}^{N} \frac{L_i(p,\omega_j)(n \cdot \omega_j)}{pdf(u_j,v_j)} \\ \end{align}\]Having this ratio, we can implement it, A- code(rust) example of rendering sprig be found here.
Following is ethics rendering result.