From 1885fe59a13d0bfb7b7f16ded2f2188376759b66 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 15 Feb 2023 02:36:53 -0600 Subject: [PATCH] get started on writeup --- assignment-1b/Cargo.toml | 2 +- assignment-1b/src/image.rs | 6 +++--- assignment-1b/src/lib.rs | 11 +++++++++++ assignment-1b/src/main.rs | 17 +++-------------- assignment-1b/src/scene/data.rs | 16 +++++++++------- assignment-1b/writeup.md | 15 ++++++++++++++- 6 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 assignment-1b/src/lib.rs diff --git a/assignment-1b/Cargo.toml b/assignment-1b/Cargo.toml index 2d30ba5..78b50df 100644 --- a/assignment-1b/Cargo.toml +++ b/assignment-1b/Cargo.toml @@ -10,7 +10,7 @@ path = "src/main.rs" [dependencies] anyhow = "1.0.68" -clap = { version = "4.1.4", features = ["derive"] } +clap = { version = "4.1.4", features = ["cargo", "derive"] } derivative = "2.2.0" nalgebra = "0.32.1" num = { version = "0.4.0", features = ["serde"] } diff --git a/assignment-1b/src/image.rs b/assignment-1b/src/image.rs index 918bdf7..2f80491 100644 --- a/assignment-1b/src/image.rs +++ b/assignment-1b/src/image.rs @@ -8,13 +8,13 @@ pub type Color = Vector3; /// A representation of an image pub struct Image { /// Width in pixels - pub(crate) width: usize, + pub width: usize, /// Height in pixels - pub(crate) height: usize, + pub height: usize, /// Pixel data in row-major form. - pub(crate) data: Vec, + pub data: Vec, } impl Image { diff --git a/assignment-1b/src/lib.rs b/assignment-1b/src/lib.rs new file mode 100644 index 000000000..a9d997a --- /dev/null +++ b/assignment-1b/src/lib.rs @@ -0,0 +1,11 @@ +#![doc = include_str!("../writeup.md")] + +#[macro_use] +extern crate anyhow; +#[macro_use] +extern crate derivative; + +pub mod image; +pub mod ray; +pub mod scene; +pub mod utils; diff --git a/assignment-1b/src/main.rs b/assignment-1b/src/main.rs index fff520a..ff8c9b9 100644 --- a/assignment-1b/src/main.rs +++ b/assignment-1b/src/main.rs @@ -1,22 +1,11 @@ -#[macro_use] -extern crate anyhow; -#[macro_use] -extern crate derivative; - -mod image; -mod ray; -mod scene; -mod utils; - use std::fs::File; use std::path::PathBuf; use anyhow::Result; +use assignment_1b::image::Image; +use assignment_1b::ray::Ray; +use assignment_1b::scene::Scene; use clap::Parser; -use scene::Scene; - -use crate::image::Image; -use crate::ray::Ray; /// Simple raycaster. #[derive(Parser)] diff --git a/assignment-1b/src/scene/data.rs b/assignment-1b/src/scene/data.rs index 6389d9b..36c4b02 100644 --- a/assignment-1b/src/scene/data.rs +++ b/assignment-1b/src/scene/data.rs @@ -50,18 +50,19 @@ pub struct Material { #[derive(Debug)] pub enum LightKind { /// A point light source exists at a point and emits light in all directions - Point { - location: Vector3, - }, + Point { location: Vector3 }, - Directional { - direction: Vector3, - }, + /// A directional light source exists at an infinitely far location but emits + /// light in a specific direction + Directional { direction: Vector3 }, } #[derive(Debug)] pub struct Light { + /// The kind of light source, as well as its associated information pub kind: LightKind, + + /// The color, or intensity, of the light source pub color: Vector3, } @@ -115,7 +116,8 @@ impl Scene { // Compute viewing window corners let n = self.view_dir.normalize(); - #[rustfmt::skip] // Otherwise this line wraps over + + #[rustfmt::skip] // Don't format, or else this line wraps over let view_window = Rect { upper_left: self.eye_pos + n * distance - u * (viewing_width / 2.0) + v * (viewing_height / 2.0), upper_right: self.eye_pos + n * distance + u * (viewing_width / 2.0) + v * (viewing_height / 2.0), diff --git a/assignment-1b/writeup.md b/assignment-1b/writeup.md index df8bac6..ec2c376 100644 --- a/assignment-1b/writeup.md +++ b/assignment-1b/writeup.md @@ -3,6 +3,20 @@ geometry: margin=2cm output: pdf_document --- +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) +$$ + ## Varying $k_a$ ![Varying $k_a$](examples/ka-demo.png){width=240px} @@ -22,4 +36,3 @@ output: pdf_document # Arbitrary Objects ![Varying $n$](examples/objects.png){width=240px} -