Commit 022ba1fa authored by yhesper's avatar yhesper
Browse files

pathtracer doc 1st draft

parent e2ed4635
---
layout: default
title: "Dielectrics and Transmission"
permalink: /pathtracer/dielectrics_and_transmission
---
# Dielectrics and Transmission
## Fresnel Equations for a Dielectric
The [Fresnel Equations](https://en.wikipedia.org/wiki/Fresnel_equations) (another [link](http://hyperphysics.phy-astr.gsu.edu/hbase/phyopt/freseq.html) 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 this assignment you're asked to implement a glass material, which is a dielectric.
In the description below, ![dielectric_eq1](dielectric_eq1.png) and ![dielectric_eq2](dielectric_eq2.png) 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. ![dielectric_eq3](dielectric_eq3.png) and ![dielectric_eq4](dielectric_eq4.png) 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:
![dielectric_eq5](dielectric_eq5.png)
The parallel and perpendicular terms are given by:
![dielectric_eq6](dielectric_eq6.png)
![dielectric_eq7](dielectric_eq7.png)
Therefore, for a dielectric material, the fraction of reflected light will be given by ![dielectric_eq8](dielectric_eq8.png), and the amount of transmitted light will be given by ![dielectric_eq9](dielectric_eq9.png).
Alternatively, you may compute![dielectric_eq8](dielectric_eq8.png) using [Schlick's approximation](https://en.wikipedia.org/wiki/Schlick%27s_approximation).
## 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 you guys to Pharr, Jakob, and and Humphries's book [Physically Based Rendering](http://www.pbr-book.org/) for a derivation based on Snell's Law and the relation ![dielectric_eq10](dielectric_eq10.png). (But you are more than welcome to attempt a derivation on your own!)
\ No newline at end of file
---
layout: default
title: "(Task 7) Environment Lighting"
permalink: /pathtracer/environment_lighting
---
# (Task 7) Environment Lighting
The final task of this assignment will be to implement a new type of light source: an infinite environment light. An environment light is a light that supplies incident radiance (really, the light intensity dPhi/dOmega) from all directions on the sphere. Rather than using a predefined collection of explicit lights, an environment light is a capture of the actual incoming light from some real-world scene; rendering using environment lighting can be quite striking.
The intensity of incoming light from each direction is defined by a texture map parameterized by phi and theta, as shown below.
![envmap_figure](envmap_figure.jpg)
In this task you need to implement the `Env_Map::sample` and `Env_Map::sample_direction` method in `student/env_light.cpp`. You'll start with uniform direction sampling to get things working, and then move to a more advanced implementation that uses **importance sampling** to significantly reduce variance in rendered images.
## Step 1: Uniform sampling
To get things working, your first implementation of `Env_Map::sample` will be quite simple. You should generate a random direction on the sphere (**with uniform (1/4pi) probability with respect to solid angle**), convert this direction to coordinates (phi, theta) and then look up the appropriate radiance value in the texture map using **bilinear interpolation** (note: we recommend you begin with bilinear interpolation to keep things simple.)
Since high dynamic range environment maps can be large files, we have not included them in the starter code repo. You can download a set of environment maps from this [link](http://15462.courses.cs.cmu.edu/fall2015content/misc/asst3_images/asst3_exr_archive.zip).You can designate rendering to use a particular environment map from the GUI: go to `layout` -> `new light` -> `environment map`-> `add`, and then select one of the environment maps that you have just downloaded.
![envmap_gui](envmap_gui.png)
**Tips:**
* You must write your own code to uniformly sample the sphere.
* check out the interface of `Env_Map` in `rays/env_light.h`. For `Env_Map`, the `image` field is the actual map being represented as a `HDR_Image`, which contains the pixels of the environment map and size of the environment texture. The interface for `HDR_Image` is in `util/hdr_image.h`.
## Step 2: Importance sampling the environment map
Much like light in the real world, most of the energy provided by an environment light source is concentrated in the directions toward bright light sources. **Therefore, it makes sense to bias selection of sampled directions towards the directions for which incoming radiance is the greatest.** In this final task you will implement an importance sampling scheme for environment lights. For environment lights with large variation in incoming light intensities, good importance sampling will significantly improve the quality of renderings.
The basic idea is that you will assign a probability to each pixel in the environment map based on the total flux passing through the solid angle it represents. We've written up [a set of notes for you here](importance_sampling.md).
**Here are a few tips:**
* When computing areas corresponding to a pixel, use the value of theta at the pixel centers.
* We recommend precomputing the joint distributions p(phi, theta) and marginal distributions p(theta) in the constructor of `Sampler::Sphere::Image` and storing the resulting values in fields `pdf`. See `rays/sampler.h`.
* `Spectrum::luma()` returns the luminance (brightness) of a Spectrum. The probability of a pixel should be proportional to the product of its luminance and the solid angle it subtends.
* `std::binary_search` is your friend. Documentation is [here](https://en.cppreference.com/w/cpp/algorithm/binary_search).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment