I'll keep my progress of making a renderer.
- Ray Tracing in One Weekend
- Ray Tracing The Next Week
- Ray Tracing The Rest Of Your Life
- Physically Based Renderer
I'm following advices from this Peter Shirley's blog.
I've already done Ray Tracing in One Weekend before, so it's a good refresher.
g++ -Wall -std=c++14 src/inOneWeekend/main.cpp -o build/inOneWeekend
build/inOneWeekend > results/inOneWeekend/image.ppm
Before antialiasing:
After antialiasing:
In order to generate a random scattered rays at point p, we first get a vector in unit sphere via rejection method. We normalize that vector to sit on the boundary of unit sphere. Then,
p + normal_vec + random_unit_vector = scattered ray
For a metal material, the scattered ray would be reflected.
Here, we have a scene with one metal ball, two lambertian balls on a metal surface.
For a fuzzy metal material, we add a vector in unit sphere to the scattered/reflected ray.
Snell's law state that for a incoming ray
In order to get the refracted ray, we see that
Without loss of generality, assume the direction of
Note that, geometrically it's trivial to see that
Algebraically, we can use cross product to show this, where
Hence,
We get the following image for
In reality, we have no solution to the refracted ray when
When this happend, we reflect the ray. It looks the same as before.
Glass has different reflectivity that varies with angle. We use Schlick Approximation.
If you're wondering what a real glass ball looks like (and what happens if you smash them):
This can be constructed either by adding a glass dielectric with negative radius inside another glass dielectric. This "flips" the surface normal.
But, you can also simply add another dielectric with refractive index of
We make changes to camera.h
(Camera class) to include vertical field of view, look-from, look-at, in order to position the camera freely.
Here, we position the camera at point3(-2,2,1) and it's looking at point3(0,0,-1) with vfov of 90 degrees:
vfov of 20 degrees:
Here are the results for defocus blur increasing aperture from top to bottom.
We approximate a thin lens approximation by sending the rays to the scene originated from a disk with radius of aperture/2. Note that this involves having a focus distance which is different than a focal length.
Please refer to Ray Tracing The Next Week.
g++ -Wall -std=c++14 src/theNextWeek/main.cpp -o build/theNextWeek
build/theNextWeek > results/theNextWeek/image.ppm
We can add a motion blur. In order to do this, we need to store when shutter opens t0 and closes t1 for the camera class. Also, the ray needs to have time at which it fired as well.
Here is the result of motion blur: