From 00000460abbc318ab9801fb74d5ad97cb352f1d9 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 16 Feb 2023 01:14:22 -0600 Subject: [PATCH] Add more to writeup --- assignment-1b/.gitignore | 1 + assignment-1b/Makefile | 14 ++- assignment-1b/README.md | 4 + assignment-1b/examples/depth-cueing-demo.txt | 15 +++ assignment-1b/examples/ka-demo.txt | 14 +-- assignment-1b/examples/kd-demo.txt | 14 +-- assignment-1b/examples/ks-demo.txt | 14 +-- .../examples/multiple-lights-demo.txt | 16 +++ assignment-1b/examples/n-demo.txt | 14 +-- assignment-1b/examples/objects.txt | 22 ++-- assignment-1b/examples/soft-shadow-demo.txt | 11 +- assignment-1b/src/scene/sphere.rs | 6 +- assignment-1b/src/utils.rs | 2 + assignment-1b/writeup.md | 112 +++++++++++++++--- participation/2023-02-15.md | 11 ++ 15 files changed, 203 insertions(+), 67 deletions(-) create mode 100644 assignment-1b/examples/depth-cueing-demo.txt create mode 100644 assignment-1b/examples/multiple-lights-demo.txt create mode 100644 participation/2023-02-15.md diff --git a/assignment-1b/.gitignore b/assignment-1b/.gitignore index 841bbdb..6987804 100644 --- a/assignment-1b/.gitignore +++ b/assignment-1b/.gitignore @@ -7,3 +7,4 @@ *.pdf perf.data* flamegraph.svg +showcase.png diff --git a/assignment-1b/Makefile b/assignment-1b/Makefile index 2ee7944..41f0b60 100644 --- a/assignment-1b/Makefile +++ b/assignment-1b/Makefile @@ -7,9 +7,10 @@ ZIP := zip PANDOC := pandoc CONVERT := convert -HANDIN := hw1b.michael.zhang.zip +HANDIN := ./hw1b.michael.zhang.zip BINARY := ./raytracer1b -WRITEUP := writeup.pdf +WRITEUP := ./writeup.pdf +SHOWCASE := ./showcase.png SOURCES := Cargo.toml $(shell find -name "*.rs") EXAMPLES := $(shell find examples -name "*.txt") @@ -31,9 +32,12 @@ $(BINARY): $(SOURCES) cargo build --profile release-handin mv target/docker/release-handin/raytracer1b $@ -$(HANDIN): $(BINARY) $(WRITEUP) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM) +$(HANDIN): $(BINARY) $(WRITEUP) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM) $(SHOWCASE) $(ZIP) -r $@ src examples $^ +$(SHOWCASE): examples/soft-shadow-demo.png + cp $< $@ + examples/%.ppm: examples/%.txt $(SOURCES) cargo run --release -- -o $@ $< @@ -44,4 +48,6 @@ writeup.pdf: writeup.md $(EXAMPLES_PNG) $(PANDOC) -o $@ $< clean: - rm -f $(HANDIN) $(BINARY) $(WRITEUP) $(EXAMPLES_PPM) $(EXAMPLES_PNG) + rm -rf target/docker \ + $(HANDIN) $(BINARY) $(WRITEUP) $(SHOWCASE) \ + $(EXAMPLES_PPM) $(EXAMPLES_PNG) diff --git a/assignment-1b/README.md b/assignment-1b/README.md index 396c03e..c0a5eca 100644 --- a/assignment-1b/README.md +++ b/assignment-1b/README.md @@ -14,6 +14,10 @@ sources, and the ppm files are the corresponding outputs. They have been generated by running this program. For convenience, pngs have also been provided using imagemagick. +## Showcase image + +The showcase image can be found at `/showcase.png`. + ## Building from source The Makefile currently uses Docker to produce a more consistent build. If you diff --git a/assignment-1b/examples/depth-cueing-demo.txt b/assignment-1b/examples/depth-cueing-demo.txt new file mode 100644 index 000000000..2b368c0 --- /dev/null +++ b/assignment-1b/examples/depth-cueing-demo.txt @@ -0,0 +1,15 @@ +imsize 640 480 +eye -2.5 2 -5 +viewdir -0.2 0 -1 +hfov 90 +updir 0 1 0 +bkgcolor 0.4 0.4 0.4 + +depthcueing 0.4 0.4 0.4 1 0.1 60 0 +light 0 5 -7.5 1 1 1 1 + +mtlcolor 1 0.8 0.7 1 1 1 0.6 0.6 0 10 +sphere -5 2 -10 2 +sphere -3 2 -20 2 +sphere 1.5 2 -30 2 +sphere 13 2 -60 2 diff --git a/assignment-1b/examples/ka-demo.txt b/assignment-1b/examples/ka-demo.txt index c65d309..395d198 100644 --- a/assignment-1b/examples/ka-demo.txt +++ b/assignment-1b/examples/ka-demo.txt @@ -3,21 +3,21 @@ eye 0 0 15 viewdir 0 0 -1 hfov 90 updir 0 1 0 -bkgcolor 0.1 0.1 0.1 +bkgcolor 0.4 0.4 0.4 -light 0 3 3 0 0.3 0.3 0.4 +light 0 5 5 1 0.7 0.7 0.8 -mtlcolor 0 1 0 1 1 1 0 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0 0.4 0 1 sphere -10 0 0 2 -mtlcolor 0 1 0 1 1 1 0.2 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.4 0 1 sphere -5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.4 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.4 0.4 0 1 sphere 0 0 0 2 -mtlcolor 0 1 0 1 1 1 0.6 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.6 0.4 0 1 sphere 5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.8 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.8 0.4 0 1 sphere 10 0 0 2 diff --git a/assignment-1b/examples/kd-demo.txt b/assignment-1b/examples/kd-demo.txt index e5eb7dd..10097f6 100644 --- a/assignment-1b/examples/kd-demo.txt +++ b/assignment-1b/examples/kd-demo.txt @@ -3,21 +3,21 @@ eye 0 0 15 viewdir 0 0 -1 hfov 90 updir 0 1 0 -bkgcolor 0.1 0.1 0.1 +bkgcolor 0.4 0.4 0.4 -light 0 3 3 0 0.3 0.3 0.4 +light 0 5 5 1 0.7 0.7 0.8 -mtlcolor 0 1 0 1 1 1 0.2 0 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0 0 1 sphere -10 0 0 2 -mtlcolor 0 1 0 1 1 1 0.2 0.2 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0 1 sphere -5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.2 0.4 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.4 0 1 sphere 0 0 0 2 -mtlcolor 0 1 0 1 1 1 0.2 0.6 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.6 0 1 sphere 5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.2 0.8 0 1 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.8 0 1 sphere 10 0 0 2 diff --git a/assignment-1b/examples/ks-demo.txt b/assignment-1b/examples/ks-demo.txt index 7108f1c..df401ff 100644 --- a/assignment-1b/examples/ks-demo.txt +++ b/assignment-1b/examples/ks-demo.txt @@ -3,21 +3,21 @@ eye 0 0 15 viewdir 0 0 -1 hfov 90 updir 0 1 0 -bkgcolor 0.1 0.1 0.1 +bkgcolor 0.4 0.4 0.4 -light 0 3 3 0 0.3 0.3 0.4 +light 0 5 5 1 0.7 0.7 0.8 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0 15 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0 15 sphere -10 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.2 15 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.2 15 sphere -5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 15 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 15 sphere 0 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.6 15 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.6 15 sphere 5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.8 15 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.8 15 sphere 10 0 0 2 diff --git a/assignment-1b/examples/multiple-lights-demo.txt b/assignment-1b/examples/multiple-lights-demo.txt new file mode 100644 index 000000000..cf2e84c --- /dev/null +++ b/assignment-1b/examples/multiple-lights-demo.txt @@ -0,0 +1,16 @@ +imsize 640 480 +eye 0 0 -2 +viewdir 0 0 -1 +hfov 90 +updir 0 1 0 +bkgcolor 0.4 0.4 0.4 + +light -5 5 -7.5 1 1 1 1 +light 5 5 -7.5 1 1 1 1 + +mtlcolor 0.4 0.6 1 1 1 1 0.2 0.6 0 10 +sphere 0 -2 -10 2 + +mtlcolor 0.8 0.4 0.4 1 1 1 0.2 0.6 0 10 +sphere -2.5 2.5 -10 1 +sphere 2.5 2.5 -10 1 diff --git a/assignment-1b/examples/n-demo.txt b/assignment-1b/examples/n-demo.txt index 9a25aae..38acb11 100644 --- a/assignment-1b/examples/n-demo.txt +++ b/assignment-1b/examples/n-demo.txt @@ -3,21 +3,21 @@ eye 0 0 15 viewdir 0 0 -1 hfov 90 updir 0 1 0 -bkgcolor 0.1 0.1 0.1 +bkgcolor 0.4 0.4 0.4 -light 0 3 3 0 0.3 0.3 0.4 +light 0 5 5 1 0.7 0.7 0.8 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 2 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 2 sphere -10 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 6 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 6 sphere -5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 10 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 10 sphere 0 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 50 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 50 sphere 5 0 0 2 -mtlcolor 0 1 0 1 1 1 0.1 0.2 0.4 100 +mtlcolor 0.6 1 0.4 1 1 1 0.2 0.2 0.4 100 sphere 10 0 0 2 diff --git a/assignment-1b/examples/objects.txt b/assignment-1b/examples/objects.txt index cabaccf..10f9e3a 100644 --- a/assignment-1b/examples/objects.txt +++ b/assignment-1b/examples/objects.txt @@ -1,37 +1,37 @@ -imsize 640 480 +imsize 1920 1080 eye 0 0 15 viewdir 0 0 -1 hfov 60 updir 0 1 0 -bkgcolor 0.1 0.1 0.1 +bkgcolor 0.4 0.4 0.4 -depthcueing 0.1 0.1 0.1 1 0.2 100 0 +depthcueing 0.4 0.4 0.4 1 0.1 60 0 light -10 10 -3 0 0.8 0.8 0.8 light -10 10 -3 1 0.8 0.8 0.8 -mtlcolor 0 0.5 0.5 1 1 1 0.2 0.4 0 10 +mtlcolor 0 0.5 0.5 1 1 1 0.2 0.7 0.2 10 sphere -1 -2 -5 2 -sphere 3 -5 -1 0.5 +sphere 10 -10 -40 1 -mtlcolor 0.5 0.5 1 0.4 0.4 0.4 0.2 0.4 0 10 +mtlcolor 0.5 0.5 1 0.4 0.4 0.4 0.2 0.7 0.4 10 sphere 1 2 -3 3 sphere -6 3 -4 1 -mtlcolor 1.0 0 0.5 0.6 0.4 0.2 0.2 0.4 0 10 +mtlcolor 1.0 0 0.5 0.6 0.4 0.2 0.2 0.6 0.8 10 sphere 20 20 -50 6 -mtlcolor 0.5 0 0.5 0.6 0.4 0.2 0.2 0.4 0 10 +mtlcolor 0.5 0 0.5 0.6 0.4 0.2 0.2 0.5 0 10 sphere -6 -4 -8 7 -mtlcolor 0.8 0 0.3 0.6 0.4 0.2 0.2 0.4 0 10 +mtlcolor 0.8 0 0.3 0.6 0.4 0.2 0.2 0.4 0.2 10 cylinder -2 2 -3 0 0 5 1 4 -mtlcolor 0.8 0.8 0.3 0.6 0.4 0.2 0.2 0.4 0 10 +mtlcolor 0.8 0.8 0.3 0.6 0.4 0.2 0.2 0.8 0.2 10 sphere -40 35 -80 7 sphere -25 20 -60 5 sphere -12.5 15 -40 3 -sphere -6 11 -20 1.5 +sphere -7 14 -30 2 mtlcolor 0.5 1 0.5 0.2 0.4 0.8 0.2 0.4 0 10 cylinder 5 1 -2 1 -2 1 1 2 diff --git a/assignment-1b/examples/soft-shadow-demo.txt b/assignment-1b/examples/soft-shadow-demo.txt index 92707d9..279e3f1 100644 --- a/assignment-1b/examples/soft-shadow-demo.txt +++ b/assignment-1b/examples/soft-shadow-demo.txt @@ -4,15 +4,16 @@ viewdir 0 0 -1 hfov 60 updir 0 1 0 bkgcolor 0.5 0.5 0.5 -depthcueing 0.5 0.5 0.5 1 0.4 40 20 + +depthcueing 0.5 0.5 0.5 1 0.4 60 0 light 10 10 -10 1 1 1 1 -mtlcolor 0.5 1 0.5 1 1 1 0.2 1 0 10 -sphere 5 5 -20 5 -sphere -5 -5 -20 5 +mtlcolor 0.5 1 0.5 1 1 1 0.2 1 0.1 5 +sphere 4.5 4.5 -20 4.5 +sphere -4.5 -4.5 -20 4.5 -mtlcolor 1 0.5 0.5 1 1 1 0.2 1 0 10 +mtlcolor 1 0.5 0.5 1 1 1 0.2 0.8 0 5 sphere -10 0 -30 4 sphere -20 0 -30 4 sphere -30 0 -30 4 diff --git a/assignment-1b/src/scene/sphere.rs b/assignment-1b/src/scene/sphere.rs index 3eda3c0..a9bcd1d 100644 --- a/assignment-1b/src/scene/sphere.rs +++ b/assignment-1b/src/scene/sphere.rs @@ -4,7 +4,7 @@ use ordered_float::NotNan; use crate::{ray::Ray, utils::min_f64}; -use super::{illumination::IntersectionContext}; +use super::illumination::IntersectionContext; #[derive(Debug)] pub struct Sphere { @@ -21,9 +21,7 @@ impl Sphere { &self, ray: &Ray, ) -> Result> { - let a = ray.direction.x.powi(2) - + ray.direction.y.powi(2) - + ray.direction.z.powi(2); + let a = ray.direction.norm(); let b = 2.0 * (ray.direction.x * (ray.origin.x - self.center.x) + ray.direction.y * (ray.origin.y - self.center.y) diff --git a/assignment-1b/src/utils.rs b/assignment-1b/src/utils.rs index c2ab9f1..95b1e0b 100644 --- a/assignment-1b/src/utils.rs +++ b/assignment-1b/src/utils.rs @@ -3,6 +3,7 @@ use nalgebra::{Matrix3, Vector3}; use ordered_float::NotNan; /// Finds the minimum of an iterator of f64s, ignoring any NaN values +#[inline] pub fn min_f64(i: I) -> Option where I: Iterator, @@ -14,6 +15,7 @@ where /// Finds the minimum of an iterator of f64s using the given predicate, ignoring /// any NaN values +#[inline] pub fn min_f64_by_key(i: I, f: F) -> Option where I: Iterator, diff --git a/assignment-1b/writeup.md b/assignment-1b/writeup.md index ec2c376..8d0df45 100644 --- a/assignment-1b/writeup.md +++ b/assignment-1b/writeup.md @@ -3,36 +3,118 @@ geometry: margin=2cm output: pdf_document --- +# Raytracer part B + This project implements a raytracer with Blinn-Phong illumination implemented. The primary formula that is used by this implementation is: -$$ -I_{\lambda} = k_a O_{d\lambda} + - \sum_{i=1}^{n_\textrm{lights}} \left( - IL_{i\lambda} \left[ - k_d O_{d\lambda} \textrm{max} \{ - % 0, \overrightarrow{N} \middot \vec{L_i} - \} - \right] - \right) -$$ +\begin{equation} +I_{\lambda} = +k_a O_{d\lambda} + +\sum_{i=1}^{n_\textrm{lights}} \left( +IL_{i\lambda} \left[ +k_d O_{d\lambda} \max ( 0, \vec{N} \cdot \vec{L_i} ) + +k_s O_{s\lambda} \max ( 0, \vec{N} \cdot \vec{H_i} )^n +\right] +\right) +\end{equation} + +Where: + +- $I_{\lambda}$ is the final illumination of the pixel on an object +- $k_a$ is the material's ambient reflectivity +- $k_d$ is the material's diffuse reflectivity +- $k_s$ is the material's specular reflectivity +- $n_\textrm{lights}$ is the number of lights +- $IL_{i\lambda}$ is the intensity of light $i$ +- $O_{d\lambda}$ is the object's diffuse color +- $O_{s\lambda}$ is the object's specular color +- $\vec{N}$ is the normal vector to the object's surface +- $\vec{L_i}$ is the direction from the intersection point to the light $i$ +- $\vec{H_i}$ is halfway between the direction to the light $i$ and the + direction to the viewer +- $n$ is the exponent for the specular component ## Varying $k_a$ -![Varying $k_a$](examples/ka-demo.png){width=240px} +$k_a$ is the strength of ambient light. It's used as a coefficient for the +object's diffuse color, which keeps a constant value independent of the +positions of the object, light, and the viewer. In the image below, I varied +$k_a$ between 0.2 and 1. Note how the overall color of the ball increases or +decreases in brightness when all other factors remain constant. + +![Varying $k_a$](examples/ka-demo.png){width=360px} +\ ## Varying $k_d$ -![Varying $k_d$](examples/kd-demo.png){width=240px} +TODO + +![Varying $k_d$](examples/kd-demo.png){width=360px} +\ ## Varying $k_s$ -![Varying $k_s$](examples/ks-demo.png){width=240px} +TODO + +![Varying $k_s$](examples/ks-demo.png){width=360px} +\ ## Varying $n$ -![Varying $n$](examples/n-demo.png){width=240px} +$n$ is the exponent saying how big the radius of the specular highlight should +be. In the equation, increasing the exponent usually leads to smaller shines. In +the image below, I varied $n$ between 2 and 100. Note how the size of the shine +is more focused but covers a smaller area as $n$ increases. + +![Varying $n$](examples/n-demo.png){width=360px} +\ + +## Multiple lights + +Multiple lights are handled by multiplying each light against an intensity +level, and then added together. Unfortunately, this means that the intensity of +each light can't be too bright. We rely on the image to not use lights that are +too bright. Because this may result in color values above 1.0, the final value +is clamped against 1.0. Below is an example of a scene with two lights; one to +the left and one to the right: + +![Multiple lights](examples/multiple-lights-demo.png){width=360px} +\ + +## Shadows + +Shadows are implemented by pointing a second ray between the intersection point +of the original view ray and each light. If the light has something obstructing +it in the middle, the light's effect is not used. + +The soft shadow effect is realized by jittering rays across an area. In my +implementation, a jitter radius of about 1.0 is used, and 75 rays are shot into +uniformly sampled points within that radius. This also has the side effect that +rays that are closer to the original ray are sampled more frequently. Each of +these rays produces either 0 or 1 depending on if it was obstructed by the +object. Taking the proportion of rays that hit as a coefficient for the shadow, +we can get some soft shadow effects like this: + +![Soft shadows](examples/soft-shadow-demo.png){width=360px} +\ + +## Depth Cueing + +Depth cueing is when the objects further from the viewer have a lower opacity to +"fade" into the background in some sense. A good example of this can be seen in +the image below; note how the objects are less and less bright the further they +are away from the eye. + +![Depth cueing](examples/depth-cueing-demo.png){width=360px} +\ + +## Shortcomings of the model + +The model cannot be used to represent TODO # Arbitrary Objects -![Varying $n$](examples/objects.png){width=240px} +![Objects in the scene](examples/objects.png){width=360px} +\ + diff --git a/participation/2023-02-15.md b/participation/2023-02-15.md new file mode 100644 index 000000000..9172581 --- /dev/null +++ b/participation/2023-02-15.md @@ -0,0 +1,11 @@ +# Participation Question 1 + +**What are the complications that you can imagine that results from including +the points on the side of the triangle in the triangle or not?** + +_Hint: Two triangles that share a border may have problems._ + +# Participation Question 2 + +**When d11 \* d22 - d12 \* d12 = 0, the system will have no solution. When might +this happen, and what does it mean?**