get started on writeup

This commit is contained in:
Michael Zhang 2023-02-15 02:36:53 -06:00
parent 944364910f
commit 1885fe59a1
6 changed files with 41 additions and 26 deletions

View file

@ -10,7 +10,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
anyhow = "1.0.68" anyhow = "1.0.68"
clap = { version = "4.1.4", features = ["derive"] } clap = { version = "4.1.4", features = ["cargo", "derive"] }
derivative = "2.2.0" derivative = "2.2.0"
nalgebra = "0.32.1" nalgebra = "0.32.1"
num = { version = "0.4.0", features = ["serde"] } num = { version = "0.4.0", features = ["serde"] }

View file

@ -8,13 +8,13 @@ pub type Color = Vector3<f64>;
/// A representation of an image /// A representation of an image
pub struct Image { pub struct Image {
/// Width in pixels /// Width in pixels
pub(crate) width: usize, pub width: usize,
/// Height in pixels /// Height in pixels
pub(crate) height: usize, pub height: usize,
/// Pixel data in row-major form. /// Pixel data in row-major form.
pub(crate) data: Vec<Color>, pub data: Vec<Color>,
} }
impl Image { impl Image {

11
assignment-1b/src/lib.rs Normal file
View file

@ -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;

View file

@ -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::fs::File;
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::Result; use anyhow::Result;
use assignment_1b::image::Image;
use assignment_1b::ray::Ray;
use assignment_1b::scene::Scene;
use clap::Parser; use clap::Parser;
use scene::Scene;
use crate::image::Image;
use crate::ray::Ray;
/// Simple raycaster. /// Simple raycaster.
#[derive(Parser)] #[derive(Parser)]

View file

@ -50,18 +50,19 @@ pub struct Material {
#[derive(Debug)] #[derive(Debug)]
pub enum LightKind { pub enum LightKind {
/// A point light source exists at a point and emits light in all directions /// A point light source exists at a point and emits light in all directions
Point { Point { location: Vector3<f64> },
location: Vector3<f64>,
},
Directional { /// A directional light source exists at an infinitely far location but emits
direction: Vector3<f64>, /// light in a specific direction
}, Directional { direction: Vector3<f64> },
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Light { pub struct Light {
/// The kind of light source, as well as its associated information
pub kind: LightKind, pub kind: LightKind,
/// The color, or intensity, of the light source
pub color: Vector3<f64>, pub color: Vector3<f64>,
} }
@ -115,7 +116,8 @@ impl Scene {
// Compute viewing window corners // Compute viewing window corners
let n = self.view_dir.normalize(); 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 { let view_window = Rect {
upper_left: self.eye_pos + n * distance - u * (viewing_width / 2.0) + v * (viewing_height / 2.0), 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), upper_right: self.eye_pos + n * distance + u * (viewing_width / 2.0) + v * (viewing_height / 2.0),

View file

@ -3,6 +3,20 @@ geometry: margin=2cm
output: pdf_document 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$
![Varying $k_a$](examples/ka-demo.png){width=240px} ![Varying $k_a$](examples/ka-demo.png){width=240px}
@ -22,4 +36,3 @@ output: pdf_document
# Arbitrary Objects # Arbitrary Objects
![Varying $n$](examples/objects.png){width=240px} ![Varying $n$](examples/objects.png){width=240px}